Search in sources :

Example 21 with Group

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");
        }
    };
}
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 22 with Group

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);
}
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 23 with Group

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

Example 24 with Group

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());
            }
        }
    }
}
Also used : Group(org.activiti.engine.identity.Group) ArrayList(java.util.ArrayList) Deployment(org.activiti.engine.test.Deployment)

Example 25 with Group

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

Aggregations

Group (org.activiti.engine.identity.Group)61 User (org.activiti.engine.identity.User)22 ArrayList (java.util.ArrayList)12 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 StringEntity (org.apache.http.entity.StringEntity)5 Item (com.vaadin.data.Item)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 PropertysetItem (com.vaadin.data.util.PropertysetItem)3 Deployment (org.activiti.engine.test.Deployment)3 HttpDelete (org.apache.http.client.methods.HttpDelete)3 HttpPut (org.apache.http.client.methods.HttpPut)3 HashSet (java.util.HashSet)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 IdentityService (org.activiti.engine.IdentityService)2 GroupQuery (org.activiti.engine.identity.GroupQuery)2 LoggedInUser (org.activiti.explorer.identity.LoggedInUser)2 ActivitiConflictException (org.activiti.rest.exception.ActivitiConflictException)2