use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.
the class AbstractAuthorizedRestResource method isAuthorized.
protected boolean isAuthorized(Permission permission, Resource resource, String resourceId) {
if (!processEngine.getProcessEngineConfiguration().isAuthorizationEnabled()) {
// if authorization is disabled everyone is authorized
return true;
}
final IdentityService identityService = processEngine.getIdentityService();
final AuthorizationService authorizationService = processEngine.getAuthorizationService();
Authentication authentication = identityService.getCurrentAuthentication();
if (authentication == null) {
return true;
} else {
return authorizationService.isUserAuthorized(authentication.getUserId(), authentication.getGroupIds(), permission, resource, resourceId);
}
}
use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceImpl method isUserAuthorized.
public AuthorizationCheckResultDto isUserAuthorized(String permissionName, String resourceName, Integer resourceType, String resourceId) {
// validate request:
if (permissionName == null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Query parameter 'permissionName' cannot be null");
} else if (resourceName == null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Query parameter 'resourceName' cannot be null");
} else if (resourceType == null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "Query parameter 'resourceType' cannot be null");
}
final Authentication currentAuthentication = processEngine.getIdentityService().getCurrentAuthentication();
if (currentAuthentication == null) {
throw new InvalidRequestException(Status.UNAUTHORIZED, "You must be authenticated in order to use this resource.");
}
final AuthorizationService authorizationService = processEngine.getAuthorizationService();
// create new authorization dto implementing both Permission and Resource
AuthorizationUtil authorizationUtil = new AuthorizationUtil(resourceName, resourceType, permissionName);
boolean isUserAuthorized = false;
if (resourceId == null || Authorization.ANY.equals(resourceId)) {
isUserAuthorized = authorizationService.isUserAuthorized(currentAuthentication.getUserId(), currentAuthentication.getGroupIds(), authorizationUtil, authorizationUtil);
} else {
isUserAuthorized = authorizationService.isUserAuthorized(currentAuthentication.getUserId(), currentAuthentication.getGroupIds(), authorizationUtil, authorizationUtil, resourceId);
}
return new AuthorizationCheckResultDto(isUserAuthorized, authorizationUtil, resourceId);
}
use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.
the class CommandContext method getAuthenticatedGroupIds.
public List<String> getAuthenticatedGroupIds() {
IdentityService identityService = processEngineConfiguration.getIdentityService();
Authentication currentAuthentication = identityService.getCurrentAuthentication();
if (currentAuthentication == null) {
return null;
} else {
return currentAuthentication.getGroupIds();
}
}
use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.
the class CommandContext method getAuthenticatedUserId.
public String getAuthenticatedUserId() {
IdentityService identityService = processEngineConfiguration.getIdentityService();
Authentication currentAuthentication = identityService.getCurrentAuthentication();
if (currentAuthentication == null) {
return null;
} else {
return currentAuthentication.getUserId();
}
}
use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.
the class IdentityServiceTest method testSetAuthenticatedUserAndGroups.
@Test
public void testSetAuthenticatedUserAndGroups() {
List<String> groups = Arrays.asList("sales", "development");
identityService.setAuthentication("john", groups);
Authentication currentAuthentication = identityService.getCurrentAuthentication();
assertNotNull(currentAuthentication);
assertEquals("john", currentAuthentication.getUserId());
assertEquals(groups, currentAuthentication.getGroupIds());
assertNull(currentAuthentication.getTenantIds());
}
Aggregations