in deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/authorization/SecurityParameterValueRedefiner.java [60:132]
public Object redefineParameterValue(ParameterValue value)
{
InjectionPoint injectionPoint = value.getInjectionPoint();
if (injectionPoint != null)
{
if (value.getInjectionPoint().getAnnotated().getBaseType().equals(InvocationContext.class))
{
return invocation;
}
else if (value.getInjectionPoint().getAnnotated().isAnnotationPresent(SecuredReturn.class))
{
return result;
}
else
{
Annotated securingParameterAnnotatedType = injectionPoint.getAnnotated();
Set<Annotation> securingParameterAnnotations = securingParameterAnnotatedType.getAnnotations();
Set<Annotation> requiredBindingAnnotations = new HashSet<Annotation>();
for (Annotation annotation : securingParameterAnnotations)
{
if (annotation.annotationType().isAnnotationPresent(SecurityParameterBinding.class))
{
requiredBindingAnnotations.add(annotation);
}
}
if (!requiredBindingAnnotations.isEmpty())
{
Method method = invocation.getMethod();
Annotation[][] businessMethodParameterAnnotations = method.getParameterAnnotations();
for (int i = 0; i < businessMethodParameterAnnotations.length; i++)
{
List<Annotation> businessParameterAnnotations = Arrays
.asList(businessMethodParameterAnnotations[i]);
for (Annotation annotation : requiredBindingAnnotations)
{
if (businessParameterAnnotations.contains(annotation))
{
return invocation.getParameters()[i];
}
}
Set<Integer> hashCodesOfBusinessParameterAnnotations =
new HashSet<Integer>(businessParameterAnnotations.size());
for (Annotation annotation : businessParameterAnnotations)
{
hashCodesOfBusinessParameterAnnotations.add(beanManager.getQualifierHashCode(annotation));
}
//2nd try (detailed check)
for (Annotation annotation : requiredBindingAnnotations)
{
if (hashCodesOfBusinessParameterAnnotations.contains(beanManager.getQualifierHashCode(annotation)))
{
return invocation.getParameters()[i];
}
}
}
throw new IllegalStateException("Missing required security parameter binding "
+ requiredBindingAnnotations + " on method invocation ["
+ method.getDeclaringClass().getName() + "." + method.getName()
+ Arrays.asList(method.getParameterTypes()).toString().replaceFirst("\\[", "(")
.replaceFirst("\\]$", ")") + "]");
}
}
}
return value.getDefaultValue(creationalContext);
}