Search in sources :

Example 11 with UserInSession

use of edu.stanford.bmir.protege.web.shared.app.UserInSession 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)

Example 12 with UserInSession

use of edu.stanford.bmir.protege.web.shared.app.UserInSession in project webprotege by protegeproject.

the class DispatchServiceManager method handleError.

private void handleError(final Throwable throwable, final Action<?> action, final DispatchServiceCallback<?> callback) {
    if (throwable instanceof PermissionDeniedException) {
        // Try to determine if the user is logged in.  The session might have expired.
        UserInSession userInSession = ((PermissionDeniedException) throwable).getUserInSession();
        if (userInSession.isGuest()) {
            // Set up next place
            Place continueTo = placeController.getWhere();
            loggedInUser.setLoggedInUser(userInSession);
            GWT.log("[Dispatch] Permission denied.  User is the guest user so redirecting to login.");
            signInRequiredHandler.handleSignInRequired(continueTo);
        }
    }
    // Skip handling for actions that do not care about errors
    if (action instanceof InvocationExceptionTolerantAction) {
        Optional<String> errorMessage = ((InvocationExceptionTolerantAction) action).handleInvocationException((InvocationException) throwable);
        errorMessage.ifPresent(this::displayAlert);
        return;
    }
    callback.onFailure(throwable);
}
Also used : PermissionDeniedException(edu.stanford.bmir.protege.web.shared.permissions.PermissionDeniedException) UserInSession(edu.stanford.bmir.protege.web.shared.app.UserInSession) Place(com.google.gwt.place.shared.Place)

Example 13 with UserInSession

use of edu.stanford.bmir.protege.web.shared.app.UserInSession in project webprotege by protegeproject.

the class GetCurrentUserInSessionActionHandler method execute.

@Nonnull
@Override
public GetCurrentUserInSessionResult execute(@Nonnull GetCurrentUserInSessionAction action, @Nonnull ExecutionContext executionContext) {
    UserId userId = executionContext.getUserId();
    UserInSession userInSession = userInSessionFactory.getUserInSession(userId);
    return new GetCurrentUserInSessionResult(userInSession);
}
Also used : UserId(edu.stanford.bmir.protege.web.shared.user.UserId) GetCurrentUserInSessionResult(edu.stanford.bmir.protege.web.shared.dispatch.actions.GetCurrentUserInSessionResult) UserInSession(edu.stanford.bmir.protege.web.shared.app.UserInSession) Nonnull(javax.annotation.Nonnull)

Aggregations

UserInSession (edu.stanford.bmir.protege.web.shared.app.UserInSession)13 Test (org.junit.Test)5 PermissionDeniedException (edu.stanford.bmir.protege.web.shared.permissions.PermissionDeniedException)3 UserDetails (edu.stanford.bmir.protege.web.shared.user.UserDetails)3 JSONObject (com.google.gwt.json.client.JSONObject)2 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 JSONString (com.google.gwt.json.client.JSONString)1 JSONValue (com.google.gwt.json.client.JSONValue)1 Place (com.google.gwt.place.shared.Place)1 UserInSessionDecoder (edu.stanford.bmir.protege.web.client.app.UserInSessionDecoder)1 UserInSessionEncoding (edu.stanford.bmir.protege.web.shared.app.UserInSessionEncoding)1 GetCurrentUserInSessionResult (edu.stanford.bmir.protege.web.shared.dispatch.actions.GetCurrentUserInSessionResult)1 HashSet (java.util.HashSet)1 Json (javax.json.Json)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObject (javax.json.JsonObject)1