Search in sources :

Example 16 with Authentication

use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.

the class TaskAttachmentResourceImpl method isHistoryEnabled.

private boolean isHistoryEnabled() {
    IdentityService identityService = engine.getIdentityService();
    Authentication currentAuthentication = identityService.getCurrentAuthentication();
    try {
        identityService.clearAuthentication();
        int historyLevel = engine.getManagementService().getHistoryLevel();
        return historyLevel > ProcessEngineConfigurationImpl.HISTORYLEVEL_NONE;
    } finally {
        identityService.setAuthentication(currentAuthentication);
    }
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) Authentication(org.camunda.bpm.engine.impl.identity.Authentication)

Example 17 with Authentication

use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.

the class AuthorizationManager method configureQuery.

// authorization checks on queries ////////////////////////////////
public void configureQuery(ListQueryParameterObject query) {
    AuthorizationCheck authCheck = query.getAuthCheck();
    authCheck.getPermissionChecks().clear();
    if (isAuthCheckExecuted()) {
        Authentication currentAuthentication = getCurrentAuthentication();
        authCheck.setAuthUserId(currentAuthentication.getUserId());
        authCheck.setAuthGroupIds(currentAuthentication.getGroupIds());
        enableQueryAuthCheck(authCheck);
    } else {
        authCheck.setAuthorizationCheckEnabled(false);
        authCheck.setAuthUserId(null);
        authCheck.setAuthGroupIds(null);
    }
}
Also used : Authentication(org.camunda.bpm.engine.impl.identity.Authentication) AuthorizationCheck(org.camunda.bpm.engine.impl.db.AuthorizationCheck)

Example 18 with Authentication

use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.

the class AuthorizationManager method checkAuthorization.

public void checkAuthorization(List<PermissionCheck> permissionChecks) {
    if (isAuthCheckExecuted()) {
        Authentication currentAuthentication = getCurrentAuthentication();
        String userId = currentAuthentication.getUserId();
        boolean isAuthorized = isAuthorized(userId, currentAuthentication.getGroupIds(), permissionChecks);
        if (!isAuthorized) {
            List<MissingAuthorization> missingAuthorizations = new ArrayList<MissingAuthorization>();
            for (PermissionCheck check : permissionChecks) {
                missingAuthorizations.add(new MissingAuthorization(check.getPermission().getName(), check.getResource().resourceName(), check.getResourceId()));
            }
            throw new AuthorizationException(userId, missingAuthorizations);
        }
    }
}
Also used : MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) PermissionCheck(org.camunda.bpm.engine.impl.db.PermissionCheck) CompositePermissionCheck(org.camunda.bpm.engine.impl.db.CompositePermissionCheck) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) ArrayList(java.util.ArrayList)

Example 19 with Authentication

use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.

the class AuthorizationManager method checkCamundaAdmin.

// predefined authorization checks
/* MEMBER OF CAMUNDA_ADMIN */
/**
 * Checks if the current authentication contains the group
 * {@link Groups#CAMUNDA_ADMIN}. The check is ignored if the authorization is
 * disabled or no authentication exists.
 *
 * @throws AuthorizationException
 */
public void checkCamundaAdmin() {
    final Authentication currentAuthentication = getCurrentAuthentication();
    CommandContext commandContext = Context.getCommandContext();
    if (isAuthorizationEnabled() && commandContext.isAuthorizationCheckEnabled() && currentAuthentication != null && !isCamundaAdmin(currentAuthentication)) {
        throw LOG.requiredCamundaAdminException();
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Authentication(org.camunda.bpm.engine.impl.identity.Authentication)

Example 20 with Authentication

use of org.camunda.bpm.engine.impl.identity.Authentication in project camunda-bpm-platform by camunda.

the class AuthorizationManager method checkAuthorization.

public void checkAuthorization(CompositePermissionCheck compositePermissionCheck) {
    if (isAuthCheckExecuted()) {
        Authentication currentAuthentication = getCurrentAuthentication();
        String userId = currentAuthentication.getUserId();
        boolean isAuthorized = isAuthorized(compositePermissionCheck);
        if (!isAuthorized) {
            List<MissingAuthorization> missingAuthorizations = new ArrayList<MissingAuthorization>();
            for (PermissionCheck check : compositePermissionCheck.getAllPermissionChecks()) {
                missingAuthorizations.add(new MissingAuthorization(check.getPermission().getName(), check.getResource().resourceName(), check.getResourceId()));
            }
            throw new AuthorizationException(userId, missingAuthorizations);
        }
    }
}
Also used : MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) PermissionCheck(org.camunda.bpm.engine.impl.db.PermissionCheck) CompositePermissionCheck(org.camunda.bpm.engine.impl.db.CompositePermissionCheck) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) ArrayList(java.util.ArrayList)

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