Java Code Examples for org.apache.catalina.core.StandardContext#addParameter()
The following examples show how to use
org.apache.catalina.core.StandardContext#addParameter() .
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: BasicAuthAuthenticatorTest.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
@Test(description = "This method tests the behaviour of canHandle method when different wrong values given for a " + "request") public void testCanHandleWithoutRequireParameters() throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException { request = new Request(); context = new StandardContext(); request.setContext(context); Assert.assertFalse(basicAuthAuthenticator.canHandle(request), "Without proper headers and parameters, the request can be handled by BasicAuthAuthenticator."); context.addParameter("basicAuth", "true"); request.setContext(context); Assert.assertFalse(basicAuthAuthenticator.canHandle(request), "Without proper Authentication headers request can be handled by BasicAuthAuthenticator."); coyoteRequest = new org.apache.coyote.Request(); mimeHeaders = new MimeHeaders(); bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER); bytes.setString("test"); headersField.set(coyoteRequest, mimeHeaders); request.setCoyoteRequest(coyoteRequest); Assert.assertFalse(basicAuthAuthenticator.canHandle(request), "With a different authorization header Basic Authenticator can handle the request"); }
Example 2
Source File: BasicAuthAuthenticatorTest.java From carbon-device-mgt with Apache License 2.0 | 6 votes |
@Test(description = "This method tests the behaviour of the authenticate method in BasicAuthenticator with valid " + "credentials", dependsOnMethods = "testCanHandleWithRequireParameters") public void testAuthenticateWithValidCredentials() throws EncoderException, IllegalAccessException { String encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":" + ADMIN_USER).getBytes())); request = new Request(); context = new StandardContext(); context.addParameter("basicAuth", "true"); request.setContext(context); mimeHeaders = new MimeHeaders(); bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER); bytes.setString(BASIC_HEADER + encodedString); coyoteRequest = new org.apache.coyote.Request(); headersField.set(coyoteRequest, mimeHeaders); request.setCoyoteRequest(coyoteRequest); AuthenticationInfo authenticationInfo = basicAuthAuthenticator.authenticate(request, null); Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.CONTINUE, "For a valid user authentication failed."); Assert.assertEquals(authenticationInfo.getUsername(), ADMIN_USER, "Authenticated username for from BasicAuthenticator is not matching with the original user."); Assert.assertEquals(authenticationInfo.getTenantDomain(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, "Authenticated user's tenant domain from BasicAuthenticator is not matching with the " + "original user's tenant domain"); Assert.assertEquals(authenticationInfo.getTenantId(), MultitenantConstants.SUPER_TENANT_ID, "Authenticated user's tenant ID from BasicAuthenticator is not matching with the " + "original user's tenant ID"); }
Example 3
Source File: BasicAuthAuthenticatorTest.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
@Test(description = "This method tests the canHandle method when all the required parameters are given with the " + "request", dependsOnMethods = {"testCanHandleWithoutRequireParameters"}) public void testCanHandleWithRequireParameters() throws IllegalAccessException { request = new Request(); context = new StandardContext(); context.addParameter("basicAuth", "true"); request.setContext(context); mimeHeaders = new MimeHeaders(); bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER); bytes.setString(BASIC_HEADER); headersField.set(coyoteRequest, mimeHeaders); request.setCoyoteRequest(coyoteRequest); Assert.assertTrue(basicAuthAuthenticator.canHandle(request), "Basic Authenticator cannot handle a request with all the required headers and parameters."); }
Example 4
Source File: TomcatLoader.java From tomee with Apache License 2.0 | 5 votes |
/** * Process running web applications for ejb deployments. * * @param tomcatWebAppBuilder tomcat web app builder instance * @param standardServer tomcat server instance */ private void processRunningApplications(final TomcatWebAppBuilder tomcatWebAppBuilder, final StandardServer standardServer) { for (final org.apache.catalina.Service service : standardServer.findServices()) { if (service.getContainer() instanceof Engine) { final Engine engine = (Engine) service.getContainer(); for (final Container engineChild : engine.findChildren()) { if (engineChild instanceof Host) { final Host host = (Host) engineChild; for (final Container hostChild : host.findChildren()) { if (hostChild instanceof StandardContext) { final StandardContext standardContext = (StandardContext) hostChild; final int state = TomcatHelper.getContextState(standardContext); if (state == 0) { // context only initialized tomcatWebAppBuilder.init(standardContext); } else if (state == 1) { // context already started standardContext.addParameter("openejb.start.late", "true"); final ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(standardContext.getLoader().getClassLoader()); try { tomcatWebAppBuilder.init(standardContext); tomcatWebAppBuilder.beforeStart(standardContext); tomcatWebAppBuilder.start(standardContext); tomcatWebAppBuilder.afterStart(standardContext); } finally { Thread.currentThread().setContextClassLoader(oldCL); } standardContext.removeParameter("openejb.start.late"); } } } } } } } }