use of org.bimserver.webservices.authorization.AdminAuthorization in project BIMserver by opensourceBIM.
the class LoginUserTokenDatabaseAction method execute.
@Override
public String execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
BimDatabaseAction<User> action = new GetUserByUserTokenDatabaseAction(getDatabaseSession(), getAccessMethod(), userToken);
User user = action.execute();
if (user != null) {
if (user.getState() == ObjectState.DELETED) {
throw new UserException("User account has been deleted");
} else if (user.getUserType() == UserType.SYSTEM) {
throw new UserException("System user cannot login");
}
Authorization authorization = null;
if (user.getUserType() == UserType.ADMIN) {
authorization = new AdminAuthorization(bimServer.getServerSettingsCache().getServerSettings().getSessionTimeOutSeconds(), TimeUnit.SECONDS);
} else {
authorization = new UserAuthorization(bimServer.getServerSettingsCache().getServerSettings().getSessionTimeOutSeconds(), TimeUnit.SECONDS);
}
authorization.setUoid(user.getOid());
authorization.setUsername(user.getUsername());
String asHexToken = authorization.asHexToken(bimServer.getEncryptionKey());
serviceMap.setAuthorization(authorization);
if (bimServer.getServerSettingsCache().getServerSettings().isStoreLastLogin()) {
user.setLastSeen(new Date());
getDatabaseSession().store(user);
}
return asHexToken;
}
try {
// Adding a random sleep to prevent timing attacks
Thread.sleep(DEFAULT_LOGIN_ERROR_TIMEOUT + new java.security.SecureRandom().nextInt(1000));
} catch (InterruptedException e) {
LOGGER.error("", e);
}
throw new UserException("Invalid token", DefaultErrorCode.INVALID_TOKEN);
}
use of org.bimserver.webservices.authorization.AdminAuthorization in project BIMserver by opensourceBIM.
the class GetSubProjectsDatabaseAction method execute.
@Override
public Set<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
User user = getUserByUoid(authorization.getUoid());
Project project = getProjectByPoid(poid);
if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project)) {
throw new UserException("User has no rights on project");
}
Set<Project> subProjects = new HashSet<Project>();
for (Project subProject : project.getSubProjects()) {
if (subProject.getState() == ObjectState.ACTIVE || authorization instanceof AdminAuthorization) {
subProjects.add(subProject);
}
}
return subProjects;
}
use of org.bimserver.webservices.authorization.AdminAuthorization in project BIMserver by opensourceBIM.
the class NewRevisionNotification method sendEmail.
private void sendEmail(DatabaseSession session, Project project, Revision revision) throws UserException {
Set<User> users = getUsers(session, project);
for (User user : users) {
String body = null;
try {
if (MailSystem.isValidEmailAddress(user.getUsername())) {
EmailMessage message = getBimServer().getMailSystem().createMessage();
ServerSettings serverSettings = getBimServer().getServerSettingsCache().getServerSettings();
String emailSenderAddress = serverSettings.getEmailSenderAddress();
InternetAddress addressFrom = new InternetAddress(emailSenderAddress);
message.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[1];
addressTo[0] = new InternetAddress(user.getUsername());
message.setRecipients(Message.RecipientType.TO, addressTo);
Map<String, Object> context = new HashMap<String, Object>();
context.put("name", user.getName());
context.put("username", user.getUsername());
context.put("siteaddress", serverSettings.getSiteAddress());
context.put("revisionId", revision.getId());
Authorization authorization = null;
if (user.getUserType() == UserType.ADMIN) {
authorization = new AdminAuthorization(getBimServer().getServerSettingsCache().getServerSettings().getSessionTimeOutSeconds(), TimeUnit.SECONDS);
} else {
authorization = new UserAuthorization(getBimServer().getServerSettingsCache().getServerSettings().getSessionTimeOutSeconds(), TimeUnit.SECONDS);
}
authorization.setUoid(user.getOid());
String asHexToken = authorization.asHexToken(getBimServer().getEncryptionKey());
context.put("token", asHexToken);
context.put("roid", revision.getOid());
context.put("comment", revision.getComment());
context.put("projectName", project.getName());
String subject = null;
body = getBimServer().getTemplateEngine().process(context, TemplateIdentifier.NEW_REVISION_EMAIL_BODY);
subject = getBimServer().getTemplateEngine().process(context, TemplateIdentifier.NEW_REVISION_EMAIL_SUBJECT);
message.setContent(body, "text/html");
message.setSubject(subject.trim());
LOGGER.info("Sending new revision e-mail to " + user.getUsername());
message.send();
}
} catch (Exception e) {
LOGGER.error(body);
LOGGER.error("", e);
throw new UserException(e);
}
}
}
use of org.bimserver.webservices.authorization.AdminAuthorization in project BIMserver by opensourceBIM.
the class GetAllRelatedProjectsDatabaseAction method addProjects.
private void addProjects(List<SProjectSmall> list, Project project, User user) {
if (project.getState() == ObjectState.DELETED && !(authorization instanceof AdminAuthorization)) {
return;
}
list.add(GetAllProjectsSmallDatabaseAction.createSmallProject(authorization, bimServer, project, user));
List<Project> subProjects = new ArrayList<Project>(project.getSubProjects());
Collections.sort(subProjects, new Comparator<Project>() {
@Override
public int compare(Project o1, Project o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (Project subProject : subProjects) {
addProjects(list, subProject, user);
}
}
use of org.bimserver.webservices.authorization.AdminAuthorization in project BIMserver by opensourceBIM.
the class LoginDatabaseAction method execute.
@Override
public String execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
BimDatabaseAction<User> action = new GetUserByUserNameDatabaseAction(getDatabaseSession(), getAccessMethod(), username);
User user = action.execute();
if (user != null) {
if (user.getPasswordHash() == null || user.getPasswordHash().length == 0) {
throw new UserException("Your email address has not been validated yet");
}
if (new Authenticator().validate(password, user.getPasswordHash(), user.getPasswordSalt())) {
if (user.getState() == ObjectState.DELETED) {
throw new UserException("User account has been deleted");
} else if (user.getUserType() == UserType.SYSTEM) {
throw new UserException("System user cannot login");
}
Authorization authorization = null;
int sessionTimeOutSeconds = 60 * 10;
boolean migrationRequired = bimServer.getDatabase().getMigrator().migrationRequired();
if (!migrationRequired) {
sessionTimeOutSeconds = bimServer.getServerSettingsCache().getServerSettings().getSessionTimeOutSeconds();
}
if (user.getUserType() == UserType.ADMIN) {
authorization = new AdminAuthorization(sessionTimeOutSeconds, TimeUnit.SECONDS);
} else if (user.getUserType() == UserType.MONITOR) {
authorization = new MonitorAuthorization(sessionTimeOutSeconds, TimeUnit.SECONDS);
} else {
authorization = new UserAuthorization(sessionTimeOutSeconds, TimeUnit.SECONDS);
}
authorization.setUoid(user.getOid());
authorization.setUsername(user.getUsername());
String asHexToken = authorization.asHexToken(bimServer.getEncryptionKey());
serviceMap.setAuthorization(authorization);
bimServer.getAuthCache().store(asHexToken, authorization);
if (!migrationRequired && bimServer.getServerSettingsCache().getServerSettings().isStoreLastLogin()) {
user.setLastSeen(new Date());
getDatabaseSession().store(user);
}
return asHexToken;
}
}
try {
// Adding a random sleep to prevent timing attacks
Thread.sleep(DEFAULT_LOGIN_ERROR_TIMEOUT + new java.security.SecureRandom().nextInt(1000));
} catch (InterruptedException e) {
LOGGER.error("", e);
}
throw new UserException("Invalid username/password combination");
}
Aggregations