Search in sources :

Example 26 with User

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());
    });
}
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 27 with User

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

Example 28 with User

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());
    }
}
Also used : User(com.enonic.xp.security.User) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 29 with User

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

Example 30 with User

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());
}
Also used : User(com.enonic.xp.security.User) PropertyTree(com.enonic.xp.data.PropertyTree) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

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