Search in sources :

Example 21 with IdentityService

use of org.camunda.bpm.engine.IdentityService in project camunda-bpm-platform by camunda.

the class GroupRestServiceImpl method availableOperations.

public ResourceOptionsDto availableOperations(UriInfo context) {
    final IdentityService identityService = getIdentityService();
    UriBuilder baseUriBuilder = context.getBaseUriBuilder().path(relativeRootResourcePath).path(GroupRestService.PATH);
    ResourceOptionsDto resourceOptionsDto = new ResourceOptionsDto();
    // GET /
    URI baseUri = baseUriBuilder.build();
    resourceOptionsDto.addReflexiveLink(baseUri, HttpMethod.GET, "list");
    // GET /count
    URI countUri = baseUriBuilder.clone().path("/count").build();
    resourceOptionsDto.addReflexiveLink(countUri, HttpMethod.GET, "count");
    // POST /create
    if (!identityService.isReadOnly() && isAuthorized(CREATE)) {
        URI createUri = baseUriBuilder.clone().path("/create").build();
        resourceOptionsDto.addReflexiveLink(createUri, HttpMethod.POST, "create");
    }
    return resourceOptionsDto;
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) ResourceOptionsDto(org.camunda.bpm.engine.rest.dto.ResourceOptionsDto) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI)

Example 22 with IdentityService

use of org.camunda.bpm.engine.IdentityService in project camunda-bpm-platform by camunda.

the class IdentityRestServiceImpl method getGroupInfo.

@Override
public GroupInfoDto getGroupInfo(String userId) {
    if (userId == null) {
        throw new InvalidRequestException(Status.BAD_REQUEST, "No user id was supplied");
    }
    IdentityService identityService = getProcessEngine().getIdentityService();
    GroupQuery query = identityService.createGroupQuery();
    List<Group> userGroups = query.groupMember(userId).orderByGroupName().asc().list();
    Set<UserDto> allGroupUsers = new HashSet<UserDto>();
    List<GroupDto> allGroups = new ArrayList<GroupDto>();
    for (Group group : userGroups) {
        List<User> groupUsers = identityService.createUserQuery().memberOfGroup(group.getId()).list();
        for (User user : groupUsers) {
            if (!user.getId().equals(userId)) {
                allGroupUsers.add(new UserDto(user.getId(), user.getFirstName(), user.getLastName()));
            }
        }
        allGroups.add(new GroupDto(group.getId(), group.getName()));
    }
    return new GroupInfoDto(allGroups, allGroupUsers);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) UserDto(org.camunda.bpm.engine.rest.dto.task.UserDto) GroupDto(org.camunda.bpm.engine.rest.dto.task.GroupDto) ArrayList(java.util.ArrayList) IdentityService(org.camunda.bpm.engine.IdentityService) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) GroupInfoDto(org.camunda.bpm.engine.rest.dto.task.GroupInfoDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) HashSet(java.util.HashSet)

Example 23 with IdentityService

use of org.camunda.bpm.engine.IdentityService in project camunda-bpm-platform by camunda.

the class IdentityRestServiceImpl method verifyUser.

@Override
public AuthenticationResult verifyUser(BasicUserCredentialsDto credentialsDto) {
    if (credentialsDto.getUsername() == null || credentialsDto.getPassword() == null) {
        throw new InvalidRequestException(Status.BAD_REQUEST, "Username and password are required");
    }
    IdentityService identityService = getProcessEngine().getIdentityService();
    boolean valid = identityService.checkPassword(credentialsDto.getUsername(), credentialsDto.getPassword());
    if (valid) {
        return AuthenticationResult.successful(credentialsDto.getUsername());
    } else {
        return AuthenticationResult.unsuccessful(credentialsDto.getUsername());
    }
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 24 with IdentityService

use of org.camunda.bpm.engine.IdentityService 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 25 with IdentityService

use of org.camunda.bpm.engine.IdentityService in project camunda-bpm-platform by camunda.

the class AuthorizationScenario method startProcessInstance.

@DescribesScenario("startProcessInstance")
public static ScenarioSetup startProcessInstance() {
    return new ScenarioSetup() {

        public void execute(ProcessEngine engine, String scenarioName) {
            IdentityService identityService = engine.getIdentityService();
            // create an user
            String userId = "test";
            User user = identityService.newUser(userId);
            identityService.saveUser(user);
            // create group
            String groupId = "accounting";
            Group group = identityService.newGroup(groupId);
            identityService.saveGroup(group);
            // create membership
            identityService.createMembership("test", "accounting");
            // start a process instance
            engine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess", scenarioName);
        }
    };
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) ScenarioSetup(org.camunda.bpm.qa.upgrade.ScenarioSetup) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) DescribesScenario(org.camunda.bpm.qa.upgrade.DescribesScenario)

Aggregations

IdentityService (org.camunda.bpm.engine.IdentityService)32 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)9 User (org.camunda.bpm.engine.identity.User)8 Group (org.camunda.bpm.engine.identity.Group)7 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)7 RuntimeService (org.camunda.bpm.engine.RuntimeService)6 ArrayList (java.util.ArrayList)4 AuthorizationService (org.camunda.bpm.engine.AuthorizationService)4 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)4 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)4 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)3 Authorization (org.camunda.bpm.engine.authorization.Authorization)3 DescribesScenario (org.camunda.bpm.qa.upgrade.DescribesScenario)3 ScenarioSetup (org.camunda.bpm.qa.upgrade.ScenarioSetup)3 URI (java.net.URI)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 FilterService (org.camunda.bpm.engine.FilterService)2 FormService (org.camunda.bpm.engine.FormService)2 TaskService (org.camunda.bpm.engine.TaskService)2 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)2