Search in sources :

Example 6 with AuthorizingRealm

use of org.apache.shiro.realm.AuthorizingRealm in project shiro by apache.

the class ModularRealmAuthorizerTest method testSettingOfRolePermissionResolver.

@Test
public void testSettingOfRolePermissionResolver() {
    Collection<Realm> realms = new ArrayList<Realm>();
    realms.add(new MockAuthorizingRealm());
    realms.add(new MockAuthorizingRealm());
    // its null to start with
    for (Realm realm : realms) {
        Assert.assertNull(((AuthorizingRealm) realm).getRolePermissionResolver());
    }
    ModularRealmAuthorizer modRealmAuthz = new ModularRealmAuthorizer();
    modRealmAuthz.setRealms(realms);
    // make sure they are still null
    for (Realm realm : realms) {
        Assert.assertNull(((AuthorizingRealm) realm).getRolePermissionResolver());
    }
    // now set the RolePermissionResolver
    RolePermissionResolver rolePermissionResolver = new RolePermissionResolver() {

        public Collection<Permission> resolvePermissionsInRole(String roleString) {
            return null;
        }
    };
    modRealmAuthz.setRolePermissionResolver(rolePermissionResolver);
    // make sure they are set
    for (Realm realm : realms) {
        // check for same instance
        Assert.assertTrue(((AuthorizingRealm) realm).getRolePermissionResolver() == rolePermissionResolver);
    }
    // add a new realm and make sure the RolePermissionResolver is set
    MockAuthorizingRealm mockRealm = new MockAuthorizingRealm();
    realms.add(mockRealm);
    modRealmAuthz.setRealms(realms);
    assertTrue(((AuthorizingRealm) mockRealm).getRolePermissionResolver() == rolePermissionResolver);
// TODO: no way to unset them, not sure if that is a valid use case, but this is conistent with the PermissionResolver logic
// // now just to be sure, unset them
// modRealmAuthz.setRolePermissionResolver( null );
// for ( Realm realm : realms )
// {
// Assert.assertNull( ((AuthorizingRealm)realm).getRolePermissionResolver() );
// }
}
Also used : ArrayList(java.util.ArrayList) RolePermissionResolver(org.apache.shiro.authz.permission.RolePermissionResolver) Realm(org.apache.shiro.realm.Realm) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) Test(org.junit.Test)

Example 7 with AuthorizingRealm

use of org.apache.shiro.realm.AuthorizingRealm in project killbill by killbill.

the class DefaultSecurityApi method buildGetAuthorizationInfoMethods.

private void buildGetAuthorizationInfoMethods() {
    for (final Realm realm : realms) {
        if (!(realm instanceof AuthorizingRealm)) {
            logger.debug("Unable to retrieve getAuthorizationInfo method from Realm {}: not an AuthorizingRealm", realm);
            continue;
        }
        Method getAuthorizationInfoMethod = null;
        Class<?> clazz = realm.getClass();
        while (clazz != null) {
            final Method[] methods = clazz.getDeclaredMethods();
            for (final Method method : methods) {
                if ("getAuthorizationInfo".equals(method.getName())) {
                    getAuthorizationInfoMethod = method;
                    getAuthorizationInfoMethod.setAccessible(true);
                    break;
                }
            }
            clazz = clazz.getSuperclass();
        }
        if (getAuthorizationInfoMethod == null) {
            logger.debug("Unable to retrieve getAuthorizationInfo method from Realm {}", realm);
            continue;
        }
        getAuthorizationInfoMethods.put(realm, getAuthorizationInfoMethod);
    }
}
Also used : Method(java.lang.reflect.Method) Realm(org.apache.shiro.realm.Realm) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) KillBillJdbcRealm(org.killbill.billing.util.security.shiro.realm.KillBillJdbcRealm) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm)

Aggregations

AuthorizingRealm (org.apache.shiro.realm.AuthorizingRealm)7 Realm (org.apache.shiro.realm.Realm)6 Principal (java.security.Principal)4 ArrayList (java.util.ArrayList)4 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)4 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)4 Permission (org.apache.shiro.authz.Permission)3 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)3 CollectionPermission (ddf.security.permission.CollectionPermission)2 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)2 PermissionsImpl (ddf.security.permission.impl.PermissionsImpl)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Metacard (ddf.catalog.data.Metacard)1 ResultImpl (ddf.catalog.data.impl.ResultImpl)1 DeleteRequest (ddf.catalog.operation.DeleteRequest)1 ResourceRequest (ddf.catalog.operation.ResourceRequest)1 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)1 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)1 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1