@Override
public Void run() {
final ServletSecurity security = servletInfo.getServletClass().getAnnotation(ServletSecurity.class);
if (security != null) {
ServletSecurityInfo servletSecurityInfo = new ServletSecurityInfo()
.setEmptyRoleSemantic(security.value().value() == ServletSecurity.EmptyRoleSemantic.DENY ? SecurityInfo.EmptyRoleSemantic.DENY : SecurityInfo.EmptyRoleSemantic.PERMIT)
.setTransportGuaranteeType(security.value().transportGuarantee() == ServletSecurity.TransportGuarantee.CONFIDENTIAL ? TransportGuaranteeType.CONFIDENTIAL : TransportGuaranteeType.NONE)
.addRolesAllowed(security.value().rolesAllowed());
for (HttpMethodConstraint constraint : security.httpMethodConstraints()) {
servletSecurityInfo.addHttpMethodSecurityInfo(new HttpMethodSecurityInfo()
.setMethod(constraint.value()))
.setEmptyRoleSemantic(constraint.emptyRoleSemantic() == ServletSecurity.EmptyRoleSemantic.DENY ? SecurityInfo.EmptyRoleSemantic.DENY : SecurityInfo.EmptyRoleSemantic.PERMIT)
.setTransportGuaranteeType(constraint.transportGuarantee() == ServletSecurity.TransportGuarantee.CONFIDENTIAL ? TransportGuaranteeType.CONFIDENTIAL : TransportGuaranteeType.NONE)
.addRolesAllowed(constraint.rolesAllowed());
}
servletInfo.setServletSecurityInfo(servletSecurityInfo);
}
final MultipartConfig multipartConfig = servletInfo.getServletClass().getAnnotation(MultipartConfig.class);
if (multipartConfig != null) {
servletInfo.setMultipartConfig(new MultipartConfigElement(multipartConfig.location(), multipartConfig.maxFileSize(), multipartConfig.maxRequestSize(), multipartConfig.fileSizeThreshold()));
}
final RunAs runAs = servletInfo.getServletClass().getAnnotation(RunAs.class);
if (runAs != null) {
servletInfo.setRunAs(runAs.value());
}
final DeclareRoles declareRoles = servletInfo.getServletClass().getAnnotation(DeclareRoles.class);
if (declareRoles != null) {
deploymentInfo.addSecurityRoles(declareRoles.value());
}
return null;
}
java类javax.annotation.security.RunAs的实例源码
ServletContextImpl.java 文件源码
项目:lams
阅读 32
收藏 0
点赞 0
评论 0
WebAnnotationSet.java 文件源码
项目:class-guard
阅读 34
收藏 0
点赞 0
评论 0
/**
* Process the annotations for the servlets.
*/
protected static void loadApplicationServletAnnotations(Context context) {
Wrapper wrapper = null;
Class<?> classClass = null;
Container[] children = context.findChildren();
for (int i = 0; i < children.length; i++) {
if (children[i] instanceof Wrapper) {
wrapper = (Wrapper) children[i];
if (wrapper.getServletClass() == null) {
continue;
}
classClass = Introspection.loadClass(context,
wrapper.getServletClass());
if (classClass == null) {
continue;
}
loadClassAnnotation(context, classClass);
loadFieldsAnnotation(context, classClass);
loadMethodsAnnotation(context, classClass);
/* Process RunAs annotation which can be only on servlets.
* Ref JSR 250, equivalent to the run-as element in
* the deployment descriptor
*/
if (classClass.isAnnotationPresent(RunAs.class)) {
RunAs annotation = classClass.getAnnotation(RunAs.class);
wrapper.setRunAs(annotation.value());
}
}
}
}
WebAnnotationSet.java 文件源码
项目:apache-tomcat-7.0.57
阅读 42
收藏 0
点赞 0
评论 0
/**
* Process the annotations for the servlets.
*/
protected static void loadApplicationServletAnnotations(Context context) {
Wrapper wrapper = null;
Class<?> classClass = null;
Container[] children = context.findChildren();
for (int i = 0; i < children.length; i++) {
if (children[i] instanceof Wrapper) {
wrapper = (Wrapper) children[i];
if (wrapper.getServletClass() == null) {
continue;
}
classClass = Introspection.loadClass(context,
wrapper.getServletClass());
if (classClass == null) {
continue;
}
loadClassAnnotation(context, classClass);
loadFieldsAnnotation(context, classClass);
loadMethodsAnnotation(context, classClass);
/* Process RunAs annotation which can be only on servlets.
* Ref JSR 250, equivalent to the run-as element in
* the deployment descriptor
*/
RunAs annotation = classClass.getAnnotation(RunAs.class);
if (annotation != null) {
wrapper.setRunAs(annotation.value());
}
}
}
}
WebAnnotationSet.java 文件源码
项目:apache-tomcat-7.0.57
阅读 24
收藏 0
点赞 0
评论 0
/**
* Process the annotations for the servlets.
*/
protected static void loadApplicationServletAnnotations(Context context) {
Wrapper wrapper = null;
Class<?> classClass = null;
Container[] children = context.findChildren();
for (int i = 0; i < children.length; i++) {
if (children[i] instanceof Wrapper) {
wrapper = (Wrapper) children[i];
if (wrapper.getServletClass() == null) {
continue;
}
classClass = Introspection.loadClass(context,
wrapper.getServletClass());
if (classClass == null) {
continue;
}
loadClassAnnotation(context, classClass);
loadFieldsAnnotation(context, classClass);
loadMethodsAnnotation(context, classClass);
/* Process RunAs annotation which can be only on servlets.
* Ref JSR 250, equivalent to the run-as element in
* the deployment descriptor
*/
RunAs annotation = classClass.getAnnotation(RunAs.class);
if (annotation != null) {
wrapper.setRunAs(annotation.value());
}
}
}
}
RunAsRule.java 文件源码
项目:tomee
阅读 27
收藏 0
点赞 0
评论 0
@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();
role.remove(); // no more needed
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);
}
}
};
}