Search in sources :

Example 1 with LoggedInUserImpl

use of org.activiti.explorer.identity.LoggedInUserImpl in project Activiti by Activiti.

the class DefaultLoginHandler method authenticate.

public LoggedInUserImpl authenticate(String userName, String password) {
    LoggedInUserImpl loggedInUser = null;
    try {
        if (identityService.checkPassword(userName, password)) {
            User user = identityService.createUserQuery().userId(userName).singleResult();
            // Fetch and cache user data
            loggedInUser = new LoggedInUserImpl(user, password);
            List<Group> groups = identityService.createGroupQuery().groupMember(user.getId()).list();
            for (Group group : groups) {
                if (Constants.SECURITY_ROLE.equals(group.getType())) {
                    loggedInUser.addSecurityRoleGroup(group);
                    if (Constants.SECURITY_ROLE_USER.equals(group.getId())) {
                        loggedInUser.setUser(true);
                    }
                    if (Constants.SECURITY_ROLE_ADMIN.equals(group.getId())) {
                        loggedInUser.setAdmin(true);
                    }
                } else if (ExplorerApp.get().getAdminGroups() != null && ExplorerApp.get().getAdminGroups().contains(group.getId())) {
                    loggedInUser.addSecurityRoleGroup(group);
                    loggedInUser.setAdmin(true);
                } else if (ExplorerApp.get().getUserGroups() != null && ExplorerApp.get().getUserGroups().contains(group.getId())) {
                    loggedInUser.addSecurityRoleGroup(group);
                    loggedInUser.setUser(true);
                } else {
                    loggedInUser.addGroup(group);
                }
            }
        }
    } catch (Exception e) {
    // Do nothing, returning null should be enough
    }
    return loggedInUser;
}
Also used : Group(org.activiti.engine.identity.Group) LoggedInUser(org.activiti.explorer.identity.LoggedInUser) User(org.activiti.engine.identity.User) LoggedInUserImpl(org.activiti.explorer.identity.LoggedInUserImpl)

Aggregations

Group (org.activiti.engine.identity.Group)1 User (org.activiti.engine.identity.User)1 LoggedInUser (org.activiti.explorer.identity.LoggedInUser)1 LoggedInUserImpl (org.activiti.explorer.identity.LoggedInUserImpl)1