use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class SecurityAuditLogSupportImpl method log.
private void log(final String type, final PropertyTree data, final AuditLogUris uris) {
final Context context = ContextBuilder.copyOf(ContextAccessor.current()).build();
final PrincipalKey userPrincipalKey = context.getAuthInfo().getUser() != null ? context.getAuthInfo().getUser().getKey() : PrincipalKey.ofAnonymous();
ContextBuilder.from(context).authInfo(AuthenticationInfo.copyOf(context.getAuthInfo()).principals(RoleKeys.AUDIT_LOG).build()).build().callWith(() -> auditLogService.log(LogAuditLogParams.create().type(type).source(SOURCE).data(data).objectUris(uris).user(userPrincipalKey).build()));
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class GetMembershipsHandlerTest method testGetUserMemberships.
@Test
public void testGetUserMemberships() {
final Group group = TestDataFixtures.getTestGroup();
final PrincipalKeys principalKeys = PrincipalKeys.from(group.getKey());
final PrincipalKey pKey = PrincipalKey.from("user:myIdProvider:userId");
Mockito.when(securityService.getMemberships(pKey)).thenReturn(principalKeys);
Mockito.verify(securityService, Mockito.never()).getAllMemberships(pKey);
Mockito.when(securityService.getPrincipals(principalKeys)).thenReturn(Principals.from(group));
runFunction("/test/getMemberships-test.js", "getUserMemberships");
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class DeletePrincipalHandlerTest method testDeleteNonExistingUser.
@Test
public void testDeleteNonExistingUser() {
final PrincipalKey principalKey = PrincipalKey.from("user:myIdProvider:XXX");
Mockito.doThrow(new PrincipalNotFoundException(principalKey)).when(securityService).deletePrincipal(principalKey);
runFunction("/test/deletePrincipal-test.js", "deleteNonExistingUser");
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class ServiceHandlerTest method testForbiddenService.
@Test
public void testForbiddenService() throws Exception {
final DescriptorKey serviceDescriptorKey = DescriptorKey.from("demo:test");
final Set<PrincipalKey> allowedPrincipals = Collections.singleton(PrincipalKey.from("role:system.admin"));
final ServiceDescriptor serviceDescriptor = ServiceDescriptor.create().key(serviceDescriptorKey).setAllowedPrincipals(allowedPrincipals).build();
Mockito.when(this.serviceDescriptorService.getByKey(serviceDescriptorKey)).thenReturn(serviceDescriptor);
this.request.setEndpointPath("/_/service/demo/test");
boolean forbiddenErrorThrown = false;
try {
this.handler.handle(this.request, PortalResponse.create().build(), null);
} catch (WebException e) {
if (HttpStatus.UNAUTHORIZED == e.getStatus()) {
forbiddenErrorThrown = true;
}
}
assertTrue(forbiddenErrorThrown);
}
use of com.enonic.xp.security.PrincipalKey in project xp by enonic.
the class IssueDataSerializer method toCreateNodeData.
public PropertyTree toCreateNodeData(final CreateIssueParams params) {
final PropertyTree propertyTree = new PropertyTree();
final PropertySet issueAsData = propertyTree.getRoot();
issueAsData.ifNotNull().addEnum(TYPE, params.getIssueType());
issueAsData.ifNotNull().addString(TITLE, params.getTitle());
issueAsData.ifNotNull().addString(STATUS, params.getStatus().toString());
issueAsData.addString(DESCRIPTION, params.getDescription());
if (params.getApproverIds().getSize() > 0) {
issueAsData.addStrings(APPROVERS, params.getApproverIds().stream().map(PrincipalKey::toString).collect(Collectors.toList()));
}
if (params.getPublishRequest() != null) {
addPublishRequest(issueAsData, params.getPublishRequest());
}
if (params instanceof CreatePublishRequestIssueParams) {
publishRequestIssueSerializer.toCreateNodeData((CreatePublishRequestIssueParams) params, issueAsData);
}
return propertyTree;
}
Aggregations