use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class IssueServiceImplTest_updateComment method updateComment.
@Test
public void updateComment() throws Exception {
Issue issue = this.createIssue(CreateIssueParams.create().title("issue-1"));
final Instant created = Instant.now().minus(1, ChronoUnit.MINUTES);
final PrincipalKey creator = PrincipalKey.from("user:store:me");
final String creatorDisplayName = "Me Myself";
final CreateIssueCommentParams params = CreateIssueCommentParams.create().text("text").issue(issue.getId()).creator(creator).creatorDisplayName(creatorDisplayName).created(created).build();
final IssueComment comment = this.issueService.createComment(params);
final IssueComment updatedComment = this.issueService.updateComment(UpdateIssueCommentParams.create().comment(comment.getId()).text("updated text").build());
assertNotNull(updatedComment);
assertEquals("updated text", updatedComment.getText());
assertEquals(creator, updatedComment.getCreator());
assertEquals(creatorDisplayName, updatedComment.getCreatorDisplayName());
assertEquals(created, updatedComment.getCreated());
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class JsonExceptionMapper method createContextJson.
private static ObjectNode createContextJson() {
final Context context = ContextAccessor.current();
final AuthenticationInfo authInfo = context.getAuthInfo();
final ObjectNode node = JsonNodeFactory.instance.objectNode();
node.put("authenticated", (authInfo != null) && authInfo.isAuthenticated());
final ArrayNode principals = node.putArray("principals");
if (authInfo != null) {
for (final PrincipalKey principal : authInfo.getPrincipals()) {
principals.add(principal.toString());
}
}
return node;
}
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));
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class GetMembershipsHandlerTest method testGetTransitiveUserMemberships.
@Test
public void testGetTransitiveUserMemberships() {
final Group group = TestDataFixtures.getTestGroup();
final PrincipalKeys principalKeys = PrincipalKeys.from(group.getKey());
final PrincipalKey pKey = PrincipalKey.from("user:myIdProvider:userId");
Mockito.when(securityService.getAllMemberships(pKey)).thenReturn(principalKeys);
Mockito.verify(securityService, Mockito.never()).getMemberships(pKey);
Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(group));
runFunction("/test/getMemberships-test.js", "getTransitiveUserMemberships");
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class XmlServiceDescriptorParser method doParse.
@Override
protected void doParse(final DomElement root) throws Exception {
assertTagName(root, "service");
final DomElement allowedPrincipals = root.getChild("allow");
if (allowedPrincipals != null) {
final List<PrincipalKey> allowedPrincipalKeys = new ArrayList<>();
final List<DomElement> allowedPrincipalList = allowedPrincipals.getChildren("principal");
for (DomElement allowedPrincipal : allowedPrincipalList) {
allowedPrincipalKeys.add(PrincipalKey.from(allowedPrincipal.getValue().trim()));
}
this.builder.setAllowedPrincipals(allowedPrincipalKeys);
}
}
Aggregations