Java Code Examples for org.camunda.bpm.engine.impl.interceptor.CommandContext#getAuthorizationManager()

The following examples show how to use org.camunda.bpm.engine.impl.interceptor.CommandContext#getAuthorizationManager() . 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: GetLicenseKeyCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public String execute(CommandContext commandContext) {
  AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();
  authorizationManager.checkCamundaAdmin();

  // case I: license is stored as BLOB
  ResourceEntity licenseResource = commandContext.getResourceManager().findLicenseKeyResource();
  if (licenseResource != null) {
    return new String(licenseResource.getBytes(), StandardCharsets.UTF_8);
  }

  // case II: license is stored in properties
  PropertyEntity licenseProperty = commandContext.getPropertyManager().findPropertyById(LICENSE_KEY_PROPERTY_NAME);
  if (licenseProperty != null) {
    return licenseProperty.getValue();
  }

  return null;
}
 
Example 2
Source File: DeletePropertyCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public Object execute(CommandContext commandContext) {
  AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();
  authorizationManager.checkCamundaAdmin();

  final PropertyManager propertyManager = commandContext.getPropertyManager();

  PropertyEntity propertyEntity = propertyManager.findPropertyById(name);

  if(propertyEntity != null) {
    propertyManager.delete(propertyEntity);
    
    commandContext.getOperationLogManager().logPropertyOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE, 
        Collections.singletonList(new PropertyChange("name", null, name)));
  }

  return null;
}
 
Example 3
Source File: SaveAuthorizationCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public Authorization execute(CommandContext commandContext) {
  
  final AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();

  authorizationManager.validateResourceCompatibility(authorization);

  provideRemovalTime(commandContext);

  String operationType = null;
  AuthorizationEntity previousValues = null;
  if(authorization.getId() == null) {
    authorizationManager.insert(authorization);
    operationType = UserOperationLogEntry.OPERATION_TYPE_CREATE;
  } else {
    previousValues = commandContext.getDbEntityManager().selectById(AuthorizationEntity.class, authorization.getId());
    authorizationManager.update(authorization);
    operationType = UserOperationLogEntry.OPERATION_TYPE_UPDATE;
  }
  commandContext.getOperationLogManager().logAuthorizationOperation(operationType, authorization, previousValues);
  
  return authorization;
}
 
Example 4
Source File: HistoryCleanupCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Job execute(CommandContext commandContext) {
  if (!isHistoryCleanupEnabled(commandContext)) {
    throw new BadUserRequestException("History cleanup is disabled for this engine");
  }

  AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();
  ProcessEngineConfigurationImpl processEngineConfiguration = commandContext.getProcessEngineConfiguration();

  authorizationManager.checkCamundaAdmin();

  //validate
  if (!willBeScheduled()) {
    LOG.debugHistoryCleanupWrongConfiguration();
  }

  //find job instance
  List<Job> historyCleanupJobs = getHistoryCleanupJobs();

  int degreeOfParallelism = processEngineConfiguration.getHistoryCleanupDegreeOfParallelism();
  int[][] minuteChunks = HistoryCleanupHelper.listMinuteChunks(degreeOfParallelism);

  if (shouldCreateJobs(historyCleanupJobs)) {
    historyCleanupJobs = createJobs(degreeOfParallelism, minuteChunks);

  }
  else if (shouldReconfigureJobs(historyCleanupJobs)) {
    historyCleanupJobs = reconfigureJobs(historyCleanupJobs, degreeOfParallelism, minuteChunks);

  }
  else if (shouldSuspendJobs(historyCleanupJobs)) {
    suspendJobs(historyCleanupJobs);

  }

  writeUserOperationLog(commandContext);

  return historyCleanupJobs.size() > 0 ? historyCleanupJobs.get(0) : null;
}
 
Example 5
Source File: GetPropertiesCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public Map<String, String> execute(CommandContext commandContext) {
  AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();
  authorizationManager.checkCamundaAdmin();

  List<PropertyEntity> propertyEntities = commandContext
    .getDbEntityManager()
    .selectList("selectProperties");
  
  Map<String, String> properties = new HashMap<String, String>();
  for (PropertyEntity propertyEntity: propertyEntities) {
    properties.put(propertyEntity.getName(), propertyEntity.getValue());
  }
  return properties;
}
 
Example 6
Source File: DeleteLicenseKeyCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(CommandContext commandContext) {
  AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();
  authorizationManager.checkCamundaAdmin();

  final ResourceManager resourceManager = commandContext.getResourceManager();
  final PropertyManager propertyManager = commandContext.getPropertyManager();
  
  // lock the property
  @SuppressWarnings("unused")
  PropertyEntity licenseProperty = propertyManager.findPropertyById(LICENSE_KEY_BYTE_ARRAY_ID);

  // delete license key BLOB
  ResourceEntity licenseKey = resourceManager.findLicenseKeyResource();
  if(licenseKey != null) {
    resourceManager.delete(licenseKey);
  }

  // always delete license key legacy property if it still exists
  new DeletePropertyCmd(LICENSE_KEY_PROPERTY_NAME).execute(commandContext);

  if(deleteProperty) {
    // delete license key byte array id
    new DeletePropertyCmd(LICENSE_KEY_BYTE_ARRAY_ID).execute(commandContext);
  }

  return null;
}
 
Example 7
Source File: IsTelemetryEnabledCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Boolean execute(CommandContext commandContext) {

    AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();
    authorizationManager.checkCamundaAdmin();

    PropertyEntity telemetryProperty = commandContext.getPropertyManager().findPropertyById("camunda.telemetry.enabled");
    if (telemetryProperty != null) {
      return Boolean.parseBoolean(telemetryProperty.getValue());
    } else {
      LOG.databaseTelemetryPropertyMissingInfo();
      return false;
    }
  }
 
Example 8
Source File: AuthorizationCheckCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public Boolean execute(CommandContext commandContext) {
  final AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();
  if (authorizationManager.isPermissionDisabled(permission)) {
    throw LOG.disabledPermissionException(permission.getName());
  }

  if (isHistoricInstancePermissionsDisabled(commandContext) && isHistoricInstanceResource()) {
    throw LOG.disabledHistoricInstancePermissionsException();
  }

  return authorizationManager.isAuthorized(userId, groupIds, permission, resource, resourceId);
}
 
Example 9
Source File: DefaultAuthorizationProvider.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected AuthorizationManager getAuthorizationManager() {
  CommandContext commandContext = Context.getCommandContext();
  return commandContext.getAuthorizationManager();
}
 
Example 10
Source File: DeleteAuthorizationCmd.java    From camunda-bpm-platform with Apache License 2.0 3 votes vote down vote up
public Void execute(CommandContext commandContext) {

    final AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();

    AuthorizationEntity authorization = (AuthorizationEntity) new AuthorizationQueryImpl()
      .authorizationId(authorizationId)
      .singleResult();

    ensureNotNull("Authorization for Id '" + authorizationId + "' does not exist", "authorization", authorization);

    authorizationManager.delete(authorization);
    commandContext.getOperationLogManager().logAuthorizationOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE, authorization, null);

    return null;
  }