use of com.enonic.xp.security.User in project xp by enonic.
the class IdProviderRequestWrapperTest method isUserInRole.
@Test
void isUserInRole() {
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.createDefault(), "userId")).login("usr").build();
final AuthenticationInfo authenticationInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN).build();
final Context context = ContextBuilder.create().build();
final Session session = new SessionMock();
context.getLocalScope().setSession(session);
session.setAttribute(authenticationInfo);
final Boolean isAdmin = context.callWith(() -> new IdProviderRequestWrapper(request).isUserInRole(RoleKeys.ADMIN.getId()));
assertTrue(isAdmin);
verifyNoInteractions(request);
}
use of com.enonic.xp.security.User in project xp by enonic.
the class IdProviderRequestWrapperTest method getUserPrincipal.
@Test
void getUserPrincipal() {
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.createDefault(), "userId")).login("usr").build();
final AuthenticationInfo authenticationInfo = AuthenticationInfo.create().user(user).build();
final Context context = ContextBuilder.create().build();
final Session session = new SessionMock();
context.getLocalScope().setSession(session);
session.setAttribute(authenticationInfo);
final Principal principal = context.callWith(() -> new IdProviderRequestWrapper(request).getUserPrincipal());
assertEquals(principal, user);
verifyNoInteractions(request);
}
use of com.enonic.xp.security.User in project xp by enonic.
the class IssueServiceImplTest_findComments method setup.
@BeforeEach
public void setup() {
this.issue = this.createIssue(CreateIssueParams.create().title("issue-1"));
final User creator = User.ANONYMOUS;
final User creator2 = User.create().key(PrincipalKey.from("user:store:user2")).login("user2").email("user2@email.com").displayName("User 2").build();
this.createComment(creator, "Comment One");
this.createComment(creator, "Comment Two");
this.createComment(creator2, "Another Comment");
}
use of com.enonic.xp.security.User in project xp by enonic.
the class ModifyProfileHandlerTest method keep_original_value_types_when_not_touched.
@Test
public void keep_original_value_types_when_not_touched() {
final User user = TestDataFixtures.getTestUserWithProfile();
Mockito.when(securityService.getUser(Mockito.any())).thenReturn(Optional.of(user));
Mockito.when(this.securityService.updateUser(Mockito.isA(UpdateUserParams.class))).thenAnswer(invocationOnMock -> {
final User editedUser = invokeUpdate((UpdateUserParams) invocationOnMock.getArguments()[0], user);
final PropertySet profile = editedUser.getProfile().getSet("myApp");
assertTrue(profile.getProperty("untouchedString").getType().equals(ValueTypes.STRING));
assertTrue(profile.getProperty("untouchedBoolean").getType().equals(ValueTypes.BOOLEAN));
assertTrue(profile.getProperty("untouchedDouble").getType().equals(ValueTypes.DOUBLE));
assertTrue(profile.getProperty("untouchedLong").getType().equals(ValueTypes.LONG));
assertTrue(profile.getProperty("untouchedLink").getType().equals(ValueTypes.LINK));
assertTrue(profile.getProperty("untouchedInstant").getType().equals(ValueTypes.DATE_TIME));
assertTrue(profile.getProperty("untouchedGeoPoint").getType().equals(ValueTypes.GEO_POINT));
assertTrue(profile.getProperty("untouchedLocalDate").getType().equals(ValueTypes.LOCAL_DATE));
assertTrue(profile.getProperty("untouchedReference").getType().equals(ValueTypes.REFERENCE));
assertTrue(profile.getProperty("untouchedBinaryRef").getType().equals(ValueTypes.BINARY_REFERENCE));
return editedUser;
});
runScript("/test/modifyProfile-test.js");
}
use of com.enonic.xp.security.User in project xp by enonic.
the class PrincipalMapper method serialize.
private void serialize(final MapGenerator gen, final Principal value) {
gen.value("type", value.getClass().getSimpleName().toLowerCase());
gen.value("key", value.getKey());
gen.value("displayName", value.getDisplayName());
gen.value("modifiedTime", value.getModifiedTime());
if (value instanceof User) {
final User user = (User) value;
gen.value("disabled", user.isDisabled());
gen.value("email", user.getEmail());
gen.value("login", user.getLogin());
gen.value("idProvider", value.getKey() != null ? value.getKey().getIdProviderKey() : null);
serializeProfile(gen, user.getProfile());
} else {
gen.value("description", value.getDescription());
}
}
Aggregations