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);
}
}
}
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();
}
}
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);
}
}
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();
}
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();
}
}
Aggregations