use of javax.annotation.security.RunAs in project Payara by payara.
the class RunAsHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebComponentContext[] webCompContexts) throws AnnotationProcessorException {
RunAs runAsAn = (RunAs) ainfo.getAnnotation();
for (WebComponentContext webCompContext : webCompContexts) {
WebComponentDescriptor webDesc = webCompContext.getDescriptor();
// override by xml
if (webDesc.getRunAsIdentity() != null) {
continue;
}
String roleName = runAsAn.value();
Role role = new Role(roleName);
// add Role if not exists
webDesc.getWebBundleDescriptor().addRole(role);
RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor();
runAsDesc.setRoleName(roleName);
webDesc.setRunAsIdentity(runAsDesc);
}
return getDefaultProcessedResult();
}
use of javax.annotation.security.RunAs in project tomcat70 by apache.
the class WebAnnotationSet method loadApplicationServletAnnotations.
/**
* Process the annotations for the servlets.
*
* @param context The context which will have its annotations processed
*/
protected static void loadApplicationServletAnnotations(Context context) {
Container[] children = context.findChildren();
for (Container child : children) {
if (child instanceof Wrapper) {
Wrapper wrapper = (Wrapper) child;
if (wrapper.getServletClass() == null) {
continue;
}
Class<?> clazz = Introspection.loadClass(context, wrapper.getServletClass());
if (clazz == null) {
continue;
}
loadClassAnnotation(context, clazz);
loadFieldsAnnotation(context, clazz);
loadMethodsAnnotation(context, clazz);
/* Process RunAs annotation which can be only on servlets.
* Ref JSR 250, equivalent to the run-as element in
* the deployment descriptor
*/
RunAs runAs = clazz.getAnnotation(RunAs.class);
if (runAs != null) {
wrapper.setRunAs(runAs.value());
}
// Process ServletSecurity annotation
ServletSecurity servletSecurity = clazz.getAnnotation(ServletSecurity.class);
if (servletSecurity != null) {
context.addServletSecurity(new ApplicationServletRegistration(wrapper, context), new ServletSecurityElement(servletSecurity));
}
}
}
}
use of javax.annotation.security.RunAs in project tomee by apache.
the class RunAsRule method apply.
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final RunAs annotation = description.getAnnotation(RunAs.class);
final As as = description.getAnnotation(As.class);
String currentRole = role.get();
// no more needed
role.remove();
if (annotation == null && as == null && currentRole == null) {
base.evaluate();
return;
}
final BeanContext beanContext = getBeanContext();
if (currentRole == null) {
if (annotation == null) {
currentRole = as.value();
} else {
currentRole = annotation.value();
}
}
final String runAs = beanContext.getRunAs();
final String runAsUser = beanContext.getRunAsUser();
beanContext.setRunAs(currentRole);
final ThreadContext old = ThreadContext.enter(new ThreadContext(beanContext, null));
try {
base.evaluate();
} finally {
// reset for next test
ThreadContext.exit(old);
beanContext.setRunAs(runAs);
beanContext.setRunAsUser(runAsUser);
}
}
};
}
Aggregations