Search in sources :

Example 16 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class PublicInterfaceFactory method get.

public synchronized ServiceMap get(String token, AccessMethod accessMethod) throws UserException {
    try {
        Authorization authorization = Authorization.fromToken(bimServer.getEncryptionKey(), token);
        DatabaseSession session = bimServer.getDatabase().createSession();
        try {
            User user = session.get(authorization.getUoid(), OldQuery.getDefault());
            if (user == null) {
                throw new UserException("No user found with uoid " + authorization.getUoid());
            }
            if (user.getState() == ObjectState.DELETED) {
                throw new UserException("User has been deleted");
            }
        } finally {
            session.close();
        }
        return get(authorization, accessMethod);
    } catch (Exception e) {
        if (e instanceof UserException) {
            throw (UserException) e;
        } else {
            throw new UserException(e);
        }
    }
}
Also used : Authorization(org.bimserver.webservices.authorization.Authorization) AnonymousAuthorization(org.bimserver.webservices.authorization.AnonymousAuthorization) User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) UserException(org.bimserver.shared.exceptions.UserException) UserException(org.bimserver.shared.exceptions.UserException)

Example 17 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class AdminServiceImpl method getLogs.

@Override
public List<SLogAction> getLogs() throws ServerException, UserException {
    requireRealUserAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        BimDatabaseAction<List<LogAction>> action = new GetLogsDatabaseAction(session, getInternalAccessMethod(), getAuthorization());
        List<LogAction> logs = session.executeAndCommitAction(action);
        List<SLogAction> convertToSListLogAction = getBimServer().getSConverter().convertToSListLogAction(logs);
        Collections.sort(convertToSListLogAction, new SLogComparator(true));
        return convertToSListLogAction;
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : SLogAction(org.bimserver.interfaces.objects.SLogAction) LogAction(org.bimserver.models.log.LogAction) DatabaseSession(org.bimserver.database.DatabaseSession) GetLogsDatabaseAction(org.bimserver.database.actions.GetLogsDatabaseAction) SLogComparator(org.bimserver.webservices.SLogComparator) List(java.util.List) ArrayList(java.util.ArrayList) SLogAction(org.bimserver.interfaces.objects.SLogAction) UserException(org.bimserver.shared.exceptions.UserException) BimBotsException(org.bimserver.bimbots.BimBotsException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 18 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class AdminServiceImpl method migrateDatabase.

@Override
public void migrateDatabase() throws ServerException, UserException {
    try {
        getBimServer().getDatabase().getMigrator().migrate();
        getBimServer().getServerInfoManager().update();
    } catch (Exception e) {
        LOGGER.error("", e);
        throw new ServerException(e);
    }
}
Also used : ServerException(org.bimserver.shared.exceptions.ServerException) UserException(org.bimserver.shared.exceptions.UserException) BimBotsException(org.bimserver.bimbots.BimBotsException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 19 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class AdminServiceImpl method setup.

@Override
public void setup(String siteAddress, String serverName, String serverDescription, String serverIcon, String adminName, String adminUsername, String adminPassword) throws ServerException, UserException {
    SettingsInterface settingsInterface = getServiceMap().get(SettingsInterface.class);
    if (!siteAddress.startsWith("http://") && !siteAddress.startsWith("https://")) {
        throw new UserException("Site address should start with \"http://\" or \"https://\"");
    }
    if (siteAddress.startsWith("http://http://") || siteAddress.startsWith("https://https://")) {
        throw new UserException("Site address should not have duplicate protocols");
    }
    settingsInterface.setSiteAddress(siteAddress);
    settingsInterface.setServerName(serverName);
    settingsInterface.setServerDescription(serverDescription);
    settingsInterface.setServerIcon(serverIcon);
    if (adminUsername.trim().isEmpty()) {
        throw new UserException("Admin Username cannot be empty");
    }
    if (adminPassword.trim().isEmpty()) {
        throw new UserException("Admin Password cannot be empty");
    }
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        AddUserDatabaseAction addUserDatabaseAction = new AddUserDatabaseAction(getBimServer(), session, AccessMethod.INTERNAL, adminUsername, adminPassword, adminName, UserType.ADMIN, getAuthorization(), false, "");
        session.executeAndCommitAction(addUserDatabaseAction);
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } finally {
        session.close();
    }
    getBimServer().getServerInfoManager().update();
}
Also used : SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) AddUserDatabaseAction(org.bimserver.database.actions.AddUserDatabaseAction) DatabaseSession(org.bimserver.database.DatabaseSession) UserException(org.bimserver.shared.exceptions.UserException)

Example 20 with UserException

use of org.bimserver.shared.exceptions.UserException in project BIMserver by opensourceBIM.

the class AuthServiceImpl method setHash.

@Override
public void setHash(Long uoid, byte[] hash, byte[] salt) throws ServerException, UserException {
    requireAdminAuthentication();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        User user = session.get(uoid, OldQuery.getDefault());
        user.setPasswordHash(hash);
        user.setPasswordSalt(salt);
        session.commit();
    } catch (Exception e) {
        handleException(e);
    } finally {
        session.close();
    }
}
Also used : User(org.bimserver.models.store.User) SUser(org.bimserver.interfaces.objects.SUser) DatabaseSession(org.bimserver.database.DatabaseSession) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException)

Aggregations

UserException (org.bimserver.shared.exceptions.UserException)362 ServerException (org.bimserver.shared.exceptions.ServerException)253 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)241 DatabaseSession (org.bimserver.database.DatabaseSession)227 IOException (java.io.IOException)220 SerializerException (org.bimserver.plugins.serializers.SerializerException)113 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)112 MalformedURLException (java.net.MalformedURLException)109 MessagingException (javax.mail.MessagingException)109 BcfException (org.opensourcebim.bcf.BcfException)109 UnsupportedEncodingException (java.io.UnsupportedEncodingException)108 AddressException (javax.mail.internet.AddressException)108 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)108 User (org.bimserver.models.store.User)65 Project (org.bimserver.models.store.Project)48 Revision (org.bimserver.models.store.Revision)39 ArrayList (java.util.ArrayList)35 Date (java.util.Date)34 SProject (org.bimserver.interfaces.objects.SProject)31 PackageMetaData (org.bimserver.emf.PackageMetaData)30