use of org.activiti.engine.identity.User 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.User 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.User in project Activiti by Activiti.
the class IdentityTest method testFindGroupsByUserAndType.
public void testFindGroupsByUserAndType() {
Group sales = identityService.newGroup("sales");
sales.setType("hierarchy");
identityService.saveGroup(sales);
Group development = identityService.newGroup("development");
development.setType("hierarchy");
identityService.saveGroup(development);
Group admin = identityService.newGroup("admin");
admin.setType("security-role");
identityService.saveGroup(admin);
Group user = identityService.newGroup("user");
user.setType("security-role");
identityService.saveGroup(user);
User johndoe = identityService.newUser("johndoe");
identityService.saveUser(johndoe);
User joesmoe = identityService.newUser("joesmoe");
identityService.saveUser(joesmoe);
User jackblack = identityService.newUser("jackblack");
identityService.saveUser(jackblack);
identityService.createMembership("johndoe", "sales");
identityService.createMembership("johndoe", "user");
identityService.createMembership("johndoe", "admin");
identityService.createMembership("joesmoe", "user");
List<Group> groups = identityService.createGroupQuery().groupMember("johndoe").groupType("security-role").list();
Set<String> groupIds = getGroupIds(groups);
Set<String> expectedGroupIds = new HashSet<String>();
expectedGroupIds.add("user");
expectedGroupIds.add("admin");
assertEquals(expectedGroupIds, groupIds);
groups = identityService.createGroupQuery().groupMember("joesmoe").groupType("security-role").list();
groupIds = getGroupIds(groups);
expectedGroupIds = new HashSet<String>();
expectedGroupIds.add("user");
assertEquals(expectedGroupIds, groupIds);
groups = identityService.createGroupQuery().groupMember("jackblack").groupType("security-role").list();
assertTrue(groups.isEmpty());
identityService.deleteGroup("sales");
identityService.deleteGroup("development");
identityService.deleteGroup("admin");
identityService.deleteGroup("user");
identityService.deleteUser("johndoe");
identityService.deleteUser("joesmoe");
identityService.deleteUser("jackblack");
}
use of org.activiti.engine.identity.User in project Activiti by Activiti.
the class UserResourceTest method testDeleteUser.
/**
* Test deleting a single user.
*/
public void testDeleteUser() throws Exception {
User savedUser = null;
try {
User newUser = identityService.newUser("testuser");
newUser.setFirstName("Fred");
newUser.setLastName("McDonald");
newUser.setEmail("no-reply@activiti.org");
identityService.saveUser(newUser);
savedUser = newUser;
closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())), HttpStatus.SC_NO_CONTENT));
// Check if user is deleted
assertEquals(0, identityService.createUserQuery().userId(newUser.getId()).count());
savedUser = null;
} finally {
// Delete user after test fails
if (savedUser != null) {
identityService.deleteUser(savedUser.getId());
}
}
}
use of org.activiti.engine.identity.User in project Activiti by Activiti.
the class UserResourceTest method testGetUser.
/**
* Test getting a single user.
*/
public void testGetUser() throws Exception {
User savedUser = null;
try {
User newUser = identityService.newUser("testuser");
newUser.setFirstName("Fred");
newUser.setLastName("McDonald");
newUser.setEmail("no-reply@activiti.org");
identityService.saveUser(newUser);
savedUser = newUser;
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())), HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("testuser", responseNode.get("id").textValue());
assertEquals("Fred", responseNode.get("firstName").textValue());
assertEquals("McDonald", responseNode.get("lastName").textValue());
assertEquals("no-reply@activiti.org", responseNode.get("email").textValue());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())));
} finally {
// Delete user after test passes or fails
if (savedUser != null) {
identityService.deleteUser(savedUser.getId());
}
}
}
Aggregations