Search in sources :

Example 1 with UserDetails

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);
}
Also used : JSONArray(com.google.gwt.json.client.JSONArray) JSONString(com.google.gwt.json.client.JSONString) UserInSession(edu.stanford.bmir.protege.web.shared.app.UserInSession) JSONValue(com.google.gwt.json.client.JSONValue) ActionId(edu.stanford.bmir.protege.web.shared.access.ActionId) UserDetails(edu.stanford.bmir.protege.web.shared.user.UserDetails) JSONObject(com.google.gwt.json.client.JSONObject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) JSONString(com.google.gwt.json.client.JSONString) HashSet(java.util.HashSet)

Example 2 with UserDetails

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);
    }
}
Also used : Salt(edu.stanford.bmir.protege.web.shared.auth.Salt) UserDetails(edu.stanford.bmir.protege.web.shared.user.UserDetails) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) SaltedPasswordDigest(edu.stanford.bmir.protege.web.shared.auth.SaltedPasswordDigest) ResetPasswordResult(edu.stanford.bmir.protege.web.shared.chgpwd.ResetPasswordResult) Nonnull(javax.annotation.Nonnull)

Example 3 with UserDetails

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);
}
Also used : ActionId(edu.stanford.bmir.protege.web.shared.access.ActionId) UserDetails(edu.stanford.bmir.protege.web.shared.user.UserDetails) UserInSession(edu.stanford.bmir.protege.web.shared.app.UserInSession) Nonnull(javax.annotation.Nonnull)

Example 4 with UserDetails

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();
}
Also used : JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder) UserDetails(edu.stanford.bmir.protege.web.shared.user.UserDetails) Json(javax.json.Json) UserInSession(edu.stanford.bmir.protege.web.shared.app.UserInSession) UserInSessionEncoding(edu.stanford.bmir.protege.web.shared.app.UserInSessionEncoding) UserDetails(edu.stanford.bmir.protege.web.shared.user.UserDetails) JsonArrayBuilder(javax.json.JsonArrayBuilder)

Aggregations

UserDetails (edu.stanford.bmir.protege.web.shared.user.UserDetails)4 UserInSession (edu.stanford.bmir.protege.web.shared.app.UserInSession)3 ActionId (edu.stanford.bmir.protege.web.shared.access.ActionId)2 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)2 Nonnull (javax.annotation.Nonnull)2 JSONArray (com.google.gwt.json.client.JSONArray)1 JSONObject (com.google.gwt.json.client.JSONObject)1 JSONString (com.google.gwt.json.client.JSONString)1 JSONValue (com.google.gwt.json.client.JSONValue)1 UserInSessionEncoding (edu.stanford.bmir.protege.web.shared.app.UserInSessionEncoding)1 Salt (edu.stanford.bmir.protege.web.shared.auth.Salt)1 SaltedPasswordDigest (edu.stanford.bmir.protege.web.shared.auth.SaltedPasswordDigest)1 ResetPasswordResult (edu.stanford.bmir.protege.web.shared.chgpwd.ResetPasswordResult)1 HashSet (java.util.HashSet)1 Json (javax.json.Json)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObject (javax.json.JsonObject)1