Search in sources :

Example 1 with LoginConfig

use of org.apache.tomcat.util.descriptor.web.LoginConfig in project tomcat by apache.

the class TestDigestAuthenticator method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    // Configure a context with digest auth and a single protected resource
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctxt = tomcat.addContext(CONTEXT_PATH, null);
    // Add protected servlet
    Tomcat.addServlet(ctxt, "TesterServlet", new TesterServlet());
    ctxt.addServletMappingDecoded(URI, "TesterServlet");
    SecurityCollection collection = new SecurityCollection();
    collection.addPatternDecoded(URI);
    SecurityConstraint sc = new SecurityConstraint();
    sc.addAuthRole(ROLE);
    sc.addCollection(collection);
    ctxt.addConstraint(sc);
    // Configure the Realm
    TesterMapRealm realm = new TesterMapRealm();
    realm.addUser(USER, PWD);
    realm.addUserRole(USER, ROLE);
    ctxt.setRealm(realm);
    // Configure the authenticator
    LoginConfig lc = new LoginConfig();
    lc.setAuthMethod("DIGEST");
    lc.setRealmName(REALM);
    ctxt.setLoginConfig(lc);
    ctxt.getPipeline().addValve(new DigestAuthenticator());
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) Context(org.apache.catalina.Context) TesterContext(org.apache.tomcat.unittest.TesterContext) Tomcat(org.apache.catalina.startup.Tomcat) TesterMapRealm(org.apache.catalina.startup.TesterMapRealm) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) TesterServlet(org.apache.catalina.startup.TesterServlet) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Example 2 with LoginConfig

use of org.apache.tomcat.util.descriptor.web.LoginConfig in project tomcat by apache.

the class TestNonLoginAndBasicAuthenticator method setUpLogin.

private void setUpLogin() throws Exception {
    // Must have a real docBase for webapps - just use temp
    basicContext = tomcat.addContext(CONTEXT_PATH_LOGIN, System.getProperty("java.io.tmpdir"));
    // Add protected servlet to the context
    Tomcat.addServlet(basicContext, "TesterServlet3", new TesterServlet());
    basicContext.addServletMappingDecoded(URI_PROTECTED, "TesterServlet3");
    SecurityCollection collection = new SecurityCollection();
    collection.addPatternDecoded(URI_PROTECTED);
    SecurityConstraint sc = new SecurityConstraint();
    sc.addAuthRole(ROLE);
    sc.addCollection(collection);
    basicContext.addConstraint(sc);
    // Add unprotected servlet to the context
    Tomcat.addServlet(basicContext, "TesterServlet4", new TesterServlet());
    basicContext.addServletMappingDecoded(URI_PUBLIC, "TesterServlet4");
    SecurityCollection collection2 = new SecurityCollection();
    collection2.addPatternDecoded(URI_PUBLIC);
    SecurityConstraint sc2 = new SecurityConstraint();
    // do not add a role - which signals access permitted without one
    sc2.addCollection(collection2);
    basicContext.addConstraint(sc2);
    // Configure the authenticator and inherit the Realm from Engine
    LoginConfig lc = new LoginConfig();
    lc.setAuthMethod("BASIC");
    basicContext.setLoginConfig(lc);
    AuthenticatorBase basicAuthenticator = new BasicAuthenticator();
    basicContext.getPipeline().addValve(basicAuthenticator);
}
Also used : LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) TesterServlet(org.apache.catalina.startup.TesterServlet) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Example 3 with LoginConfig

use of org.apache.tomcat.util.descriptor.web.LoginConfig in project tomcat by apache.

the class TestSSOnonLoginAndDigestAuthenticator method setUpDigest.

private void setUpDigest(Tomcat tomcat) throws Exception {
    // Must have a real docBase for webapps - just use temp
    Context ctxt = tomcat.addContext(CONTEXT_PATH_DIGEST, System.getProperty("java.io.tmpdir"));
    ctxt.setSessionTimeout(SHORT_TIMEOUT_SECS);
    // Add protected servlet
    Tomcat.addServlet(ctxt, "TesterServlet3", new TesterServlet());
    ctxt.addServletMappingDecoded(URI_PROTECTED, "TesterServlet3");
    SecurityCollection collection = new SecurityCollection();
    collection.addPatternDecoded(URI_PROTECTED);
    SecurityConstraint sc = new SecurityConstraint();
    sc.addAuthRole(ROLE);
    sc.addCollection(collection);
    ctxt.addConstraint(sc);
    // Configure the appropriate authenticator
    LoginConfig lc = new LoginConfig();
    lc.setAuthMethod("DIGEST");
    ctxt.setLoginConfig(lc);
    ctxt.getPipeline().addValve(new DigestAuthenticator());
}
Also used : Context(org.apache.catalina.Context) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) TesterServlet(org.apache.catalina.startup.TesterServlet) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Example 4 with LoginConfig

use of org.apache.tomcat.util.descriptor.web.LoginConfig in project tomcat by apache.

the class TestRequest method testLoginLogout.

/*
     * Test case for {@link Request#login(String, String)} and
     * {@link Request#logout()}.
     */
@Test
public void testLoginLogout() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    LoginConfig config = new LoginConfig();
    config.setAuthMethod("BASIC");
    ctx.setLoginConfig(config);
    ctx.getPipeline().addValve(new BasicAuthenticator());
    Tomcat.addServlet(ctx, "servlet", new LoginLogoutServlet());
    ctx.addServletMappingDecoded("/", "servlet");
    TesterMapRealm realm = new TesterMapRealm();
    realm.addUser(LoginLogoutServlet.USER, LoginLogoutServlet.PWD);
    ctx.setRealm(realm);
    tomcat.start();
    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    assertEquals(LoginLogoutServlet.OK, res.toString());
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) TesterMapRealm(org.apache.catalina.startup.TesterMapRealm) BasicAuthenticator(org.apache.catalina.authenticator.BasicAuthenticator) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 5 with LoginConfig

use of org.apache.tomcat.util.descriptor.web.LoginConfig in project tomcat by apache.

the class TesterSupport method configureClientCertContext.

protected static void configureClientCertContext(Tomcat tomcat) {
    TesterSupport.initSsl(tomcat);
    // Need a web application with a protected and unprotected URL
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    Tomcat.addServlet(ctx, "simple", new SimpleServlet());
    ctx.addServletMappingDecoded("/unprotected", "simple");
    ctx.addServletMappingDecoded("/protected", "simple");
    // Security constraints
    SecurityCollection collection = new SecurityCollection();
    collection.addPatternDecoded("/protected");
    SecurityConstraint sc = new SecurityConstraint();
    sc.addAuthRole(ROLE);
    sc.addCollection(collection);
    ctx.addConstraint(sc);
    // Configure the Realm
    TesterMapRealm realm = new TesterMapRealm();
    realm.addUser("CN=user1, C=US", "not used");
    realm.addUserRole("CN=user1, C=US", ROLE);
    ctx.setRealm(realm);
    // Configure the authenticator
    LoginConfig lc = new LoginConfig();
    lc.setAuthMethod("CLIENT-CERT");
    ctx.setLoginConfig(lc);
    ctx.getPipeline().addValve(new SSLAuthenticator());
}
Also used : SSLContext(javax.net.ssl.SSLContext) Context(org.apache.catalina.Context) TesterMapRealm(org.apache.catalina.startup.TesterMapRealm) SSLAuthenticator(org.apache.catalina.authenticator.SSLAuthenticator) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Aggregations

LoginConfig (org.apache.tomcat.util.descriptor.web.LoginConfig)21 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)13 SecurityCollection (org.apache.tomcat.util.descriptor.web.SecurityCollection)11 Context (org.apache.catalina.Context)9 BasicAuthenticator (org.apache.catalina.authenticator.BasicAuthenticator)7 TesterMapRealm (org.apache.catalina.startup.TesterMapRealm)7 TesterServlet (org.apache.catalina.startup.TesterServlet)5 Tomcat (org.apache.catalina.startup.Tomcat)5 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)4 ServletContext (javax.servlet.ServletContext)3 SSLAuthenticator (org.apache.catalina.authenticator.SSLAuthenticator)3 StandardContext (org.apache.catalina.core.StandardContext)3 Test (org.junit.Test)3 ServletContainerInitializer (javax.servlet.ServletContainerInitializer)2 DigestAuthenticator (org.apache.catalina.authenticator.DigestAuthenticator)2 NonLoginAuthenticator (org.apache.catalina.authenticator.NonLoginAuthenticator)2 TesterServletEncodeUrl (org.apache.catalina.startup.TesterServletEncodeUrl)2 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)2 IgnoredStandardContext (org.apache.tomee.catalina.IgnoredStandardContext)2 OpenEJBValve (org.apache.tomee.catalina.OpenEJBValve)2