List of usage examples for javax.servlet ServletConfig getInitParameter
public String getInitParameter(String name);
From source file:com.sap.cloudlabs.connectivity.proxy.ProxyServlet.java
public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); String securityHandlerName = servletConfig.getInitParameter("security.handler"); if (securityHandlerName != null) { try {/*w w w. j a v a 2s. c om*/ Class<?> clazz = Class.forName(securityHandlerName); if (SecurityHandler.class.isAssignableFrom(clazz)) { securityHandler = (SecurityHandler) clazz.newInstance(); } else { LOGGER.debug("Provided security.handler " + securityHandlerName + " is not an implementation of SecurityHandler class: "); } // no exception will be thrown as the proxy servlet can work without security handler implementation } catch (ClassNotFoundException e) { LOGGER.error("Provided security.handler " + securityHandlerName + " cannot be loaded"); } catch (InstantiationException e) { LOGGER.error("Provided security.handler " + securityHandlerName + " cannot be instantioated"); } catch (IllegalAccessException e) { LOGGER.error("Provided security.handler " + securityHandlerName + " cannot be accessed"); } } }
From source file:org.apache.chemistry.opencmis.server.impl.atompub.CmisAtomPubServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); // set the binding setBinding(CallContext.BINDING_ATOMPUB); // get and CMIS version String cmisVersionStr = config.getInitParameter(PARAM_CMIS_VERSION); if (cmisVersionStr != null) { try {/*from w w w .j a va 2s . com*/ setCmisVersion(CmisVersion.fromValue(cmisVersionStr)); } catch (IllegalArgumentException e) { LOG.warn("CMIS version is invalid! Setting it to CMIS 1.0."); setCmisVersion(CmisVersion.CMIS_1_0); } } else { LOG.warn("CMIS version is not defined! Setting it to CMIS 1.0."); setCmisVersion(CmisVersion.CMIS_1_0); } // initialize resources addResource("", METHOD_GET, new RepositoryService.GetRepositories()); addResource(RESOURCE_TYPES, METHOD_GET, new RepositoryService.GetTypeChildren()); addResource(RESOURCE_TYPES, METHOD_POST, new RepositoryService.CreateType()); addResource(RESOURCE_TYPESDESC, METHOD_GET, new RepositoryService.GetTypeDescendants()); addResource(RESOURCE_TYPE, METHOD_GET, new RepositoryService.GetTypeDefinition()); addResource(RESOURCE_TYPE, METHOD_PUT, new RepositoryService.UpdateType()); addResource(RESOURCE_TYPE, METHOD_DELETE, new RepositoryService.DeleteType()); addResource(RESOURCE_CHILDREN, METHOD_GET, new NavigationService.GetChildren()); addResource(RESOURCE_DESCENDANTS, METHOD_GET, new NavigationService.GetDescendants()); addResource(RESOURCE_FOLDERTREE, METHOD_GET, new NavigationService.GetFolderTree()); addResource(RESOURCE_PARENT, METHOD_GET, new NavigationService.GetFolderParent()); addResource(RESOURCE_PARENTS, METHOD_GET, new NavigationService.GetObjectParents()); addResource(RESOURCE_CHECKEDOUT, METHOD_GET, new NavigationService.GetCheckedOutDocs()); addResource(RESOURCE_ENTRY, METHOD_GET, new ObjectService.GetObject()); addResource(RESOURCE_OBJECTBYID, METHOD_GET, new ObjectService.GetObject()); addResource(RESOURCE_OBJECTBYPATH, METHOD_GET, new ObjectService.GetObjectByPath()); addResource(RESOURCE_ALLOWABLEACIONS, METHOD_GET, new ObjectService.GetAllowableActions()); addResource(RESOURCE_CONTENT, METHOD_GET, new ObjectService.GetContentStream()); addResource(RESOURCE_CONTENT, METHOD_PUT, new ObjectService.SetOrAppendContentStream()); addResource(RESOURCE_CONTENT, METHOD_DELETE, new ObjectService.DeleteContentStream()); addResource(RESOURCE_CHILDREN, METHOD_POST, new ObjectService.Create()); addResource(RESOURCE_RELATIONSHIPS, METHOD_POST, new ObjectService.CreateRelationship()); addResource(RESOURCE_ENTRY, METHOD_PUT, new ObjectService.UpdateProperties()); addResource(RESOURCE_ENTRY, METHOD_DELETE, new ObjectService.DeleteObject()); addResource(RESOURCE_CHILDREN, METHOD_DELETE, new ObjectService.DeleteTree()); // 1.1 addResource(RESOURCE_DESCENDANTS, METHOD_DELETE, new ObjectService.DeleteTree()); addResource(RESOURCE_FOLDERTREE, METHOD_DELETE, new ObjectService.DeleteTree()); addResource(RESOURCE_BULK_UPDATE, METHOD_POST, new ObjectService.BulkUpdateProperties()); addResource(RESOURCE_CHECKEDOUT, METHOD_POST, new VersioningService.CheckOut()); addResource(RESOURCE_VERSIONS, METHOD_GET, new VersioningService.GetAllVersions()); addResource(RESOURCE_VERSIONS, METHOD_DELETE, new VersioningService.DeleteAllVersions()); addResource(RESOURCE_QUERY, METHOD_GET, new DiscoveryService.Query()); addResource(RESOURCE_QUERY, METHOD_POST, new DiscoveryService.Query()); addResource(RESOURCE_CHANGES, METHOD_GET, new DiscoveryService.GetContentChanges()); addResource(RESOURCE_RELATIONSHIPS, METHOD_GET, new RelationshipService.GetObjectRelationships()); addResource(RESOURCE_UNFILED, METHOD_POST, new MultiFilingService.RemoveObjectFromFolder()); addResource(RESOURCE_ACL, METHOD_GET, new AclService.GetAcl()); addResource(RESOURCE_ACL, METHOD_PUT, new AclService.ApplyAcl()); addResource(RESOURCE_POLICIES, METHOD_GET, new PolicyService.GetAppliedPolicies()); addResource(RESOURCE_POLICIES, METHOD_POST, new PolicyService.ApplyPolicy()); addResource(RESOURCE_POLICIES, METHOD_DELETE, new PolicyService.RemovePolicy()); }
From source file:test.unit.be.fedict.eid.applet.service.IdentityDataMessageHandlerTest.java
@Test public void testHandleMessage() throws Exception { // setup//from w w w . j a v a2 s. co m ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class); Map<String, String> httpHeaders = new HashMap<String, String>(); HttpSession mockHttpSession = EasyMock.createMock(HttpSession.class); HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class); EasyMock.expect(mockServletConfig.getInitParameter("IdentityIntegrityService")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("IdentityIntegrityServiceClass")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("AuditService")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("AuditServiceClass")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("SkipNationalNumberCheck")).andStubReturn(null); mockHttpSession.setAttribute(EasyMock.eq("eid.identity"), EasyMock.isA(Identity.class)); EasyMock.expect(mockHttpSession.getAttribute("eid")).andStubReturn(null); mockHttpSession.setAttribute(EasyMock.eq("eid"), EasyMock.isA(EIdData.class)); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_ADDRESS_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_CERTIFICATES_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_PHOTO_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockServletConfig.getInitParameter(IdentityDataMessageHandler.INCLUDE_DATA_FILES)) .andReturn(null); byte[] idFile = "foobar-id-file".getBytes(); IdentityDataMessage message = new IdentityDataMessage(); message.idFile = idFile; // prepare EasyMock.replay(mockServletConfig, mockHttpSession, mockServletRequest); // operate AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance); this.testedInstance.init(mockServletConfig); this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, mockHttpSession); // verify EasyMock.verify(mockServletConfig, mockHttpSession, mockServletRequest); }
From source file:org.sakaiproject.login.tool.SkinnableLogin.java
public void init(ServletConfig config) throws ServletException { super.init(config); loginContext = config.getInitParameter("login.context"); if (loginContext == null || loginContext.length() == 0) { loginContext = DEFAULT_LOGIN_CONTEXT; }/*from w w w . j ava2 s . c o m*/ loginService = (LoginService) ComponentManager.get(LoginService.class); serverConfigurationService = (ServerConfigurationService) ComponentManager .get(ServerConfigurationService.class); siteService = (SiteService) ComponentManager.get(SiteService.class); log.info("init()"); }
From source file:test.unit.be.fedict.eid.applet.service.IdentityDataMessageHandlerTest.java
public void testHandleMessageCorruptIntegritySignature() throws Exception { // setup//from w w w .j a v a2 s. c om KeyPair keyPair = MiscTestUtils.generateKeyPair(); DateTime notBefore = new DateTime(); DateTime notAfter = notBefore.plusYears(1); X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(), "CN=TestNationalRegistration", notBefore, notAfter, null, keyPair.getPrivate(), true, 0, null, null); ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class); Map<String, String> httpHeaders = new HashMap<String, String>(); HttpSession mockHttpSession = EasyMock.createMock(HttpSession.class); HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class); EasyMock.expect(mockServletConfig.getInitParameter("IdentityIntegrityService")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("IdentityIntegrityServiceClass")) .andStubReturn(IdentityIntegrityTestService.class.getName()); EasyMock.expect(mockServletConfig.getInitParameter("AuditService")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("AuditServiceClass")) .andStubReturn(AuditTestService.class.getName()); EasyMock.expect(mockServletConfig.getInitParameter("SkipNationalNumberCheck")).andStubReturn(null); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_ADDRESS_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_CERTIFICATES_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_PHOTO_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockServletConfig.getInitParameter(IdentityDataMessageHandler.INCLUDE_DATA_FILES)) .andReturn(null); EasyMock.expect(mockServletRequest.getRemoteAddr()).andStubReturn("remote-address"); byte[] idFile = "foobar-id-file".getBytes(); IdentityDataMessage message = new IdentityDataMessage(); message.idFile = idFile; message.identitySignatureFile = "foobar-signature".getBytes(); message.rrnCertFile = certificate.getEncoded(); // prepare EasyMock.replay(mockServletConfig, mockHttpSession, mockServletRequest); // operate AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance); this.testedInstance.init(mockServletConfig); try { this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, mockHttpSession); fail(); } catch (ServletException e) { LOG.debug("expected exception: " + e.getMessage(), e); LOG.debug("exception type: " + e.getClass().getName()); // verify EasyMock.verify(mockServletConfig, mockHttpSession, mockServletRequest); assertNull(IdentityIntegrityTestService.getCertificate()); assertEquals("remote-address", AuditTestService.getAuditIntegrityRemoteAddress()); } }
From source file:test.unit.be.fedict.eid.applet.service.IdentityDataMessageHandlerTest.java
public void testHandleMessageInvalidIntegritySignature() throws Exception { // setup/*from w w w . j av a 2 s. co m*/ KeyPair keyPair = MiscTestUtils.generateKeyPair(); DateTime notBefore = new DateTime(); DateTime notAfter = notBefore.plusYears(1); X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(), "CN=TestNationalRegistration", notBefore, notAfter, null, keyPair.getPrivate(), true, 0, null, null); ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class); Map<String, String> httpHeaders = new HashMap<String, String>(); HttpSession mockHttpSession = EasyMock.createMock(HttpSession.class); HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class); EasyMock.expect(mockServletConfig.getInitParameter("IdentityIntegrityService")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("IdentityIntegrityServiceClass")) .andStubReturn(IdentityIntegrityTestService.class.getName()); EasyMock.expect(mockServletConfig.getInitParameter("AuditService")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("AuditServiceClass")) .andStubReturn(AuditTestService.class.getName()); EasyMock.expect(mockServletConfig.getInitParameter("SkipNationalNumberCheck")).andStubReturn(null); EasyMock.expect(mockServletRequest.getRemoteAddr()).andStubReturn("remote-address"); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_ADDRESS_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_CERTIFICATES_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_PHOTO_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockServletConfig.getInitParameter(IdentityDataMessageHandler.INCLUDE_DATA_FILES)) .andReturn(null); byte[] idFile = "foobar-id-file".getBytes(); IdentityDataMessage message = new IdentityDataMessage(); message.idFile = idFile; KeyPair intruderKeyPair = MiscTestUtils.generateKeyPair(); Signature signature = Signature.getInstance("SHA1withRSA"); signature.initSign(intruderKeyPair.getPrivate()); signature.update(idFile); byte[] idFileSignature = signature.sign(); message.identitySignatureFile = idFileSignature; message.rrnCertFile = certificate.getEncoded(); // prepare EasyMock.replay(mockServletConfig, mockHttpSession, mockServletRequest); // operate AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance); this.testedInstance.init(mockServletConfig); try { this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, mockHttpSession); fail(); } catch (ServletException e) { LOG.debug("expected exception: " + e.getMessage()); // verify EasyMock.verify(mockServletConfig, mockHttpSession, mockServletRequest); assertNull(IdentityIntegrityTestService.getCertificate()); assertEquals("remote-address", AuditTestService.getAuditIntegrityRemoteAddress()); } }
From source file:test.unit.be.fedict.eid.applet.service.IdentityDataMessageHandlerTest.java
public void testHandleMessageWithIntegrityCheck() throws Exception { // setup// w w w. j a va 2s .com KeyPair rootKeyPair = MiscTestUtils.generateKeyPair(); KeyPair rrnKeyPair = MiscTestUtils.generateKeyPair(); DateTime notBefore = new DateTime(); DateTime notAfter = notBefore.plusYears(1); X509Certificate rootCertificate = MiscTestUtils.generateCertificate(rootKeyPair.getPublic(), "CN=TestRootCA", notBefore, notAfter, null, rootKeyPair.getPrivate(), true, 0, null, null); X509Certificate rrnCertificate = MiscTestUtils.generateCertificate(rrnKeyPair.getPublic(), "CN=TestNationalRegistration", notBefore, notAfter, null, rootKeyPair.getPrivate(), false, 0, null, null); ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class); Map<String, String> httpHeaders = new HashMap<String, String>(); HttpSession mockHttpSession = EasyMock.createMock(HttpSession.class); HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class); EasyMock.expect(mockServletConfig.getInitParameter("IdentityIntegrityService")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("IdentityIntegrityServiceClass")) .andStubReturn(IdentityIntegrityTestService.class.getName()); EasyMock.expect(mockServletConfig.getInitParameter("AuditService")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("AuditServiceClass")).andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter("SkipNationalNumberCheck")).andStubReturn(null); EasyMock.expect(mockHttpSession.getAttribute("eid.identifier")).andStubReturn(null); mockHttpSession.setAttribute(EasyMock.eq("eid.identity"), EasyMock.isA(Identity.class)); EasyMock.expect(mockHttpSession.getAttribute("eid")).andStubReturn(null); mockHttpSession.setAttribute(EasyMock.eq("eid"), EasyMock.isA(EIdData.class)); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_ADDRESS_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_CERTIFICATES_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockHttpSession.getAttribute(RequestContext.INCLUDE_PHOTO_SESSION_ATTRIBUTE)) .andStubReturn(false); EasyMock.expect(mockServletConfig.getInitParameter(IdentityDataMessageHandler.INCLUDE_DATA_FILES)) .andReturn(null); byte[] idFile = "foobar-id-file".getBytes(); IdentityDataMessage message = new IdentityDataMessage(); message.idFile = idFile; Signature signature = Signature.getInstance("SHA1withRSA"); signature.initSign(rrnKeyPair.getPrivate()); signature.update(idFile); byte[] idFileSignature = signature.sign(); message.identitySignatureFile = idFileSignature; message.rrnCertFile = rrnCertificate.getEncoded(); message.rootCertFile = rootCertificate.getEncoded(); // prepare EasyMock.replay(mockServletConfig, mockHttpSession, mockServletRequest); // operate AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance); this.testedInstance.init(mockServletConfig); this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, mockHttpSession); // verify EasyMock.verify(mockServletConfig, mockHttpSession, mockServletRequest); assertEquals(rrnCertificate, IdentityIntegrityTestService.getCertificate()); }
From source file:org.etudes.jforum.EtudesJForumBaseServlet.java
public void init(ServletConfig config) throws ServletException { super.init(config); //initialize configurations try {/*from w ww. j a v a2 s. com*/ String appPath = config.getServletContext().getRealPath(""); debug = "true".equals(config.getInitParameter("development")); // Load system default values ConfigLoader.startSystemglobals(appPath); ConfigLoader.startCacheEngine(); // Configure the template engine Configuration templateCfg = new Configuration(); templateCfg.setDirectoryForTemplateLoading(new File(SystemGlobals.getApplicationPath() + "/templates")); templateCfg.setTemplateUpdateDelay(2); templateCfg.setSetting("number_format", "#"); ModulesRepository.init(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR)); SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_GENERIC)); SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_DRIVER)); // Start the dao.driver implementation DataAccessDriver daoImpl = null; String vendor = SqlService.getVendor(); if (vendor.equals("oracle")) { daoImpl = new OracleDataAccessDriver(); } else if (vendor.equals("mysql")) { daoImpl = new MysqlDataAccessDriver(); } else if (vendor.equals("hsqldb")) { daoImpl = new HsqldbDataAccessDriver(); } else { logger.error("Unable to find an appropriate DataAccessDriver for DB vendor " + vendor); } DataAccessDriver.init(daoImpl); this.loadConfigStuff(); if (!this.debug) { templateCfg.setTemplateUpdateDelay(3600); } ConfigLoader.listenForChanges(); ConfigLoader.startSearchIndexer(); Configuration.setDefaultConfiguration(templateCfg); } catch (Exception e) { throw new ForumStartupException("Error while starting jforum", e); } //create database tables boolean m_autoDdl = config.getInitParameter("autoddl").equals("true"); try { // if autoDdl is true create the tables if (m_autoDdl) { Connection conn = null; //Start database boolean isDatabaseUp = ForumStartup.startDatabase(); if (isDatabaseUp) { conn = DBConnection.getImplementation().getConnection(); //create tables and data only one time if (!createTablesAndData(conn)) if (logger.isDebugEnabled()) logger.debug(this.getClass().getName() + ".init() : JForum Table's and data already existing in the database"); else if (logger.isDebugEnabled()) logger.debug(this.getClass().getName() + ".init() : JForum Table's and data created in the database"); } //Finalize if (conn != null) { try { DBConnection.getImplementation().releaseConnection(conn); } catch (Exception e) { throw e; } } } //register sakai-JForum functions registerJForumFunctions(); } catch (Exception e) { logger.error(this.getClass().getName() + ".init() : " + e.toString(), e); } }
From source file:net.sf.qooxdoo.rpc.RpcServlet.java
/** * Initializes this servlet.//from ww w .j a va2 s . c o m * * @param config the servlet config. */ public void init(ServletConfig config) throws ServletException { super.init(config); _remoteCallUtils = getRemoteCallUtils(); String referrerCheckName = config.getInitParameter("referrerCheck"); if ("strict".equals(referrerCheckName)) { _referrerCheck = REFERRER_CHECK_STRICT; } else if ("domain".equals(referrerCheckName)) { _referrerCheck = REFERRER_CHECK_DOMAIN; } else if ("session".equals(referrerCheckName)) { _referrerCheck = REFERRER_CHECK_SESSION; } else if ("public".equals(referrerCheckName)) { _referrerCheck = REFERRER_CHECK_PUBLIC; } else if ("fail".equals(referrerCheckName)) { _referrerCheck = REFERRER_CHECK_FAIL; } else { _referrerCheck = REFERRER_CHECK_STRICT; log("No referrer checking configuration found. Using strict checking as the default."); } }
From source file:org.ejbca.ui.web.pub.HealthCheckServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); // Install BouncyCastle provider CryptoProviderTools.installBCProviderIfNotAvailable(); authIPs = EjbcaConfiguration.getHealthCheckAuthorizedIps().split(";"); if (ArrayUtils.contains(authIPs, "ANY")) { log.info(intres.getLocalizedMessage("healthcheck.allipsauthorized")); anyIpAuthorized = true;/*from ww w . ja v a 2 s. c o m*/ } if (config.getInitParameter("CheckPublishers") != null) { log.warn( "CheckPublishers servlet parameter has been dropped. Use \"healthcheck.publisherconnections\" property instead."); } initMaintenanceFile(); }