use of com.enonic.xp.security.User 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.User in project xp by enonic.
the class LocalTaskManagerImpl method prepareRunnable.
private Runnable prepareRunnable(final DescribedTask runnableTask) {
final TaskId id = runnableTask.getTaskId();
final User user = Objects.requireNonNullElse(runnableTask.getTaskContext().getAuthInfo().getUser(), User.ANONYMOUS);
final TaskInfo info = TaskInfo.create().id(id).description(runnableTask.getDescription()).name(runnableTask.getName()).state(TaskState.WAITING).startTime(Instant.now(clock)).application(runnableTask.getApplicationKey()).user(user.getKey()).build();
final TaskInfoHolder taskInfoHolder = TaskInfoHolder.create().taskInfo(info).build();
tasks.put(id, taskInfoHolder);
eventPublisher.publish(TaskEvents.submitted(info));
return new TaskRunnable(runnableTask, new ProgressReporterAdapter(id));
}
use of com.enonic.xp.security.User in project xp by enonic.
the class SecurityServiceImpl method doCreateUser.
private User doCreateUser(final CreateUserParams createUser) {
final User user = User.create().key(createUser.getKey()).login(createUser.getLogin()).email(createUser.getEmail()).displayName(createUser.getDisplayName()).modifiedTime(Instant.now(clock)).build();
final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(user);
try {
final Node node = callWithContext(() -> {
final Node createdNode = nodeService.create(createNodeParams);
this.nodeService.refresh(RefreshMode.SEARCH);
return createdNode;
});
if (createUser.getPassword() != null) {
return setPassword(user.getKey(), createUser.getPassword());
}
return PrincipalNodeTranslator.userFromNode(node);
} catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
throw new PrincipalAlreadyExistsException(createUser.getKey());
}
}
use of com.enonic.xp.security.User in project xp by enonic.
the class PrincipalKeyNodeTranslatorTest method toNodeName.
@Test
public void toNodeName() throws Exception {
PrincipalKey principalKey = PrincipalKey.ofUser(IdProviderKey.from("myidprovider"), "rmy");
User user = User.create().key(principalKey).email("rmy@enonic.com").login("rmy").displayName("Runar Myklebust").modifiedTime(Instant.now(clock)).build();
String nodeName = PrincipalKeyNodeTranslator.toNodeName(user.getKey()).toString();
assertEquals("rmy", nodeName);
}
use of com.enonic.xp.security.User in project xp by enonic.
the class UserNodeTranslatorTest method toCreateNode.
@Test
public void toCreateNode() throws Exception {
final User user = User.create().displayName("displayname").email("rmy@enonic.com").login("login").authenticationHash("password").key(PrincipalKey.ofUser(IdProviderKey.system(), "rmy")).modifiedTime(Instant.now(clock)).build();
final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(user);
assertEquals("rmy", createNodeParams.getName());
final PropertyTree rootDataSet = createNodeParams.getData();
assertEquals(IdProviderKey.system().toString(), rootDataSet.getString(PrincipalPropertyNames.ID_PROVIDER_KEY));
assertEquals(PrincipalType.USER.toString(), rootDataSet.getString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY));
assertEquals("displayname", rootDataSet.getString(PrincipalPropertyNames.DISPLAY_NAME_KEY));
assertNotNull(rootDataSet);
assertEquals(7, rootDataSet.getTotalSize());
}
Aggregations