use of org.activiti.engine.identity.Group in project Activiti by Activiti.
the class Application method seedUsersAndGroups.
@Bean
CommandLineRunner seedUsersAndGroups(final IdentityService identityService) {
return new CommandLineRunner() {
@Override
public void run(String... strings) throws Exception {
// install groups & users
Group group = identityService.newGroup("user");
group.setName("users");
group.setType("security-role");
identityService.saveGroup(group);
User joram = identityService.newUser("jbarrez");
joram.setFirstName("Joram");
joram.setLastName("Barrez");
joram.setPassword("password");
identityService.saveUser(joram);
User josh = identityService.newUser("jlong");
josh.setFirstName("Josh");
josh.setLastName("Long");
josh.setPassword("password");
identityService.saveUser(josh);
identityService.createMembership("jbarrez", "user");
identityService.createMembership("jlong", "user");
}
};
}
use of org.activiti.engine.identity.Group in project Activiti by Activiti.
the class IdentityServiceUserDetailsService method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
User user = null;
try {
user = this.identityService.createUserQuery().userId(userId).singleResult();
} catch (ActivitiException ex) {
// don't care
}
if (null == user) {
throw new UsernameNotFoundException(String.format("user (%s) could not be found", userId));
}
// if the results not null then its active...
boolean active = true;
// get the granted authorities
List<GrantedAuthority> grantedAuthorityList = new ArrayList<GrantedAuthority>();
List<Group> groupsForUser = identityService.createGroupQuery().groupMember(user.getId()).list();
for (Group g : groupsForUser) {
grantedAuthorityList.add(new GroupGrantedAuthority(g));
}
return new org.springframework.security.core.userdetails.User(user.getId(), user.getPassword(), active, active, active, active, grantedAuthorityList);
}
use of org.activiti.engine.identity.Group in project Activiti by Activiti.
the class BaseSpringRestTestCase method createUsers.
protected void createUsers() {
User user = identityService.newUser("kermit");
user.setFirstName("Kermit");
user.setLastName("the Frog");
user.setPassword("kermit");
identityService.saveUser(user);
Group group = identityService.newGroup("admin");
group.setName("Administrators");
identityService.saveGroup(group);
identityService.createMembership(user.getId(), group.getId());
}
use of org.activiti.engine.identity.Group in project Activiti by Activiti.
the class GroupCollectionResourceTest method testGetGroups.
/**
* Test getting all groups.
*/
@Deployment
public void testGetGroups() throws Exception {
List<Group> savedGroups = new ArrayList<Group>();
try {
Group group1 = identityService.newGroup("testgroup1");
group1.setName("Test group");
group1.setType("Test type");
identityService.saveGroup(group1);
savedGroups.add(group1);
Group group2 = identityService.newGroup("testgroup2");
group2.setName("Another group");
group2.setType("Another type");
identityService.saveGroup(group2);
savedGroups.add(group2);
Group group3 = identityService.createGroupQuery().groupId("admin").singleResult();
assertNotNull(group3);
// Test filter-less
String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION);
assertResultsPresentInDataResponse(url, group1.getId(), group2.getId(), group3.getId());
// Test based on name
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?name=" + encode("Test group");
assertResultsPresentInDataResponse(url, group1.getId());
// Test based on name like
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?nameLike=" + encode("% group");
assertResultsPresentInDataResponse(url, group2.getId(), group1.getId());
// Test based on type
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?type=" + encode("Another type");
assertResultsPresentInDataResponse(url, group2.getId());
// Test based on group member
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?member=kermit";
assertResultsPresentInDataResponse(url, group3.getId());
// Test based on potentialStarter
String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey("simpleProcess").singleResult().getId();
repositoryService.addCandidateStarterGroup(processDefinitionId, "admin");
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP_COLLECTION) + "?potentialStarter=" + processDefinitionId;
assertResultsPresentInDataResponse(url, group3.getId());
} finally {
// Delete groups after test passes or fails
if (!savedGroups.isEmpty()) {
for (Group group : savedGroups) {
identityService.deleteGroup(group.getId());
}
}
}
}
use of org.activiti.engine.identity.Group in project Activiti by Activiti.
the class GroupResourceTest method testGetGroup.
/**
* Test getting a single group.
*/
public void testGetGroup() throws Exception {
try {
Group testGroup = identityService.newGroup("testgroup");
testGroup.setName("Test group");
testGroup.setType("Test type");
identityService.saveGroup(testGroup);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, "testgroup")), HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("testgroup", responseNode.get("id").textValue());
assertEquals("Test group", responseNode.get("name").textValue());
assertEquals("Test type", responseNode.get("type").textValue());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_GROUP, testGroup.getId())));
Group createdGroup = identityService.createGroupQuery().groupId("testgroup").singleResult();
assertNotNull(createdGroup);
assertEquals("Test group", createdGroup.getName());
assertEquals("Test type", createdGroup.getType());
} finally {
try {
identityService.deleteGroup("testgroup");
} catch (Throwable ignore) {
// Ignore, since the group may not have been created in the test
// or already deleted
}
}
}
Aggregations