Search in sources :

Example 1 with ActionId

use of edu.stanford.bmir.protege.web.shared.access.ActionId 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 ActionId

use of edu.stanford.bmir.protege.web.shared.access.ActionId 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 3 with ActionId

use of edu.stanford.bmir.protege.web.shared.access.ActionId in project webprotege by protegeproject.

the class AbstractProjectActionHandler method getRequestValidator.

@Nonnull
@Override
public final RequestValidator getRequestValidator(@Nonnull A action, @Nonnull RequestContext requestContext) {
    List<RequestValidator> validators = new ArrayList<>();
    BuiltInAction builtInAction = getRequiredExecutableBuiltInAction();
    if (builtInAction != null) {
        ProjectPermissionValidator validator = new ProjectPermissionValidator(accessManager, action.getProjectId(), requestContext.getUserId(), builtInAction.getActionId());
        validators.add(validator);
    }
    ActionId reqActionId = getRequiredExecutableAction();
    if (reqActionId != null) {
        ProjectPermissionValidator validator = new ProjectPermissionValidator(accessManager, action.getProjectId(), requestContext.getUserId(), reqActionId);
        validators.add(validator);
    }
    Iterable<BuiltInAction> requiredExecutableBuiltInActions = getRequiredExecutableBuiltInActions();
    for (BuiltInAction actionId : requiredExecutableBuiltInActions) {
        ProjectPermissionValidator validator = new ProjectPermissionValidator(accessManager, action.getProjectId(), requestContext.getUserId(), actionId.getActionId());
        validators.add(validator);
    }
    final RequestValidator additionalRequestValidator = getAdditionalRequestValidator(action, requestContext);
    if (additionalRequestValidator != NullValidator.get()) {
        validators.add(additionalRequestValidator);
    }
    return CompositeRequestValidator.get(validators);
}
Also used : ProjectPermissionValidator(edu.stanford.bmir.protege.web.server.dispatch.validators.ProjectPermissionValidator) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) ActionId(edu.stanford.bmir.protege.web.shared.access.ActionId) CompositeRequestValidator(edu.stanford.bmir.protege.web.server.dispatch.validators.CompositeRequestValidator) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Example 4 with ActionId

use of edu.stanford.bmir.protege.web.shared.access.ActionId in project webprotege by protegeproject.

the class RoleOracleImpl method get.

public static RoleOracleImpl get() {
    RoleOracleImpl impl = new RoleOracleImpl();
    for (BuiltInRole builtInRole : BuiltInRole.values()) {
        List<RoleId> parentRoles = builtInRole.getParents().stream().map(BuiltInRole::getRoleId).collect(toList());
        List<ActionId> actions = builtInRole.getActions().stream().map(BuiltInAction::getActionId).collect(toList());
        impl.addRole(new Role(builtInRole.getRoleId(), parentRoles, actions));
    }
    return impl;
}
Also used : BuiltInRole(edu.stanford.bmir.protege.web.shared.access.BuiltInRole) ActionId(edu.stanford.bmir.protege.web.shared.access.ActionId) BuiltInRole(edu.stanford.bmir.protege.web.shared.access.BuiltInRole) RoleId(edu.stanford.bmir.protege.web.shared.access.RoleId)

Aggregations

ActionId (edu.stanford.bmir.protege.web.shared.access.ActionId)4 UserInSession (edu.stanford.bmir.protege.web.shared.app.UserInSession)2 UserDetails (edu.stanford.bmir.protege.web.shared.user.UserDetails)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 CompositeRequestValidator (edu.stanford.bmir.protege.web.server.dispatch.validators.CompositeRequestValidator)1 ProjectPermissionValidator (edu.stanford.bmir.protege.web.server.dispatch.validators.ProjectPermissionValidator)1 BuiltInAction (edu.stanford.bmir.protege.web.shared.access.BuiltInAction)1 BuiltInRole (edu.stanford.bmir.protege.web.shared.access.BuiltInRole)1 RoleId (edu.stanford.bmir.protege.web.shared.access.RoleId)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1