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() );
// }
}
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);
}
}
Aggregations