@SuppressWarnings({ "unchecked", "rawtypes" }) private synchronized void lookupTargetBean() { if (targetBean == null) { Method m = implementationMethod.getJavaMember(); Set<Bean<?>> beans = beanManager.getBeans(m.getDeclaringClass()); if (beans.size() == 1) { targetBean = beans.iterator().next(); } else if (beans.isEmpty()) { throw new IllegalStateException("Exception looking up authorizer method bean - " + "no beans found for method [" + m.getDeclaringClass() + "." + m.getName() + "]"); } else if (beans.size() > 1) { throw new IllegalStateException("Exception looking up authorizer method bean - " + "multiple beans found for method [" + m.getDeclaringClass().getName() + "." + m.getName() + "]"); } injectableMethod = new InjectableMethod(implementationMethod, targetBean, beanManager); } }
public void authorize() { if (targetBean == null) { lookupTargetBean(); } CreationalContext<?> cc = beanManager.createCreationalContext(targetBean); Object reference = beanManager.getReference(targetBean, implementationMethod.getJavaMember().getDeclaringClass(), cc); Object result = injectableMethod.invoke(reference, cc, null); if (result.equals(Boolean.FALSE)) { throw new AuthorizationException("Authorization check failed"); } }
public void authorize(InvocationContext context) { if (targetBean == null) { lookupTargetBean(); } CreationalContext<?> cc = beanManager.createCreationalContext(targetBean); Object reference = beanManager.getReference(targetBean, implementationMethod.getJavaMember().getDeclaringClass(), cc); Object result = injectableMethod.invoke(reference, cc, new SecurityParameterValueRedefiner(cc, context)); if (result.equals(Boolean.FALSE)) { throw new AuthorizationException("Authorization check failed"); } }