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);
}
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();
}
}
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();
}
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));
}
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);
}
Aggregations