Search in sources :

Example 41 with Authentication

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

the class AuthorizationCheckRevokesCfgTest method setup.

@Before
public void setup() {
    mockedCmdContext = mock(CommandContext.class);
    mockedConfiguration = mock(ProcessEngineConfigurationImpl.class);
    authorizationManager = spy(new AuthorizationManager());
    mockedEntityManager = mock(DbEntityManager.class);
    when(mockedCmdContext.getSession(eq(DbEntityManager.class))).thenReturn(mockedEntityManager);
    when(authorizationManager.filterAuthenticatedGroupIds(eq(AUTHENTICATED_GROUPS))).thenReturn(AUTHENTICATED_GROUPS);
    when(mockedCmdContext.getAuthentication()).thenReturn(new Authentication(AUTHENTICATED_USER_ID, AUTHENTICATED_GROUPS));
    when(mockedCmdContext.isAuthorizationCheckEnabled()).thenReturn(true);
    when(mockedConfiguration.isAuthorizationEnabled()).thenReturn(true);
    Context.setCommandContext(mockedCmdContext);
    Context.setProcessEngineConfiguration(mockedConfiguration);
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) AuthorizationManager(org.camunda.bpm.engine.impl.persistence.entity.AuthorizationManager) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) Before(org.junit.Before)

Example 42 with Authentication

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

the class DefaultAuthorizationProvider method newDeployment.

// Deployment ///////////////////////////////////////////////
public AuthorizationEntity[] newDeployment(Deployment deployment) {
    ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
    IdentityService identityService = processEngineConfiguration.getIdentityService();
    Authentication currentAuthentication = identityService.getCurrentAuthentication();
    if (currentAuthentication != null && currentAuthentication.getUserId() != null) {
        String userId = currentAuthentication.getUserId();
        String deploymentId = deployment.getId();
        AuthorizationEntity authorization = createGrantAuthorization(userId, null, DEPLOYMENT, deploymentId, READ, DELETE);
        return new AuthorizationEntity[] { authorization };
    }
    return null;
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) AuthorizationEntity(org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 43 with Authentication

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

the class AuthorizationManager method checkAuthorization.

@Override
public void checkAuthorization(Permission permission, Resource resource, String resourceId) {
    if (isAuthCheckExecuted()) {
        Authentication currentAuthentication = getCurrentAuthentication();
        boolean isAuthorized = isAuthorized(currentAuthentication.getUserId(), currentAuthentication.getGroupIds(), permission, resource, resourceId);
        if (!isAuthorized) {
            throw new AuthorizationException(currentAuthentication.getUserId(), permission.getName(), resource.resourceName(), resourceId);
        }
    }
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Authentication(org.camunda.bpm.engine.impl.identity.Authentication)

Example 44 with Authentication

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

the class AuthorizationManager method isAuthCheckExecuted.

protected boolean isAuthCheckExecuted() {
    Authentication currentAuthentication = getCurrentAuthentication();
    CommandContext commandContext = Context.getCommandContext();
    return isAuthorizationEnabled() && commandContext.isAuthorizationCheckEnabled() && currentAuthentication != null && currentAuthentication.getUserId() != null;
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Authentication(org.camunda.bpm.engine.impl.identity.Authentication)

Example 45 with Authentication

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

the class AuthorizationTest method deleteDeployment.

protected void deleteDeployment(final String deploymentId, final boolean cascade) {
    Authentication authentication = identityService.getCurrentAuthentication();
    try {
        identityService.clearAuthentication();
        runWithoutAuthorization(new Callable<Void>() {

            public Void call() throws Exception {
                repositoryService.deleteDeployment(deploymentId, cascade);
                return null;
            }
        });
    } finally {
        if (authentication != null) {
            identityService.setAuthentication(authentication);
        }
    }
}
Also used : Authentication(org.camunda.bpm.engine.impl.identity.Authentication) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

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