use of com.enonic.xp.security.PrincipalKey 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.PrincipalKey in project xp by enonic.
the class SecurityServiceImplTest method testGetUserMemberships.
@Test
public void testGetUserMemberships() throws Exception {
runAsAdmin(() -> {
final PrincipalKey userKey = PrincipalKey.ofUser(SYSTEM, "User1");
final CreateUserParams createUser = CreateUserParams.create().userKey(userKey).displayName("User 1").email("user1@enonic.com").login("User1").password("123456").build();
final PrincipalKey groupKey1 = PrincipalKey.ofGroup(SYSTEM, "Group-a");
final CreateGroupParams createGroup1 = CreateGroupParams.create().groupKey(groupKey1).displayName("Group A").build();
final PrincipalKey groupKey2 = PrincipalKey.ofGroup(SYSTEM, "group-b");
final CreateGroupParams createGroup2 = CreateGroupParams.create().groupKey(groupKey2).displayName("Group B").build();
securityService.createUser(createUser);
securityService.createGroup(createGroup1);
securityService.createGroup(createGroup2);
securityService.addRelationship(PrincipalRelationship.from(groupKey1).to(userKey));
securityService.addRelationship(PrincipalRelationship.from(groupKey2).to(userKey));
refresh();
final PrincipalKeys memberships = securityService.getMemberships(userKey);
assertTrue(memberships.contains(groupKey1));
assertTrue(memberships.contains(groupKey2));
assertEquals(2, memberships.getSize());
});
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class GroupNodeTranslatorTest method toGroup.
@Test
public void toGroup() throws Exception {
final PrincipalKey groupKey = PrincipalKey.ofGroup(IdProviderKey.system(), "group-a");
final PropertyTree rootDataSet = new PropertyTree();
rootDataSet.setString(PrincipalPropertyNames.DISPLAY_NAME_KEY, "Group A");
rootDataSet.setString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY, groupKey.getType().toString());
rootDataSet.setString(PrincipalPropertyNames.ID_PROVIDER_KEY, groupKey.getIdProviderKey().toString());
final Node node = Node.create().id(NodeId.from("id")).name(PrincipalKeyNodeTranslator.toNodeName(groupKey)).data(rootDataSet).build();
final Group group = PrincipalNodeTranslator.groupFromNode(node);
assertEquals(groupKey, group.getKey());
}
use of com.enonic.xp.security.PrincipalKey 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.PrincipalKey in project xp by enonic.
the class ChangePasswordHandler method changePassword.
public void changePassword() {
final PrincipalKey principalKey = PrincipalKey.from(userKey);
this.securityService.get().setPassword(principalKey, normalize(password));
}
Aggregations