Search in sources :

Example 1 with UserInSession

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

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

the class LoginPresenter method handlePerformLoginResult.

private void handlePerformLoginResult(@Nonnull PerformLoginResult result) {
    if (result.getResponse() == AuthenticationResponse.SUCCESS) {
        UserInSession userInSession = result.getUserInSession();
        loggedInUserManager.setLoggedInUser(userInSession);
        nextPlace.ifPresent(placeController::goTo);
    } else {
        view.showLoginFailedErrorMessage();
    }
}
Also used : UserInSession(edu.stanford.bmir.protege.web.shared.app.UserInSession)

Example 3 with UserInSession

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

the class DispatchServiceCallbackWithProgress_TestCase method shouldCall_handlePermissionDeniedException.

@Test
public void shouldCall_handlePermissionDeniedException() {
    PermissionDeniedException exception = mock(PermissionDeniedException.class);
    UserInSession userInSession = mock(UserInSession.class);
    when(userInSession.isGuest()).thenReturn(false);
    when(exception.getUserInSession()).thenReturn(userInSession);
    callback.onFailure(exception);
    verify(callback, times(1)).handlePermissionDeniedException(exception);
    verify(messageDisplay, times(1)).displayPermissionDeniedErrorMessage();
}
Also used : PermissionDeniedException(edu.stanford.bmir.protege.web.shared.permissions.PermissionDeniedException) UserInSession(edu.stanford.bmir.protege.web.shared.app.UserInSession) Test(org.junit.Test)

Example 4 with UserInSession

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

the class UserInSessionFactory_TestCase method shouldProvideUserInSession.

@Test
public void shouldProvideUserInSession() {
    UserInSession userInSession = factory.getUserInSession(userId);
    assertThat(userInSession.getUserDetails(), is(userDetails));
    assertThat(userInSession.getAllowedApplicationActions(), is(appActions));
}
Also used : UserInSession(edu.stanford.bmir.protege.web.shared.app.UserInSession) Test(org.junit.Test)

Example 5 with UserInSession

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

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