/** * 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(); }
/** * 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(); }
/** * This method is currently used to skip certain tests if LibreOffice/OpenOffice is not available (eg. on build machines). * * @return * @throws InterruptedException */ protected boolean isOpenOfficeWorkerAvailable() throws InterruptedException { ChildApplicationContextFactory jodconverterSubsystem = (ChildApplicationContextFactory) ctx.getBean("OOoJodconverter"); JodContentTransformer jodContentTransformer = (JodContentTransformer)jodconverterSubsystem.getApplicationContext().getBean("transformer.worker.JodConverter"); return jodContentTransformer.isAvailable(); } }
/** * Finds the keycloak deployment bean and applies a hardcoded public key locator using the * provided public key. */ private void applyHardcodedPublicKey(PublicKey publicKey) { KeycloakDeployment deployment = (KeycloakDeployment)childApplicationContextFactory.getApplicationContext(). getBean(DEPLOYMENT_BEAN_NAME); HardcodedPublicKeyLocator publicKeyLocator = new HardcodedPublicKeyLocator(publicKey); deployment.setPublicKeyLocator(publicKeyLocator); } }
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)); }
public void testInvalidJwt() throws Exception { // create mock request object HttpServletRequest mockRequest = createMockTokenRequest("thisisnotaJWT"); // ensure null is returned if the JWT is invalid assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( REMOTE_USER_MAPPER_BEAN_NAME)).getRemoteUser(mockRequest)); }
@Override protected void setUp() throws Exception { // switch authentication to use token auth childApplicationContextManager = (DefaultChildApplicationContextManager) ctx.getBean("Authentication"); childApplicationContextManager.stop(); childApplicationContextManager.setProperty("chain", "identity-service1:identity-service"); childApplicationContextFactory = getChildApplicationContextFactory(childApplicationContextManager, "identity-service1"); // generate keys for test this.keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair(); // hardcode the realm public key in the deployment bean to stop it fetching keys applyHardcodedPublicKey(this.keyPair.getPublic()); // extract config this.identityServiceConfig = (IdentityServiceConfig)childApplicationContextFactory. getApplicationContext().getBean(CONFIG_BEAN_NAME); }
@Before @Override public void setUp() throws Exception { ChildApplicationContextFactory emailSubsystem = (ChildApplicationContextFactory) ctx.getBean("InboundSMTP"); assertNotNull("emailSubsystem", emailSubsystem); ApplicationContext emailCtx = emailSubsystem.getApplicationContext(); emailServer = (EmailServer) emailCtx.getBean("emailServer"); emailService = (EmailService)emailCtx.getBean("emailService"); assertNotNull("emailService", emailService); // MNT-14417 shutdownServer(); }
public void testProxiedHeader() throws Exception { // Set the proxy user name childApplicationContextFactory.stop(); childApplicationContextFactory.setProperty("external.authentication.proxyUserName", "bob"); // Mock a request with both a user and a header HttpServletRequest mockRequest = mock(HttpServletRequest.class); when(mockRequest.getScheme()).thenReturn("http"); when(mockRequest.getRemoteUser()).thenReturn("bob"); when(mockRequest.getHeader("X-Alfresco-Remote-User")).thenReturn("AdMiN"); assertEquals("admin", ((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( "remoteUserMapper")).getRemoteUser(mockRequest)); // Now try header pattern matching childApplicationContextFactory.stop(); childApplicationContextFactory.setProperty("external.authentication.userIdPattern", "abc-(.*)-999"); when(mockRequest.getHeader("X-Alfresco-Remote-User")).thenReturn("abc-AdMiN-999"); assertEquals("admin", ((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( "remoteUserMapper")).getRemoteUser(mockRequest)); // Try a request with an invalid match when(mockRequest.getHeader("X-Alfresco-Remote-User")).thenReturn("abc-AdMiN-998"); assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( "remoteUserMapper")).getRemoteUser(mockRequest)); // Try a request without the remote user when(mockRequest.getRemoteUser()).thenReturn(null); assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( "remoteUserMapper")).getRemoteUser(mockRequest)); }
public void testMissingToken() throws Exception { // create mock request object HttpServletRequest mockRequest = createMockTokenRequest(""); // ensure null is returned if the token is missing assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( REMOTE_USER_MAPPER_BEAN_NAME)).getRemoteUser(mockRequest)); }
public void testMissingHeader() throws Exception { // create mock request object with no Authorization header HttpServletRequest mockRequest = createMockTokenRequest(null); // ensure null is returned if the header was missing assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( REMOTE_USER_MAPPER_BEAN_NAME)).getRemoteUser(mockRequest)); }
ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext(); postLookup = (PostLookup) activitiesFeedCtx.getBean("postLookup"); feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
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 testExpiredToken() throws Exception { // create token String jwt = generateToken(true); // create mock request object HttpServletRequest mockRequest = createMockTokenRequest(jwt); // ensure null is returned if the token has expired assertNull(((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( REMOTE_USER_MAPPER_BEAN_NAME)).getRemoteUser(mockRequest)); }
public void testValidToken() throws Exception { // create token String jwt = generateToken(false); // create mock request object HttpServletRequest mockRequest = createMockTokenRequest(jwt); // validate correct user was found assertEquals(TEST_USER_USERNAME, ((RemoteUserMapper) childApplicationContextFactory.getApplicationContext().getBean( REMOTE_USER_MAPPER_BEAN_NAME)).getRemoteUser(mockRequest)); }
@Override protected void setUp() throws Exception { applicationContext = ApplicationContextHelper.getApplicationContext(); nodeService = (NodeService)applicationContext.getBean("nodeService"); repositoryHelper = (Repository)this.applicationContext.getBean("repositoryHelper"); transactionService = (TransactionService)applicationContext.getBean("transactionService"); ChildApplicationContextFactory fileServersSubSystem = (ChildApplicationContextFactory) applicationContext.getBean("fileServers"); assertNotNull("fileServers subsystem is null", fileServersSubSystem); lockKeeper = (LockKeeper)fileServersSubSystem.getApplicationContext().getBean("lockKeeper"); assertNotNull("nodeService is null", nodeService); assertNotNull("lockKeeper is null", lockKeeper); assertNotNull("transactionService is null", transactionService); AuthenticationUtil.setRunAsUserSystem(); AuthenticationUtil.setFullyAuthenticatedUser("bugsBunny"); }
public void testWrongPublicKeyWithError() throws Exception { // generate and apply an incorrect public key childApplicationContextFactory.stop(); childApplicationContextFactory.setProperty(CONFIG_SILENT_ERRORS, "false"); applyHardcodedPublicKey(KeyPairGenerator.getInstance("RSA").generateKeyPair().getPublic()); // create token String jwt = generateToken(false); // create mock request object HttpServletRequest mockRequest = createMockTokenRequest(jwt); // ensure user mapper falls through instead of throwing an exception String user = ((RemoteUserMapper)childApplicationContextFactory.getApplicationContext().getBean( REMOTE_USER_MAPPER_BEAN_NAME)).getRemoteUser(mockRequest); assertEquals("Returned user should be null when wrong public key is used.", null, user); }
@Override public void setUp() throws Exception { AuthenticationUtil.setRunAsUserSystem(); nodeService = (NodeService)ctx.getBean("NodeService"); assertNotNull("nodeService", nodeService); authorityService = (AuthorityService)ctx.getBean("AuthorityService"); assertNotNull("authorityService", authorityService); ChildApplicationContextFactory emailSubsystem = (ChildApplicationContextFactory) ctx.getBean("InboundSMTP"); assertNotNull("emailSubsystem", emailSubsystem); ApplicationContext emailCtx = emailSubsystem.getApplicationContext(); emailService = (EmailService)emailCtx.getBean("emailService"); assertNotNull("emailService", emailService); personService = (PersonService)emailCtx.getBean("PersonService"); assertNotNull("personService", personService); namespaceService = (NamespaceService)emailCtx.getBean("NamespaceService"); assertNotNull("namespaceService", namespaceService); searchService = (SearchService)emailCtx.getBean("SearchService"); assertNotNull("searchService", searchService); folderEmailMessageHandler = (FolderEmailMessageHandler) emailCtx.getBean("folderEmailMessageHandler"); assertNotNull("folderEmailMessageHandler", folderEmailMessageHandler); transactionHelper = (RetryingTransactionHelper) emailCtx.getBean("retryingTransactionHelper"); assertNotNull("transactionHelper", transactionHelper); }
@Before public void before() { childApplicationContextManager = (DefaultChildApplicationContextManager) ctx.getBean("Authentication"); personService = (PersonService) ctx.getBean("PersonService"); childApplicationContextManager.stop(); childApplicationContextManager.setProperty("chain", "external1:external"); ChildApplicationContextFactory childApplicationContextFactory = childApplicationContextManager.getChildApplicationContextFactory("external1"); // Clear the proxy user name childApplicationContextFactory.stop(); childApplicationContextFactory.setProperty("external.authentication.proxyUserName", ""); localAuthenticationService = (AuthenticationService) childApplicationContextFactory.getApplicationContext() .getBean("localAuthenticationService"); AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); }
public void testExpiredTokenWithError() throws Exception { // turn on validation failure reporting childApplicationContextFactory.stop(); childApplicationContextFactory.setProperty(CONFIG_SILENT_ERRORS, "false"); applyHardcodedPublicKey(this.keyPair.getPublic()); // create token String jwt = generateToken(true); // create mock request object HttpServletRequest mockRequest = createMockTokenRequest(jwt); // ensure an exception is thrown with correct description String user = ((RemoteUserMapper)childApplicationContextFactory.getApplicationContext().getBean( REMOTE_USER_MAPPER_BEAN_NAME)).getRemoteUser(mockRequest); assertEquals("Returned user should be null when the token is expired.", null, user); }