Java Code Examples for org.camunda.bpm.engine.IdentityService#getCurrentAuthentication()

The following examples show how to use org.camunda.bpm.engine.IdentityService#getCurrentAuthentication() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationContextPathUtil.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static String getApplicationPathForDeployment(ProcessEngine engine, String deploymentId) {

    // get the name of the process application that made the deployment
    String processApplicationName = null;
    IdentityService identityService = engine.getIdentityService();
    Authentication currentAuthentication = identityService.getCurrentAuthentication();
    try {
      identityService.clearAuthentication();
      processApplicationName = engine.getManagementService().getProcessApplicationForDeployment(deploymentId);
    } finally {
      identityService.setAuthentication(currentAuthentication);
    }

    if (processApplicationName == null) {
      // no a process application deployment
      return null;
    } else {
      ProcessApplicationService processApplicationService = BpmPlatform.getProcessApplicationService();
      ProcessApplicationInfo processApplicationInfo = processApplicationService.getProcessApplicationInfo(processApplicationName);
      return processApplicationInfo.getProperties().get(ProcessApplicationInfo.PROP_SERVLET_CONTEXT_PATH);
    }
  }
 
Example 2
Source File: AbstractAuthorizedRestResource.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example 3
Source File: DefaultAuthorizationProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: CommandContext.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public String getAuthenticatedUserId() {
  IdentityService identityService = processEngineConfiguration.getIdentityService();
  Authentication currentAuthentication = identityService.getCurrentAuthentication();
  if(currentAuthentication == null) {
    return null;
  } else {
    return currentAuthentication.getUserId();
  }
}
 
Example 5
Source File: CommandContext.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public List<String> getAuthenticatedGroupIds() {
  IdentityService identityService = processEngineConfiguration.getIdentityService();
  Authentication currentAuthentication = identityService.getCurrentAuthentication();
  if(currentAuthentication == null) {
    return null;
  } else {
    return currentAuthentication.getGroupIds();
  }
}
 
Example 6
Source File: QueryMaxResultsLimitUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static String getAuthenticatedUserId(
    ProcessEngineConfigurationImpl processEngineConfig) {
  IdentityService identityService = processEngineConfig.getIdentityService();
  Authentication currentAuthentication = identityService.getCurrentAuthentication();
  if(currentAuthentication == null) {
    return null;
  } else {
    return currentAuthentication.getUserId();
  }
}
 
Example 7
Source File: MultiTenancyJobExecutorTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static DelegateExecutionAsserter hasAuthenticatedTenantId(final String expectedTenantId) {
  return new DelegateExecutionAsserter() {

    @Override
    public void doAssert(DelegateExecution execution) {
      IdentityService identityService = execution.getProcessEngineServices().getIdentityService();

      Authentication currentAuthentication = identityService.getCurrentAuthentication();
      assertThat(currentAuthentication, is(notNullValue()));
      assertThat(currentAuthentication.getTenantIds(), hasItem(expectedTenantId));
    }
  };
}
 
Example 8
Source File: MultiTenancyJobExecutorTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected static DelegateExecutionAsserter hasNoAuthenticatedTenantId() {
  return new DelegateExecutionAsserter() {

    @Override
    public void doAssert(DelegateExecution execution) {
      IdentityService identityService = execution.getProcessEngineServices().getIdentityService();

      Authentication currentAuthentication = identityService.getCurrentAuthentication();
      assertThat(currentAuthentication, is(nullValue()));
    }
  };
}
 
Example 9
Source File: TaskAttachmentResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 10
Source File: TaskCommentResourceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 11
Source File: CommandContext.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public Authentication getAuthentication() {
  IdentityService identityService = processEngineConfiguration.getIdentityService();
  return identityService.getCurrentAuthentication();
}
 
Example 12
Source File: MyDelegationService.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected void logAuthentication(IdentityService identityService) {
  CURRENT_AUTHENTICATION = identityService.getCurrentAuthentication();
}
 
Example 13
Source File: FetchAndLockHandlerImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void addPendingRequest(FetchExternalTasksExtendedDto dto, AsyncResponse asyncResponse, ProcessEngine processEngine) {
  Long asyncResponseTimeout = dto.getAsyncResponseTimeout();
  if (asyncResponseTimeout != null && asyncResponseTimeout > MAX_REQUEST_TIMEOUT) {
    asyncResponse.resume(new InvalidRequestException(Status.BAD_REQUEST, "The asynchronous response timeout cannot be set to a value greater than "
        + MAX_REQUEST_TIMEOUT + " milliseconds"));
    return;
  }

  IdentityService identityService = processEngine.getIdentityService();
  Authentication authentication = identityService.getCurrentAuthentication();
  String processEngineName = processEngine.getName();

  FetchAndLockRequest incomingRequest = new FetchAndLockRequest()
    .setProcessEngineName(processEngineName)
    .setAsyncResponse(asyncResponse)
    .setAuthentication(authentication)
    .setDto(dto);

  LOG.log(Level.FINEST, "New request: {0}", incomingRequest);

  FetchAndLockResult result = tryFetchAndLock(incomingRequest);

  LOG.log(Level.FINEST, "Fetch and lock result: {0}", result);

  if (result.wasSuccessful()) {
    List<LockedExternalTaskDto> lockedTasks = result.getTasks();
    if (!lockedTasks.isEmpty() || dto.getAsyncResponseTimeout() == null) { // response immediately if tasks available
      asyncResponse.resume(lockedTasks);

      LOG.log(Level.FINEST, "Resuming request with {0}", lockedTasks);
    } else {
      addRequest(incomingRequest);

      LOG.log(Level.FINEST, "Deferred request");
    }
  }
  else {
    Throwable processEngineException = result.getThrowable();
    asyncResponse.resume(processEngineException);

    LOG.log(Level.FINEST, "Resuming request with error {0}", processEngineException);
  }
}