本文整理汇总了Java中org.apache.tomcat.util.descriptor.web.SecurityConstraint.addAuthRole方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityConstraint.addAuthRole方法的具体用法?Java SecurityConstraint.addAuthRole怎么用?Java SecurityConstraint.addAuthRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.descriptor.web.SecurityConstraint
的用法示例。
在下文中一共展示了SecurityConstraint.addAuthRole方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findSecurityConstraints
import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入方法依赖的package包/类
@Override
public SecurityConstraint[] findSecurityConstraints(final Request request, final Context context) {
final SecurityConstraint[] sc = super.findSecurityConstraints(request, context);
if (beanManager() == null) {
return sc;
}
final FindSecurityConstraintsEvent event = new FindSecurityConstraintsEvent(request.getRequest(), context.getPath());
beanManager().fireEvent(event);
if (!event.getRoles().isEmpty()) {
final SecurityConstraint s = new SecurityConstraint();
final SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*"); // only for the current request
collection.addMethod(request.getMethod());
s.addCollection(collection);
if (event.getUserConstraint() != null) {
s.setUserConstraint(event.getUserConstraint());
}
for(final String r: event.getRoles()) {
s.addAuthRole(r);
}
return new SecurityConstraint[] { s };
}
return sc;
}
示例2: makeContext
import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入方法依赖的package包/类
private void makeContext(Tomcat tomcat, Path noSuchBaseDir) throws IOException {
Path contextPath = noSuchBaseDir.resolve("context");
Files.createDirectories(contextPath);
context = tomcat.addContext(contextPathURIBase, contextPath.toAbsolutePath().toString());
context.setWebappVersion("3.1");
context.setName("Oryx");
context.addWelcomeFile("index.html");
addErrorPages(context);
// OryxApplication only needs one config value, so just pass it
context.addParameter(OryxApplication.class.getName() + ".packages", appResourcesPackages);
// ModelManagerListener will need whole config
String serializedConfig = ConfigUtils.serialize(config);
context.addParameter(ConfigUtils.class.getName() + ".serialized", serializedConfig);
Wrapper wrapper =
Tomcat.addServlet(context, "Jersey", "org.glassfish.jersey.servlet.ServletContainer");
wrapper.addInitParameter("javax.ws.rs.Application", OryxApplication.class.getName());
//wrapper.addInitParameter(OryxApplication.class.getName() + ".packages", appResourcesPackage);
wrapper.addMapping("/*");
wrapper.setLoadOnStartup(1);
wrapper.setMultipartConfigElement(new MultipartConfigElement(""));
if (!doNotInitTopics) { // Only for tests
context.addApplicationListener(ModelManagerListener.class.getName());
}
// Better way to configure JASPIC?
AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());
boolean needHTTPS = keystoreFile != null;
boolean needAuthentication = userName != null;
if (needHTTPS || needAuthentication) {
SecurityCollection securityCollection = new SecurityCollection();
securityCollection.addPattern("/*");
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.addCollection(securityCollection);
if (needHTTPS) {
securityConstraint.setUserConstraint("CONFIDENTIAL");
}
if (needAuthentication) {
LoginConfig loginConfig = new LoginConfig();
loginConfig.setAuthMethod("DIGEST");
loginConfig.setRealmName(InMemoryRealm.NAME);
context.setLoginConfig(loginConfig);
securityConstraint.addAuthRole(InMemoryRealm.AUTH_ROLE);
context.addSecurityRole(InMemoryRealm.AUTH_ROLE);
DigestAuthenticator authenticator = new DigestAuthenticator();
authenticator.setNonceValidity(10 * 1000L); // Shorten from 5 minutes to 10 seconds
authenticator.setNonceCacheSize(20000); // Increase from 1000 to 20000
context.getPipeline().addValve(authenticator);
}
context.addConstraint(securityConstraint);
}
context.setCookies(false);
}
示例3: createNewContext
import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入方法依赖的package包/类
private static Context createNewContext(final ClassLoader classLoader, String authMethod, String transportGuarantee, final String realmName, final String name) {
String path = name;
if (path == null) {
path = "/";
}
if (!path.startsWith("/")) {
path = "/" + path;
}
final StandardContext context = new IgnoredStandardContext();
context.setPath(path);
context.setDocBase("");
context.setParentClassLoader(classLoader);
context.setDelegate(true);
context.setName(name);
((TomcatWebAppBuilder) SystemInstance.get().getComponent(WebAppBuilder.class)).initJ2EEInfo(context);
// Configure security
if (authMethod != null) {
authMethod = authMethod.toUpperCase();
}
if (transportGuarantee != null) {
transportGuarantee = transportGuarantee.toUpperCase();
}
if (authMethod == null || "NONE".equals(authMethod)) { //NOPMD
// ignore none for now as the NonLoginAuthenticator seems to be completely hosed
} else if ("BASIC".equals(authMethod) || "DIGEST".equals(authMethod) || "CLIENT-CERT".equals(authMethod)) {
//Setup a login configuration
final LoginConfig loginConfig = new LoginConfig();
loginConfig.setAuthMethod(authMethod);
loginConfig.setRealmName(realmName);
context.setLoginConfig(loginConfig);
//Setup a default Security Constraint
final String securityRole = SystemInstance.get().getProperty(TOMEE_JAXWS_SECURITY_ROLE_PREFIX + name, "default");
for (final String role : securityRole.split(",")) {
final SecurityCollection collection = new SecurityCollection();
collection.addMethod("GET");
collection.addMethod("POST");
collection.addPattern("/*");
collection.setName(role);
final SecurityConstraint sc = new SecurityConstraint();
sc.addAuthRole("*");
sc.addCollection(collection);
sc.setAuthConstraint(true);
sc.setUserConstraint(transportGuarantee);
context.addConstraint(sc);
context.addSecurityRole(role);
}
//Set the proper authenticator
if ("BASIC".equals(authMethod)) {
context.addValve(new BasicAuthenticator());
} else if ("DIGEST".equals(authMethod)) {
context.addValve(new DigestAuthenticator());
} else if ("CLIENT-CERT".equals(authMethod)) {
context.addValve(new SSLAuthenticator());
} else if ("NONE".equals(authMethod)) {
context.addValve(new NonLoginAuthenticator());
}
context.getPipeline().addValve(new OpenEJBValve());
} else {
throw new IllegalArgumentException("Invalid authMethod: " + authMethod);
}
return context;
}
示例4: createNewContext
import org.apache.tomcat.util.descriptor.web.SecurityConstraint; //导入方法依赖的package包/类
private static Context createNewContext(final ClassLoader classLoader, final String rAuthMethod, final String rTransportGuarantee, final String realmName, final String name) {
String path = name;
if (path == null) {
path = "/";
}
if (!path.startsWith("/")) {
path = "/" + path;
}
final StandardContext context = new IgnoredStandardContext();
context.setPath(path);
context.setDocBase("");
context.setParentClassLoader(classLoader);
context.setDelegate(true);
context.setName(name);
TomcatWebAppBuilder.class.cast(SystemInstance.get().getComponent(WebAppBuilder.class)).initJ2EEInfo(context);
// Configure security
String authMethod = rAuthMethod;
if (authMethod != null) {
authMethod = authMethod.toUpperCase();
}
String transportGuarantee = rTransportGuarantee;
if (transportGuarantee != null) {
transportGuarantee = transportGuarantee.toUpperCase();
}
if (authMethod != null & !"NONE".equals(authMethod)) {
if ("BASIC".equals(authMethod) || "DIGEST".equals(authMethod) || "CLIENT-CERT".equals(authMethod)) {
//Setup a login configuration
final LoginConfig loginConfig = new LoginConfig();
loginConfig.setAuthMethod(authMethod);
loginConfig.setRealmName(realmName);
context.setLoginConfig(loginConfig);
//Setup a default Security Constraint
final String securityRole = SystemInstance.get().getProperty(TOMEE_HESSIAN_SECURITY_ROLE_PREFIX + name, "default");
for (final String role : securityRole.split(",")) {
final SecurityCollection collection = new SecurityCollection();
collection.addMethod("GET");
collection.addMethod("POST");
collection.addPattern("/*");
collection.setName(role);
final SecurityConstraint sc = new SecurityConstraint();
sc.addAuthRole("*");
sc.addCollection(collection);
sc.setAuthConstraint(true);
sc.setUserConstraint(transportGuarantee);
context.addConstraint(sc);
context.addSecurityRole(role);
}
}
//Set the proper authenticator
switch (authMethod) {
case "BASIC":
context.addValve(new BasicAuthenticator());
break;
case "DIGEST":
context.addValve(new DigestAuthenticator());
break;
case "CLIENT-CERT":
context.addValve(new SSLAuthenticator());
break;
case "NONE":
context.addValve(new NonLoginAuthenticator());
break;
}
context.getPipeline().addValve(new OpenEJBValve());
} else {
throw new IllegalArgumentException("Invalid authMethod: " + authMethod);
}
return context;
}