Subversion Repositories SmartDukaan

Rev

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

Rev 3128 Rev 3206
Line 29... Line 29...
29
/**
29
/**
30
 * @author mandeep
30
 * @author mandeep
31
 * 
31
 * 
32
 * This class is realm for fetching authentication and authorization details for an agent.
32
 * This class is realm for fetching authentication and authorization details for an agent.
33
 */
33
 */
34
public class CRMRealm extends AuthorizingRealm {
34
public class CRMAuthorizingRealm extends AuthorizingRealm {
35
    private static final Log log = LogFactory.getLog(CRMRealm.class);
35
    private static final Log log = LogFactory.getLog(CRMAuthorizingRealm.class);
36
 
36
 
37
    @Override
37
    @Override
38
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
38
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
39
        //null usernames are invalid
39
        //null usernames are invalid
40
        if (principals == null) {
40
        if (principals == null) {
41
            throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
41
            throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
42
        }
42
        }
43
 
43
 
44
        String username = (String) getAvailablePrincipal(principals);
44
        String username = (String) getAvailablePrincipal(principals);
45
        List<String> roleNames = null;
45
        List<String> roleNames = null;
46
        Set<String> permissions = null;
46
        Set<String> permissions = new HashSet<String>();
47
 
47
 
48
        try {
48
        try {
49
            Client crmServiceClient = new CRMClient().getClient();
49
            Client crmServiceClient = new CRMClient().getClient();
50
 
50
 
51
            // Retrieve roles and permissions from database
51
            // Retrieve roles and permissions from database
52
            roleNames = crmServiceClient.getRoleNamesForAgent(username);
52
            roleNames = crmServiceClient.getRoleNamesForAgent(username);
53
 
53
 
54
//            // XXX - we might not need permissions!
-
 
55
//            if (permissionsLookupEnabled) {
54
            for (String roleName : roleNames) {
56
//                permissions = crmServiceClient.getPermissionsForRoleName(roleNames.get(0));
55
                permissions.addAll(crmServiceClient.getPermissionsForRoleName(roleName));
57
//            }
56
            }
58
        } catch (TException e) {
57
        } catch (TException e) {
59
            throw new AuthorizationException("Error fetching roles' information", e);
58
            throw new AuthorizationException("Error fetching roles' information", e);
60
        } catch (Exception e) {
59
        } catch (Exception e) {
61
            throw new AuthorizationException("Error creating CRM client", e);
60
            throw new AuthorizationException("Error creating CRM client", e);
62
        }
61
        }