Search in sources :

Example 6 with CreateUserParams

use of com.enonic.xp.security.CreateUserParams in project xp by enonic.

the class SecurityServiceImplTest method testUpdateUserDuplicatedEmail.

@Test
public void testUpdateUserDuplicatedEmail() {
    try {
        runAsAdmin(() -> {
            final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
            final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("same_email@enonic.com").login("User1").password("123456").build();
            final PrincipalKey userKey2 = PrincipalKey.ofUser(SYSTEM, "user2");
            final CreateUserParams createUser2 = CreateUserParams.create().userKey(userKey2).displayName("User 2").email("same_email@enonic.com").login("user2").build();
            final User user1 = securityService.createUser(createUser1);
            securityService.createUser(createUser2);
            final UpdateUserParams updateUserParams = UpdateUserParams.create(user1).email("same_email@enonic.com").build();
            securityService.updateUser(updateUserParams);
            refresh();
        });
        fail("Expected exception");
    } catch (IllegalArgumentException e) {
        assertEquals("A user with email 'same_email@enonic.com' already exists in id provider 'system'", e.getMessage());
    }
}
Also used : CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) UpdateUserParams(com.enonic.xp.security.UpdateUserParams) PrincipalKey(com.enonic.xp.security.PrincipalKey) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with CreateUserParams

use of com.enonic.xp.security.CreateUserParams in project xp by enonic.

the class SecurityServiceImplTest method testAuthenticateByEmail.

@Test
public void testAuthenticateByEmail() throws Exception {
    runAsAdmin(() -> {
        final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").password("password").build();
        final User user = securityService.createUser(createUser);
        refresh();
        final VerifiedEmailAuthToken authToken = new VerifiedEmailAuthToken();
        authToken.setEmail("user1@enonic.com");
        authToken.setIdProvider(SYSTEM);
        final AuthenticationInfo authInfo = securityService.authenticate(authToken);
        assertTrue(authInfo.isAuthenticated());
        assertEquals(user.getKey(), authInfo.getUser().getKey());
    });
}
Also used : CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) VerifiedEmailAuthToken(com.enonic.xp.security.auth.VerifiedEmailAuthToken) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 8 with CreateUserParams

use of com.enonic.xp.security.CreateUserParams in project xp by enonic.

the class SecurityServiceImplTest method testCreateUserDuplicatedEmail.

@Test
public void testCreateUserDuplicatedEmail() {
    try {
        runAsAdmin(() -> {
            final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
            final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("same_email@enonic.com").login("User1").password("123456").build();
            final PrincipalKey userKey2 = PrincipalKey.ofUser(SYSTEM, "user2");
            final CreateUserParams createUser2 = CreateUserParams.create().userKey(userKey2).displayName("User 2").email("same_email@enonic.com").login("user2").build();
            securityService.createUser(createUser1);
            securityService.createUser(createUser2);
        });
        fail("Expected exception");
    } catch (IllegalArgumentException e) {
        assertEquals("A user with email 'same_email@enonic.com' already exists in id provider 'system'", e.getMessage());
    }
}
Also used : CreateUserParams(com.enonic.xp.security.CreateUserParams) PrincipalKey(com.enonic.xp.security.PrincipalKey) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with CreateUserParams

use of com.enonic.xp.security.CreateUserParams in project xp by enonic.

the class SecurityServiceImplTest method setPassword.

@Test
public void setPassword() throws Exception {
    runAsAdmin(() -> {
        final PrincipalKey userKey1 = PrincipalKey.ofUser(SYSTEM, "User1");
        final CreateUserParams createUser1 = CreateUserParams.create().userKey(userKey1).displayName("User 1").email("user1@enonic.com").login("User1").password("fisk").build();
        final User user = securityService.createUser(createUser1);
        refresh();
        final UsernamePasswordAuthToken authToken = new UsernamePasswordAuthToken();
        authToken.setUsername("user1");
        authToken.setPassword("runar");
        authToken.setIdProvider(SYSTEM);
        AuthenticationInfo authInfo = securityService.authenticate(authToken);
        assertFalse(authInfo.isAuthenticated());
        securityService.setPassword(user.getKey(), "runar");
        AuthenticationInfo authInfo2 = securityService.authenticate(authToken);
        assertTrue(authInfo2.isAuthenticated());
    });
}
Also used : CreateUserParams(com.enonic.xp.security.CreateUserParams) User(com.enonic.xp.security.User) UsernamePasswordAuthToken(com.enonic.xp.security.auth.UsernamePasswordAuthToken) PrincipalKey(com.enonic.xp.security.PrincipalKey) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with CreateUserParams

use of com.enonic.xp.security.CreateUserParams in project xp by enonic.

the class SecurityInitializer method createUsers.

private void createUsers() {
    final CreateUserParams createAnonymousUser = CreateUserParams.create().userKey(PrincipalKey.ofAnonymous()).displayName("Anonymous User").login("anonymous").build();
    addUser(createAnonymousUser);
    final CreateUserParams createSuperUser = CreateUserParams.create().userKey(SUPER_USER).displayName("Super User").login(SUPER_USER.getId()).build();
    addUser(createSuperUser);
    addMember(RoleKeys.ADMIN, createSuperUser.getKey());
}
Also used : CreateUserParams(com.enonic.xp.security.CreateUserParams)

Aggregations

CreateUserParams (com.enonic.xp.security.CreateUserParams)19 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)18 Test (org.junit.jupiter.api.Test)18 PrincipalKey (com.enonic.xp.security.PrincipalKey)11 User (com.enonic.xp.security.User)10 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)7 CreateGroupParams (com.enonic.xp.security.CreateGroupParams)6 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)3 PrincipalRelationship (com.enonic.xp.security.PrincipalRelationship)3 PrincipalRelationships (com.enonic.xp.security.PrincipalRelationships)3 UpdateUserParams (com.enonic.xp.security.UpdateUserParams)3 EmailPasswordAuthToken (com.enonic.xp.security.auth.EmailPasswordAuthToken)3 UsernamePasswordAuthToken (com.enonic.xp.security.auth.UsernamePasswordAuthToken)3 CreateRoleParams (com.enonic.xp.security.CreateRoleParams)2 PrincipalQuery (com.enonic.xp.security.PrincipalQuery)2 VerifiedEmailAuthToken (com.enonic.xp.security.auth.VerifiedEmailAuthToken)2 Context (com.enonic.xp.context.Context)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 EventPublisher (com.enonic.xp.event.EventPublisher)1 MemoryBlobStore (com.enonic.xp.internal.blobstore.MemoryBlobStore)1