/** * Gets the application context. * * @param id * the id * @return the application context */ public ApplicationContext getApplicationContext(String id) { ChildApplicationContextFactory child = this.childApplicationContexts.get(id); return child == null ? null : child.getApplicationContext(); }
public String getProperty(String name) { String value = subsystem.getProperty(name); if (value == null) { value = globalProperties.getProperty(name); if (value == null) { name = alias(name, JOD_CONVERTER, OPEN_OFFICE); value = globalProperties.getProperty(name); } } return value; }
public Set<String> getPropertyNames() { Set<String> propertyNames = new HashSet<String>(subsystem.getPropertyNames()); for (String name: globalProperties.stringPropertyNames()) { if (name.startsWith(TransformerConfig.PREFIX)) { name = alias(name, OPEN_OFFICE, JOD_CONVERTER); if (!propertyNames.contains(name)) { propertyNames.add(name); } } } return propertyNames; }
private String[] getContextResourcePatterns() { return new String[] { ChildApplicationContextFactory.CLASSPATH_PREFIX + getCategory() + '/' + getTypeName() + ChildApplicationContextFactory.CONTEXT_SUFFIX, ChildApplicationContextFactory.CLASSPATH_PREFIX + getCategory() + '/' + getTypeName() + ChildApplicationContextFactory.ENTERPRISE_CONTEXT_SUFFIX, ChildApplicationContextFactory.EXTENSION_CLASSPATH_PREFIX + getCategory() + '/' + getTypeName() + '/' + ChildApplicationContextFactory.this.getId().get( ChildApplicationContextFactory.this.getId().size() - 1) + ChildApplicationContextFactory.CONTEXT_SUFFIX }; }
throws IOException setApplicationContext(parent); setRegistry(registry); setPropertyDefaults(propertyDefaults); setEncryptedPropertyDefaults(encryptedPropertyDefaults); setCategory(category); setTypeName(typeName); setInstancePath(instancePath); afterPropertiesSet();
public void stop() { if (this.applicationContext != null) { ChildApplicationContextFactory.logger .info("Stopping '" + getCategory() + "' subsystem, ID: " + getId()); try { this.applicationContext.close(); } catch (Exception e) { ChildApplicationContextFactory.logger.error(e); // Continue anyway. Perhaps it didn't start properly } this.applicationContext = null; ChildApplicationContextFactory.logger.info("Stopped '" + getCategory() + "' subsystem, ID: " + getId()); } }
public void testUnproxiedHeader() throws Exception { // Clear the proxy user name childApplicationContextFactory.stop(); childApplicationContextFactory.setProperty("external.authentication.proxyUserName", ""); // Mock a request with a username in the header HttpServletRequest mockRequest = mock(HttpServletRequest.class); when(mockRequest.getHeader("X-Alfresco-Remote-User")).thenReturn("AdMiN"); assertEquals("admin", ((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( "remoteUserMapper")).getRemoteUser(mockRequest)); // Mock an unauthenticated request when(mockRequest.getHeader("X-Alfresco-Remote-User")).thenReturn(null); assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( "remoteUserMapper")).getRemoteUser(mockRequest)); // Mock a remote user request when(mockRequest.getRemoteUser()).thenReturn("ADMIN"); assertEquals("admin", ((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( "remoteUserMapper")).getRemoteUser(mockRequest)); }
/** * Instantiates a new application context state. * * @throws IOException * Signals that an I/O exception has occurred. */ protected ApplicationContextState(boolean allowInitAccess ) throws IOException { this.allowInitAccess = allowInitAccess; // Load the property defaults PropertiesFactoryBean factory = new PropertiesFactoryBean(); factory.setPropertiesPersister(getPersister()); factory.setLocations(getParent().getResources( ChildApplicationContextFactory.CLASSPATH_PREFIX + getCategory() + '/' + getTypeName() + ChildApplicationContextFactory.PROPERTIES_SUFFIX)); factory.afterPropertiesSet(); this.properties = (Properties) factory.getObject(); }
@Override public void afterPropertiesSet() throws Exception { List<String> idList = getInstancePath(); if (idList.isEmpty()) { throw new IllegalStateException("Invalid instance path"); } if (getTypeName() == null) { setTypeName(idList.get(0)); } super.afterPropertiesSet(); // Validate that context files exist for this path if (new ResourceFinder(getParent()).getResources(getContextResourcePatterns()).length == 0) { throw new IllegalStateException("Invalid type " + getTypeName() + " specified for "+ getCategory() + " subsystem. No context file found"); } }
String groupName = sysAdminSubsystem.getProperty(sitePublicGroupPropName); assertEquals(sitePublicGroupPropName + " was not the pristine value", originalSitePublicGroup, groupName); String prefixedNewGroupName = PermissionService.GROUP_PREFIX + newGroupName; sysAdminSubsystem.stop(); sysAdminSubsystem.setProperty(sitePublicGroupPropName, prefixedNewGroupName); sysAdminSubsystem.start(); sysAdminSubsystem.stop(); sysAdminSubsystem.setProperty(sitePublicGroupPropName, originalSitePublicGroup); sysAdminSubsystem.start();
childPath.addAll(getInstancePath()); childPath.add(name); childPath.add(id); child = new CompositeDataBean(getParent(), ChildApplicationContextFactory.this, getRegistry(), getPropertyDefaults(), getCategory(), type, childPath);
@AfterClass public static void stopOOoSubsystems() throws Exception { // Put the OOoJodconverter subsystem back to its install settings (disabled). if (log.isDebugEnabled()) { log.debug("Disabling OOoJodconverter"); } oooJodcSubsystem.stop(); oooJodcSubsystem.setProperty("jodconverter.enabled", "false"); oooJodcSubsystem.start(); oooJodcSubsystem.stop(); } }
if (factory != null && !factory.getTypeName().equals(typeName)) factory.destroy(true); childId.add("managed"); childId.add(id); this.childApplicationContexts.put(id, new ChildApplicationContextFactory(getParent(), getRegistry(), getPropertyDefaults(), getEncryptedPropertyDefaults(), getCategory(), typeName, childId)); try factory.destroy(true);
/** * Mock up the responses from the subsystem so that it returns all the supplied * property names and values. * @param subsystem to mock the return values * @param namesAndValues a sequence of property names and values. * @throws IllegalStateException if there is not a value for every property */ public static void mockProperties(ChildApplicationContextFactory subsystem, String... namesAndValues) { if (namesAndValues.length % 2 != 0) { // Not using IllegalArgumentException as this is thrown by classes under test throw new java.lang.IllegalStateException("There should be a value for every property"); } final Set<String> propertyNames = new TreeSet<String>(); for (int i=0; i < namesAndValues.length; i+=2) { propertyNames.add(namesAndValues[i]); when(subsystem.getProperty(namesAndValues[i])).thenReturn(namesAndValues[i+1]); } when(subsystem.getPropertyNames()).thenReturn(propertyNames); }
@Test public void testAbstractPropertyBackedBean_performEarlyPropertyChecks_CustomEarlyPropertyChecker() ChildApplicationContextFactory testBean = new ChildApplicationContextFactory(); earlyPropertyCheckersMap.put("test2.property", testEarlyPropertyChecker); testBean.setEarlyPropertyCheckers(earlyPropertyCheckersMap); String errorMessage = testBean.performEarlyPropertyChecks(testProperties); testProperties.put("test3.property", "Test property value"); errorMessage = testBean.performEarlyPropertyChecks(testProperties); assertTrue(errorMessage.contains("No 'bad value's allowed!"));
prop.put(ChildApplicationContextFactory.INSTANCE_PATH_PROPERTY, getInstancePath().toString()); .info("Starting '" + getCategory() + "' subsystem, ID: " + getId()); ClassPathXmlApplicationContext applicationContext = ChildApplicationContextFactory.this.new ChildApplicationContext( prop, this.compositeProperties); ChildApplicationContextFactory.logger.info("Startup of '" + getCategory() + "' subsystem, ID: " + getId() + " complete"); ChildApplicationContextFactory.logger.warn("Startup of '" + getCategory() + "' subsystem, ID: " + getId() + " failed", e); this.lastStartupError = e; throw e;
public void testWrongPublicKey() throws Exception { // generate and apply an incorrect public key childApplicationContextFactory.stop(); applyHardcodedPublicKey(KeyPairGenerator.getInstance("RSA").generateKeyPair().getPublic()); // create token String jwt = generateToken(false); // create mock request object HttpServletRequest mockRequest = createMockTokenRequest(jwt); // ensure null is returned if the public key is wrong assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( REMOTE_USER_MAPPER_BEAN_NAME)).getRemoteUser(mockRequest)); }
public void removeProperties(Collection<String> propertyNames) { subsystem.removeProperties(propertyNames); } }
public void setProperties(Map<String, String> map) { subsystem.setProperties(map); }
protected void destroy(boolean isPermanent) { super.destroy(isPermanent); doInit(); }