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