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;
}
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);
}
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());
}
}
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);
}
}
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);
}
};
}
Aggregations