Search in sources :

Example 11 with WebResourceCollection

use of io.undertow.servlet.api.WebResourceCollection in project undertow by undertow-io.

the class WelcomeFileSecurityTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE).setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext").setDeploymentName("servletContext.war").setResourceManager(new TestResourceLoader(WelcomeFileSecurityTestCase.class)).addWelcomePages("doesnotexist.html", "index.html", "default").setIdentityManager(identityManager).setLoginConfig(new LoginConfig("BASIC", "Test Realm")).addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/path/default")).addSecurityConstraint(new SecurityConstraint().addRoleAllowed("role1").addWebResourceCollection(new WebResourceCollection().addUrlPattern("/index.html")));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) ServletSecurityInfo(io.undertow.servlet.api.ServletSecurityInfo) TestResourceLoader(io.undertow.servlet.test.util.TestResourceLoader) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) PathHandler(io.undertow.server.handlers.PathHandler) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServletPathMappingTestCase(io.undertow.servlet.test.path.ServletPathMappingTestCase) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) BeforeClass(org.junit.BeforeClass)

Example 12 with WebResourceCollection

use of io.undertow.servlet.api.WebResourceCollection in project indy by Commonjava.

the class KeycloakDeploymentProvider method getDeploymentInfo.

@Override
public DeploymentInfo getDeploymentInfo() {
    logger.debug("Keycloak deployment provider triggered.");
    final DeploymentInfo di = new DeploymentInfo();
    if (config.isEnabled()) {
        di.addAuthenticationMechanism(BASIC_LOGIN_MECHANISM, new ImmediateAuthenticationMechanismFactory(basicAuthInjector));
        logger.debug("Adding keycloak security constraints");
        final SecurityConstraint ui = new SecurityConstraint();
        ui.setEmptyRoleSemantic(EmptyRoleSemantic.PERMIT);
        final WebResourceCollection uiCollection = new WebResourceCollection();
        uiCollection.addUrlPatterns(UIServlet.PATHS);
        uiCollection.addHttpMethods(UIServlet.METHODS);
        ui.addWebResourceCollection(uiCollection);
        di.addSecurityConstraint(ui);
        for (final KeycloakSecurityConstraint constraint : bindings.getConstraints()) {
            final SecurityConstraint sc = new SecurityConstraint();
            sc.setEmptyRoleSemantic(EmptyRoleSemantic.PERMIT);
            final WebResourceCollection collection = new WebResourceCollection();
            collection.addUrlPattern(constraint.getUrlPattern());
            logger.debug("new constraint>>> URL pattern: {}", constraint.getUrlPattern());
            if (constraint.getMethods() != null) {
                logger.debug("methods: {}", constraint.getMethods());
                collection.addHttpMethods(constraint.getMethods());
            }
            sc.addWebResourceCollection(collection);
            if (constraint.getRole() != null) {
                logger.debug("role: {}", constraint.getRole());
                sc.addRoleAllowed(constraint.getRole());
            }
            logger.debug("Keycloak Security Constraint: {}", sc);
            di.addSecurityConstraint(sc);
        }
        logger.debug("Using keycloak.json: {} (exists? {})", config.getKeycloakJson(), new File(config.getKeycloakJson()).exists());
        di.addInitParameter(KEYCLOAK_CONFIG_FILE_PARAM, config.getKeycloakJson());
        logger.debug("login realm: {}", config.getRealm());
        final LoginConfig loginConfig = new LoginConfig(KEYCLOAK_LOGIN_MECHANISM, config.getRealm());
        loginConfig.addFirstAuthMethod(BASIC_LOGIN_MECHANISM);
        di.setLoginConfig(loginConfig);
    }
    return di;
}
Also used : WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) KeycloakSecurityConstraint(org.commonjava.indy.subsys.keycloak.conf.KeycloakSecurityConstraint) ImmediateAuthenticationMechanismFactory(io.undertow.util.ImmediateAuthenticationMechanismFactory) LoginConfig(io.undertow.servlet.api.LoginConfig) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) File(java.io.File) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) KeycloakSecurityConstraint(org.commonjava.indy.subsys.keycloak.conf.KeycloakSecurityConstraint)

Aggregations

SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)12 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)12 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)11 LoginConfig (io.undertow.servlet.api.LoginConfig)9 ServletInfo (io.undertow.servlet.api.ServletInfo)9 PathHandler (io.undertow.server.handlers.PathHandler)8 DeploymentManager (io.undertow.servlet.api.DeploymentManager)8 ServletContainer (io.undertow.servlet.api.ServletContainer)8 BeforeClass (org.junit.BeforeClass)8 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)6 AuthMethodConfig (io.undertow.servlet.api.AuthMethodConfig)4 ServletSecurityInfo (io.undertow.servlet.api.ServletSecurityInfo)4 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)4 HttpMethodSecurityInfo (io.undertow.servlet.api.HttpMethodSecurityInfo)3 SendAuthTypeServlet (io.undertow.servlet.test.security.SendAuthTypeServlet)3 SendUsernameServlet (io.undertow.servlet.test.security.SendUsernameServlet)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)2 File (java.io.File)2