Search in sources :

Example 1 with BASIC

use of io.undertow.util.Headers.BASIC in project undertow by undertow-io.

the class WebsocketBasicAuthTestCase method setup.

@BeforeClass
public static void setup() throws ServletException {
    final PathHandler path = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    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).addFilter(Servlets.filter("wrapper", WrapperFilter.class)).addFilterUrlMapping("wrapper", "/wrapper/*", DispatcherType.REQUEST).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(DefaultServer.getBufferPool()).setWorker(DefaultServer.getWorker()).addEndpoint(SecuredEndpoint.class).addListener(containerReady -> deployment = containerReady));
    builder.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/*")).addRoleAllowed("role1").setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY));
    deploymentManager = container.addDeployment(builder);
    deploymentManager.deploy();
    path.addPrefixPath(builder.getContextPath(), deploymentManager.start());
    DefaultServer.setRootHandler(path);
}
Also used : FilterChain(javax.servlet.FilterChain) ServletException(javax.servlet.ServletException) TestClassIntrospector(io.undertow.servlet.test.util.TestClassIntrospector) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) ServerWebSocketContainer(io.undertow.websockets.jsr.ServerWebSocketContainer) Endpoint(javax.websocket.Endpoint) MessageHandler(javax.websocket.MessageHandler) Map(java.util.Map) Filter(javax.servlet.Filter) URI(java.net.URI) BASIC(io.undertow.util.Headers.BASIC) AuthMethodConfig(io.undertow.servlet.api.AuthMethodConfig) AfterClass(org.junit.AfterClass) Session(javax.websocket.Session) ContainerProvider(javax.websocket.ContainerProvider) DefaultServer(io.undertow.testutils.DefaultServer) ServerEndpoint(javax.websocket.server.ServerEndpoint) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Principal(java.security.Principal) ServletResponse(javax.servlet.ServletResponse) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) SecurityInfo(io.undertow.servlet.api.SecurityInfo) BeforeClass(org.junit.BeforeClass) CloseReason(javax.websocket.CloseReason) HttpOneOnly(io.undertow.testutils.HttpOneOnly) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) RunWith(org.junit.runner.RunWith) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) HashMap(java.util.HashMap) Servlets(io.undertow.servlet.Servlets) OnOpen(javax.websocket.OnOpen) HttpServletRequest(javax.servlet.http.HttpServletRequest) PathHandler(io.undertow.server.handlers.PathHandler) AUTHORIZATION(io.undertow.util.Headers.AUTHORIZATION) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) ClientConfigurator(io.undertow.websockets.jsr.test.annotated.ClientConfigurator) ServletRequest(javax.servlet.ServletRequest) LoginConfig(io.undertow.servlet.api.LoginConfig) EndpointConfig(javax.websocket.EndpointConfig) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) ServletContainer(io.undertow.servlet.api.ServletContainer) DeploymentManager(io.undertow.servlet.api.DeploymentManager) TimeUnit(java.util.concurrent.TimeUnit) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) FilterConfig(javax.servlet.FilterConfig) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) DispatcherType(javax.servlet.DispatcherType) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) FlexBase64(io.undertow.util.FlexBase64) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) WebResourceCollection(io.undertow.servlet.api.WebResourceCollection) HashMap(java.util.HashMap) PathHandler(io.undertow.server.handlers.PathHandler) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) ServletIdentityManager(io.undertow.servlet.test.security.constraint.ServletIdentityManager) SimpleServletTestCase(io.undertow.servlet.test.SimpleServletTestCase) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) AuthMethodConfig(io.undertow.servlet.api.AuthMethodConfig) ServletContainer(io.undertow.servlet.api.ServletContainer) LoginConfig(io.undertow.servlet.api.LoginConfig) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) BeforeClass(org.junit.BeforeClass)

Aggregations

PathHandler (io.undertow.server.handlers.PathHandler)1 Servlets (io.undertow.servlet.Servlets)1 AuthMethodConfig (io.undertow.servlet.api.AuthMethodConfig)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 DeploymentManager (io.undertow.servlet.api.DeploymentManager)1 LoginConfig (io.undertow.servlet.api.LoginConfig)1 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)1 SecurityInfo (io.undertow.servlet.api.SecurityInfo)1 ServletContainer (io.undertow.servlet.api.ServletContainer)1 WebResourceCollection (io.undertow.servlet.api.WebResourceCollection)1 SimpleServletTestCase (io.undertow.servlet.test.SimpleServletTestCase)1 ServletIdentityManager (io.undertow.servlet.test.security.constraint.ServletIdentityManager)1 TestClassIntrospector (io.undertow.servlet.test.util.TestClassIntrospector)1 DefaultServer (io.undertow.testutils.DefaultServer)1 HttpOneOnly (io.undertow.testutils.HttpOneOnly)1 FlexBase64 (io.undertow.util.FlexBase64)1 AUTHORIZATION (io.undertow.util.Headers.AUTHORIZATION)1 BASIC (io.undertow.util.Headers.BASIC)1 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)1 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)1