Subversion Repositories SmartDukaan

Rev

Rev 7059 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7059 Rev 23647
Line 41... Line 41...
41
                                           .getLog(CRMAuthorizingRealm.class);
41
                                           .getLog(CRMAuthorizingRealm.class);
42
    private static Map<Long, Agent>   agentsMapById;
42
    private static Map<Long, Agent>   agentsMapById;
43
    private static Map<String, Agent> agentsMapByEmailId;
43
    private static Map<String, Agent> agentsMapByEmailId;
44
    private static Map<Long, Agent>   inactiveAgentsMapById;
44
    private static Map<Long, Agent>   inactiveAgentsMapById;
45
    private static Map<String, Agent> inactiveAgentsMapByEmailId;
45
    private static Map<String, Agent> inactiveAgentsMapByEmailId;
-
 
46
    private static Map<String, List<String>> userRoleNames;
-
 
47
    private static Map<String, Set<String>> userPermissions;
46
    
48
    
47
    @Override
49
    @Override
48
    protected AuthorizationInfo doGetAuthorizationInfo(
50
    protected AuthorizationInfo doGetAuthorizationInfo(
49
            PrincipalCollection principals) {
51
            PrincipalCollection principals) {
50
        // null usernames are invalid
52
        // null usernames are invalid
Line 53... Line 55...
53
                    "PrincipalCollection method argument cannot be null.");
55
                    "PrincipalCollection method argument cannot be null.");
54
        }
56
        }
55
 
57
 
56
        String username = (String) getAvailablePrincipal(principals);
58
        String username = (String) getAvailablePrincipal(principals);
57
        List<String> roleNames = null;
59
        List<String> roleNames = null;
58
        Set<String> permissions = new HashSet<String>();
60
        Set<String> permissions = null;
59
 
61
 
60
        try {
62
        try {
61
            Client crmServiceClient = new CRMClient().getClient();
63
            Client crmServiceClient = new CRMClient().getClient();
62
 
64
 
63
            // Retrieve roles and permissions from database
65
            // Retrieve roles and permissions from database
-
 
66
            if(!userRoleNames.containsKey(username)) {
64
            roleNames = crmServiceClient.getRoleNamesForAgent(username);
67
            	roleNames = crmServiceClient.getRoleNamesForAgent(username);
-
 
68
            	userRoleNames.put(username, roleNames);
-
 
69
            } else {
-
 
70
            	roleNames = userRoleNames.get(username);
65
 
71
            }
-
 
72
            if(userPermissions.containsKey(username)) {
-
 
73
            	permissions = userPermissions.get(username);
-
 
74
            } else {
-
 
75
            	permissions = new HashSet<String>();
66
            for (String roleName : roleNames) {
76
	            for (String roleName : roleNames) {
67
                permissions.addAll(crmServiceClient
77
	                permissions.addAll(crmServiceClient
68
                        .getPermissionsForRoleName(roleName));
78
	                        .getPermissionsForRoleName(roleName));
-
 
79
	            }
69
            }
80
            }
70
        } catch (TException e) {
81
        } catch (TException e) {
71
            throw new AuthorizationException(
82
            throw new AuthorizationException(
72
                    "Error fetching roles' information", e);
83
                    "Error fetching roles' information", e);
73
        } catch (Exception e) {
84
        } catch (Exception e) {