use of com.enonic.xp.security.User in project xp by enonic.
the class SchedulableTaskImplTest method taskCalledWithSetUser.
@Test
public void taskCalledWithSetUser() {
mockNode();
final PropertyTree taskData = new PropertyTree();
taskData.addString("string", "value");
final User customUser = User.create().displayName("Custom").key(PrincipalKey.from("user:system:user")).login("custom").build();
final AuthenticationInfo authenticationInfo = AuthenticationInfo.create().user(customUser).principals(RoleKeys.AUTHENTICATED, RoleKeys.ADMIN).build();
when(securityService.authenticate(isA(VerifiedUsernameAuthToken.class))).thenReturn(authenticationInfo);
final SchedulableTaskImpl task = createAndRunTask(ScheduledJobName.from("task"), DescriptorKey.from("app:key"), taskData, customUser.getKey());
assertEquals("task", task.getName());
verify(taskService, times(1)).submitTask(taskCaptor.capture());
assertEquals(DescriptorKey.from("app:key"), taskCaptor.getValue().getDescriptorKey());
assertEquals(taskData, taskCaptor.getValue().getData());
}
use of com.enonic.xp.security.User in project xp by enonic.
the class PrincipalNodeTranslator method createUserFromNode.
private static User createUserFromNode(final Node node) {
Preconditions.checkNotNull(node);
final PropertyTree nodeAsTree = node.data();
final User.Builder user = User.create().email(nodeAsTree.getString(PrincipalPropertyNames.EMAIL_KEY)).login(nodeAsTree.getString(PrincipalPropertyNames.LOGIN_KEY)).key(PrincipalKeyNodeTranslator.toKey(node)).displayName(nodeAsTree.getString(PrincipalPropertyNames.DISPLAY_NAME_KEY)).authenticationHash(nodeAsTree.getString(PrincipalPropertyNames.AUTHENTICATION_HASH_KEY));
createUserProfileFromNode(nodeAsTree, user);
return user.build();
}
use of com.enonic.xp.security.User in project xp by enonic.
the class SecurityServiceImplTest method testQuery.
@Test
public void testQuery() 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("123456").build();
refresh();
final PrincipalQuery query = PrincipalQuery.create().idProvider(IdProviderKey.system()).build();
PrincipalQueryResult queryResult = securityService.query(query);
queryResult = securityService.query(query);
assertEquals(2, queryResult.getTotalSize());
final User user1 = securityService.createUser(createUser1);
refresh();
queryResult = securityService.query(query);
assertEquals(3, queryResult.getTotalSize());
assertEquals(user1, queryResult.getPrincipals().getPrincipal(userKey1));
});
}
use of com.enonic.xp.security.User in project xp by enonic.
the class SecurityServiceImplTest method testUpdateUser.
@Test
public void testUpdateUser() throws Exception {
runAsAdmin(() -> {
final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").build();
final User user = securityService.createUser(createUser);
refresh();
final UpdateUserParams updateUserParams = UpdateUserParams.create(user).email("u2@enonic.net").build();
final User updateUserResult = securityService.updateUser(updateUserParams);
refresh();
final User updatedUser = securityService.getUser(user.getKey()).get();
assertEquals("u2@enonic.net", updateUserResult.getEmail());
assertEquals("u2@enonic.net", updatedUser.getEmail());
assertEquals("User1", updatedUser.getLogin());
assertEquals("User 1", updatedUser.getDisplayName());
assertEquals(PrincipalKey.ofUser(SYSTEM, "User1"), updatedUser.getKey());
});
}
use of com.enonic.xp.security.User in project xp by enonic.
the class SecurityServiceImplTest method testAuthenticateByUsername.
@Test
public void testAuthenticateByUsername() throws Exception {
runAsAdmin(() -> {
final CreateUserParams createUser = CreateUserParams.create().userKey(PrincipalKey.ofUser(SYSTEM, "User1")).displayName("User 1").email("user1@enonic.com").login("User1").password("runar").build();
final User user = securityService.createUser(createUser);
refresh();
final VerifiedUsernameAuthToken authToken = new VerifiedUsernameAuthToken();
authToken.setUsername("user1");
authToken.setIdProvider(SYSTEM);
final AuthenticationInfo authInfo = securityService.authenticate(authToken);
assertTrue(authInfo.isAuthenticated());
assertEquals(user.getKey(), authInfo.getUser().getKey());
});
}
Aggregations