io.undertow.servlet.api.LoginConfig Java Examples

The following examples show how to use io.undertow.servlet.api.LoginConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServletClientCertAuthTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException, IOException {
    DefaultServer.startSSLServer();
    clientSSLContext = DefaultServer.getClientSSLContext();


    final PathHandler path = new PathHandler();

    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo usernameServlet = new ServletInfo("Username Servlet", SendUsernameServlet.class)
            .addMapping("/secured/username");

    ServletInfo authTypeServlet = new ServletInfo("Auth Type Servlet", SendAuthTypeServlet.class)
            .addMapping("/secured/authType");

    LoginConfig loginConfig = new LoginConfig(REALM_NAME);
    loginConfig.addFirstAuthMethod(new AuthMethodConfig("CLIENT_CERT"));
    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setIdentityManager(identityManager)
            .setLoginConfig(loginConfig)
            .addServlets(usernameServlet, authTypeServlet);

    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/secured/*"))
            .addRoleAllowed("role1")
            .setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example #2
Source File: SamlServletExtension.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected String getErrorPage(DeploymentInfo deploymentInfo) {
    LoginConfig loginConfig = deploymentInfo.getLoginConfig();
    String errorPage = null;
    if (loginConfig != null) {
        errorPage = loginConfig.getErrorPage();
    }
    return errorPage;
}
 
Example #3
Source File: SamlServletExtension.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public boolean isAuthenticationMechanismPresent(DeploymentInfo deploymentInfo, final String mechanismName) {
    LoginConfig loginConfig = deploymentInfo.getLoginConfig();
    if (loginConfig != null) {
        for (AuthMethodConfig method : loginConfig.getAuthMethods()) {
            if (method.getName().equalsIgnoreCase(mechanismName)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #4
Source File: KeycloakServletExtension.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected String getErrorPage(DeploymentInfo deploymentInfo) {
    LoginConfig loginConfig = deploymentInfo.getLoginConfig();
    String errorPage = null;
    if (loginConfig != null) {
        errorPage = loginConfig.getErrorPage();
    }
    return errorPage;
}
 
Example #5
Source File: KeycloakServletExtension.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public boolean isAuthenticationMechanismPresent(DeploymentInfo deploymentInfo, final String mechanismName) {
    LoginConfig loginConfig = deploymentInfo.getLoginConfig();
    if (loginConfig != null) {
        for (AuthMethodConfig method : loginConfig.getAuthMethods()) {
            if (method.getName().equalsIgnoreCase(mechanismName)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #6
Source File: SecurityRedirectTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@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(SecurityRedirectTestCase.class))
            .addWelcomePages("index.html")
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("BASIC", "Test Realm"))
            .addSecurityConstraint(new SecurityConstraint()
                    .addRoleAllowed("role1")
                    .addWebResourceCollection(new WebResourceCollection()
                            .addUrlPatterns("/index.html", "/filterpath/*")));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
 
Example #7
Source File: WelcomeFileSecurityTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #8
Source File: DigestAuthTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler path = new PathHandler();

    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo usernameServlet = new ServletInfo("Username Servlet", SendUsernameServlet.class)
            .addMapping("/secured/username");

    ServletInfo authTypeServlet = new ServletInfo("Auth Type Servlet", SendAuthTypeServlet.class)
            .addMapping("/secured/authType");

    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("DIGEST", REALM_NAME))
            .addServlets(usernameServlet, authTypeServlet);

    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
            .addUrlPattern("/secured/*"))
            .addRoleAllowed("role1")
            .setEmptyRoleSemantic(EmptyRoleSemantic.DENY));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example #9
Source File: ServletCustomAuthTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler path = new PathHandler();

    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", SendUsernameServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/secured/*");

    ServletInfo s1 = new ServletInfo("loginPage", FormLoginServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("group1"))
            .addMapping("/FormLoginServlet");


    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html"))
            .addServlets(s, s1)
            .addAuthenticationMechanism("FORM", CustomAuthenticationMechanism.FACTORY);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example #10
Source File: ServletLoginTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", SendUsernameServlet.class)
            .addMapping("/*");

    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    identityManager.addUser("user2", "password2", "role2");
    identityManager.addUser("user3", "password3", "role3");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("BASIC", "Test Realm"))
            .addServlet(s)
            .addFilter(new FilterInfo("LoginFilter", LoginFilter.class))
            .addFilterServletNameMapping("LoginFilter", "servlet", DispatcherType.REQUEST);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example #11
Source File: ServletFormAuthURLRewriteTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler path = new PathHandler();

    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", SendUsernameServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/secured/*");

    ServletInfo echo = new ServletInfo("echo", EchoServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/secured/echo");

    ServletInfo echoParam = new ServletInfo("echoParam", RequestParamEchoServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/secured/echoParam");

    ServletInfo s1 = new ServletInfo("loginPage", FormLoginServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("group1"))
            .addMapping("/FormLoginServlet");


    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");

    DeploymentInfo builder = new DeploymentInfo()
            .setServletSessionConfig(new ServletSessionConfig().setSessionTrackingModes(Collections.singleton(SessionTrackingMode.URL)))
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setAuthenticationMode(AuthenticationMode.CONSTRAINT_DRIVEN)
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html"))
            .addServlets(s, s1, echo,echoParam);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example #12
Source File: ServletBasicAuthTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler path = new PathHandler();

    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo usernameServlet = new ServletInfo("Username Servlet", SendUsernameServlet.class)
            .addMapping("/secured/username");

    ServletInfo authTypeServlet = new ServletInfo("Auth Type Servlet", SendAuthTypeServlet.class)
            .addMapping("/secured/authType");

    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    identityManager.addUser("charsetUser", "password-ΓΌ", "role1");

    LoginConfig loginConfig = new LoginConfig(REALM_NAME);
    Map<String, String> props = new HashMap<>();
    props.put("charset", "ISO_8859_1");
    props.put("user-agent-charsets", "Chrome,UTF-8,OPR,UTF-8");
    loginConfig.addFirstAuthMethod(new AuthMethodConfig("BASIC", props));
    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setIdentityManager(identityManager)
            .setLoginConfig(loginConfig)
            .addServlets(usernameServlet, authTypeServlet);

    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/secured/*"))
            .addRoleAllowed("role1")
            .setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example #13
Source File: Servlets.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public static LoginConfig loginConfig(String realmName, String loginPage, String errorPage) {
    return new LoginConfig(realmName, loginPage, errorPage);
}
 
Example #14
Source File: ServletFormAuthTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler path = new PathHandler();

    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", SendUsernameServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/secured/*");

    ServletInfo echo = new ServletInfo("echo", EchoServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/secured/echo");

    ServletInfo echoParam = new ServletInfo("echoParam", RequestParamEchoServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/secured/echoParam");

    ServletInfo s1 = new ServletInfo("loginPage", FormLoginServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("group1"))
            .addMapping("/FormLoginServlet");


    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setAuthenticationMode(AuthenticationMode.CONSTRAINT_DRIVEN)
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html"))
            .addServlets(s, s1, echo,echoParam);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example #15
Source File: SaveOriginalPostRequestTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {
    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo securedRequestDumper = new ServletInfo("SecuredRequestDumperServlet", RequestDumper.class)
                                       .setServletSecurityInfo(new ServletSecurityInfo()
                                                               .addRoleAllowed("role1"))
                                       .addMapping("/secured/dumpRequest");

    ServletInfo securedIndexRequestDumper = new ServletInfo("SecuredIndexRequestDumperServlet", RequestDumper.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/index.html");
    ServletInfo unsecuredRequestDumper = new ServletInfo("UnsecuredRequestDumperServlet", RequestDumper.class)
                                         .addMapping("/dumpRequest");
    ServletInfo loginFormServlet = new ServletInfo("loginPage", FormLoginServlet.class)
                     .setServletSecurityInfo(new ServletSecurityInfo()
                                             .addRoleAllowed("group1"))
                     .addMapping("/FormLoginServlet");

    ServletIdentityManager identityManager = new ServletIdentityManager();

    identityManager.addUser("user1", "password1", "role1");

    DeploymentInfo builder = new DeploymentInfo()
                             .setClassLoader(SimpleServletTestCase.class.getClassLoader())
                             .setContextPath("/servletContext")
                             .setClassIntrospecter(TestClassIntrospector.INSTANCE)
                             .setDeploymentName("servletContext.war")
                             .setIdentityManager(identityManager)
                             .addWelcomePage("index.html")
                             .setResourceManager(new TestResourceLoader(SaveOriginalPostRequestTestCase.class))
                             .setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html"))
                             .addServlets(securedRequestDumper, unsecuredRequestDumper, loginFormServlet, securedIndexRequestDumper);

    DeploymentManager manager = container.addDeployment(builder);

    manager.deploy();

    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example #16
Source File: EmptyRoleSemanticTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", AuthenticationMessageServlet.class)
            .addInitParam(MessageServlet.MESSAGE, HELLO_WORLD)
            .addMapping("/permit")
            .addMapping("/deny")
            .addMapping("/authenticate");

    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1"); // Just one role less user.

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("BASIC", "Test Realm"))
            .addServlet(s);

    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection().addUrlPattern("/permit"))
            .setEmptyRoleSemantic(EmptyRoleSemantic.PERMIT));

    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection().addUrlPattern("/deny"))
            .setEmptyRoleSemantic(EmptyRoleSemantic.DENY));

    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection().addUrlPattern("/authenticate"))
            .setEmptyRoleSemantic(EmptyRoleSemantic.AUTHENTICATE));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #17
Source File: Servlets.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static LoginConfig loginConfig(String realmName, String loginPage, String errorPage) {
    return new LoginConfig(realmName, loginPage, errorPage);
}
 
Example #18
Source File: Servlets.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static LoginConfig loginConfig(final String realmName) {
    return new LoginConfig(realmName);
}
 
Example #19
Source File: Servlets.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static LoginConfig loginConfig(String mechanismName, String realmName, String loginPage, String errorPage) {
    return new LoginConfig(mechanismName, realmName, loginPage, errorPage);
}
 
Example #20
Source File: Servlets.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static LoginConfig loginConfig(String mechanismName, final String realmName) {
    return new LoginConfig(mechanismName, realmName);
}
 
Example #21
Source File: SecurityConstraintUrlMappingTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", AuthenticationMessageServlet.class)
            .addInitParam(MessageServlet.MESSAGE, HELLO_WORLD)
            .addMapping("/role1")
            .addMapping("/role2")
            .addMapping("/starstar")
            .addMapping("/secured/role2/*")
            .addMapping("/secured/1/2/*")
            .addMapping("/public/*")
            .addMapping("/extension/*");

    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    identityManager.addUser("user2", "password2", "role2", "**");
    identityManager.addUser("user3", "password3", "role1", "role2");
    identityManager.addUser("user4", "password4", "badRole");

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("BASIC", "Test Realm"))
            .addServlet(s);

    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/role1"))
            .addRoleAllowed("role1"));

    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/starstar"))
            .addRoleAllowed("**"));
    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/secured/*"))
            .addRoleAllowed("role2"));
    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/secured/*"))
            .addRoleAllowed("role2"));
    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/secured/1/*"))
            .addRoleAllowed("role1"));
    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/secured/1/2/*"))
            .addRoleAllowed("role2"));
    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("*.html"))
            .addRoleAllowed("role2"));
    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/public/*")).setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT));
    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/public/postSecured/*")
                    .addHttpMethod("POST"))
            .addRoleAllowed("role1"));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/star")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("BASIC", "Test Realm"))
            .addSecurityRole("**")
            .addServlet(s);

    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection()
                    .addUrlPattern("/starstar"))
            .addRoleAllowed("**"));

    manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());
    DefaultServer.setRootHandler(root);
}
 
Example #22
Source File: Servlets.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public static LoginConfig loginConfig(String mechanismName, final String realmName) {
    return new LoginConfig(mechanismName, realmName);
}
 
Example #23
Source File: Servlets.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public static LoginConfig loginConfig(String mechanismName, String realmName, String loginPage, String errorPage) {
    return new LoginConfig(mechanismName, realmName, loginPage, errorPage);
}
 
Example #24
Source File: Servlets.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public static LoginConfig loginConfig(final String realmName) {
    return new LoginConfig(realmName);
}