use of edu.stanford.bmir.protege.web.shared.user.UserDetails in project webprotege by protegeproject.
the class UserInSessionDecoder method decode.
@Override
public UserInSession decode(JSONValue json) {
JSONObject object = json.isObject();
if (object == null) {
throw new RuntimeException("Expected json object");
}
JSONValue userNameValue = object.get(USER_NAME);
if (userNameValue == null) {
throw new RuntimeException("Expected userName attribute");
}
JSONString userNameStringValue = userNameValue.isString();
if (userNameStringValue == null) {
throw new RuntimeException("Expected userName value to be string");
}
String displayName = object.get(DISPLAY_NAME).isString().stringValue();
String userEmail = object.get(USER_EMAIL).isString().stringValue();
JSONArray actionArray = object.get(APPLICATION_ACTIONS).isArray();
Set<ActionId> allowedActions = new HashSet<>();
if (actionArray != null) {
for (int i = 0; i < actionArray.size(); i++) {
ActionId actionId = new ActionId(actionArray.get(i).isString().stringValue());
allowedActions.add(actionId);
}
}
UserId userId = UserId.getUserId(userNameStringValue.stringValue());
UserDetails userDetails;
if (userId.isGuest()) {
userDetails = UserDetails.getGuestUserDetails();
} else {
userDetails = UserDetails.getUserDetails(userId, displayName, userEmail);
}
return new UserInSession(userDetails, allowedActions);
}
use of edu.stanford.bmir.protege.web.shared.user.UserDetails in project webprotege by protegeproject.
the class ResetPasswordActionHandler method execute.
@Nonnull
@Override
public ResetPasswordResult execute(@Nonnull ResetPasswordAction action, @Nonnull ExecutionContext executionContext) {
final String emailAddress = action.getResetPasswordData().getEmailAddress();
try {
Optional<UserId> userId = userDetailsManager.getUserByUserIdOrEmail(emailAddress);
if (!userId.isPresent()) {
return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
}
Optional<UserDetails> userDetails = userDetailsManager.getUserDetails(userId.get());
if (!userDetails.isPresent()) {
return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
}
if (!userDetails.get().getEmailAddress().isPresent()) {
return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
}
if (!userDetails.get().getEmailAddress().get().equalsIgnoreCase(emailAddress)) {
return new ResetPasswordResult(INVALID_EMAIL_ADDRESS);
}
String pwd = IdUtil.getBase62UUID();
Salt salt = saltProvider.get();
SaltedPasswordDigest saltedPasswordDigest = passwordDigestAlgorithm.getDigestOfSaltedPassword(pwd, salt);
authenticationManager.setDigestedPassword(userId.get(), saltedPasswordDigest, salt);
mailer.sendEmail(userId.get(), emailAddress, pwd, ex -> {
throw new RuntimeException(ex);
});
logger.info("The password for {} has been reset. " + "An email has been sent to {} that contains the new password.", userId.get().getUserName(), emailAddress);
return new ResetPasswordResult(SUCCESS);
} catch (Exception e) {
logger.error("Could not reset the user password " + "associated with the email " + "address {}. The following " + "error occurred: {}.", emailAddress, e.getMessage(), e);
return new ResetPasswordResult(INTERNAL_ERROR);
}
}
use of edu.stanford.bmir.protege.web.shared.user.UserDetails in project webprotege by protegeproject.
the class UserInSessionFactory method getUserInSession.
/**
* Gets the user in session for the specified user id.
* @param userId The user id. This can be the id of the guest user.
*/
@Nonnull
public UserInSession getUserInSession(@Nonnull UserId userId) {
UserDetails userDetails = userDetailsManager.getUserDetails(userId).orElse(UserDetails.getGuestUserDetails());
Set<ActionId> actionClosure = accessManager.getActionClosure(forUser(userId), ApplicationResource.get());
return new UserInSession(userDetails, actionClosure);
}
use of edu.stanford.bmir.protege.web.shared.user.UserDetails in project webprotege by protegeproject.
the class UserInSessionEncoder method encode.
@Override
public JsonObject encode(UserInSession object) {
UserDetails userDetails = object.getUserDetails();
JsonArrayBuilder actionArray = Json.createArrayBuilder();
object.getAllowedApplicationActions().stream().map(a -> a.getId()).forEach(a -> actionArray.add(a));
return Json.createObjectBuilder().add(USER_NAME, userDetails.getUserId().getUserName()).add(DISPLAY_NAME, userDetails.getDisplayName()).add(USER_EMAIL, userDetails.getEmailAddress().orElse("")).add(APPLICATION_ACTIONS, actionArray).build();
}
Aggregations