Search in sources :

Example 36 with Authentication

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);
    }
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) AuthorizationService(org.camunda.bpm.engine.AuthorizationService) Authentication(org.camunda.bpm.engine.impl.identity.Authentication)

Example 37 with Authentication

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);
}
Also used : AuthorizationCheckResultDto(org.camunda.bpm.engine.rest.dto.authorization.AuthorizationCheckResultDto) AuthorizationUtil(org.camunda.bpm.engine.rest.util.AuthorizationUtil) AuthorizationService(org.camunda.bpm.engine.AuthorizationService) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 38 with Authentication

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();
    }
}
Also used : Authentication(org.camunda.bpm.engine.impl.identity.Authentication)

Example 39 with Authentication

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();
    }
}
Also used : Authentication(org.camunda.bpm.engine.impl.identity.Authentication)

Example 40 with Authentication

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());
}
Also used : Authentication(org.camunda.bpm.engine.impl.identity.Authentication) Test(org.junit.Test)

Aggregations

Authentication (org.camunda.bpm.engine.impl.identity.Authentication)56 Test (org.junit.Test)29 Matchers.anyString (org.mockito.Matchers.anyString)22 ArrayList (java.util.ArrayList)9 IdentityService (org.camunda.bpm.engine.IdentityService)9 User (org.camunda.bpm.engine.identity.User)5 AuthorizationUtil (org.camunda.bpm.engine.rest.util.AuthorizationUtil)5 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)4 Group (org.camunda.bpm.engine.identity.Group)4 GroupQuery (org.camunda.bpm.engine.identity.GroupQuery)4 UserQuery (org.camunda.bpm.engine.identity.UserQuery)4 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)3 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)3 Parameters (org.junit.runners.Parameterized.Parameters)3 AuthorizationService (org.camunda.bpm.engine.AuthorizationService)2 Authorization (org.camunda.bpm.engine.authorization.Authorization)2 AuthorizationQuery (org.camunda.bpm.engine.authorization.AuthorizationQuery)2 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)2 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)2 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)2