Search in sources :

Example 51 with User

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");
        }
    };
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User) CommandLineRunner(org.springframework.boot.CommandLineRunner) Bean(org.springframework.context.annotation.Bean)

Example 52 with 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);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) Group(org.activiti.engine.identity.Group) ActivitiException(org.activiti.engine.ActivitiException) User(org.activiti.engine.identity.User) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList)

Example 53 with User

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");
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User) HashSet(java.util.HashSet)

Example 54 with User

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());
        }
    }
}
Also used : User(org.activiti.engine.identity.User) HttpDelete(org.apache.http.client.methods.HttpDelete)

Example 55 with User

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());
        }
    }
}
Also used : User(org.activiti.engine.identity.User) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

User (org.activiti.engine.identity.User)94 Group (org.activiti.engine.identity.Group)22 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 Task (org.activiti.engine.task.Task)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)9 Picture (org.activiti.engine.identity.Picture)9 StringEntity (org.apache.http.entity.StringEntity)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ArrayList (java.util.ArrayList)7 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)7 HttpPut (org.apache.http.client.methods.HttpPut)7 HttpGet (org.apache.http.client.methods.HttpGet)6 UserQuery (org.activiti.engine.identity.UserQuery)5 HttpDelete (org.apache.http.client.methods.HttpDelete)5 HttpPost (org.apache.http.client.methods.HttpPost)4 Item (com.vaadin.data.Item)3 ActivitiException (org.activiti.engine.ActivitiException)3 IdentityService (org.activiti.engine.IdentityService)3