Search in sources :

Example 1 with User

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);
}
Also used : Context(com.enonic.xp.context.Context) User(com.enonic.xp.security.User) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Session(com.enonic.xp.session.Session) SessionMock(com.enonic.xp.session.SessionMock) Test(org.junit.jupiter.api.Test)

Example 2 with User

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);
}
Also used : Context(com.enonic.xp.context.Context) User(com.enonic.xp.security.User) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Principal(java.security.Principal) Session(com.enonic.xp.session.Session) SessionMock(com.enonic.xp.session.SessionMock) Test(org.junit.jupiter.api.Test)

Example 3 with User

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");
}
Also used : User(com.enonic.xp.security.User) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with User

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");
}
Also used : User(com.enonic.xp.security.User) EditableUser(com.enonic.xp.security.EditableUser) UpdateUserParams(com.enonic.xp.security.UpdateUserParams) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 5 with User

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());
    }
}
Also used : User(com.enonic.xp.security.User)

Aggregations

User (com.enonic.xp.security.User)63 Test (org.junit.jupiter.api.Test)40 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)22 PropertyTree (com.enonic.xp.data.PropertyTree)17 PrincipalKey (com.enonic.xp.security.PrincipalKey)17 Context (com.enonic.xp.context.Context)14 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)11 CreateUserParams (com.enonic.xp.security.CreateUserParams)10 IdProviderKey (com.enonic.xp.security.IdProviderKey)10 Node (com.enonic.xp.node.Node)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 UpdateUserParams (com.enonic.xp.security.UpdateUserParams)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Mockito (org.mockito.Mockito)6 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)4 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)4 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 TaskId (com.enonic.xp.task.TaskId)4