IOServiceSecuritySetup { @PostConstruct public void setup() { final AuthenticationService nonHTTPAuthenticationManager; if (authenticationManagers.isUnsatisfied()) { final String authType = System.getProperty("org.uberfire.io.auth", null); final String domain = System.getProperty(AUTH_DOMAIN_KEY, JAASAuthenticationService.DEFAULT_DOMAIN); if (authType == null || authType.toLowerCase().equals("jaas") || authType.toLowerCase().equals("container")) { nonHTTPAuthenticationManager = new JAASAuthenticationService(domain); } else { nonHTTPAuthenticationManager = loadClazz(authType, AuthenticationService.class); } } else { nonHTTPAuthenticationManager = authenticationManagers.get(); } for (final FileSystemProvider fp : FileSystemProviders.installedProviders()) { if (fp instanceof SecuredFileSystemProvider) { SecuredFileSystemProvider sfp = (SecuredFileSystemProvider) fp; sfp.setJAASAuthenticator(nonHTTPAuthenticationManager); sfp.setHTTPAuthenticator(httpAuthManager); sfp.setAuthorizer((fs, fileSystemUser) -> authorizationManager.authorize( new FileSystemResourceAdaptor(new FileSystemMetadata(fs)), fileSystemUser) ); sfp.setSSHAuthenticator((userName, key) -> sshKeyAuthenticator.authenticate(userName, key)); } } }  @PostConstruct void setup(); static final String AUTH_DOMAIN_KEY; }
@Test public void testSystemPropertyAuthConfig() throws Exception { when(authenticationManagers.isUnsatisfied()).thenReturn(true); setupBean.setup(); MockSecuredFilesystemProvider mockFsp = MockSecuredFilesystemProvider.LATEST_INSTANCE; assertNotNull(mockFsp.authenticator); assertNotNull(mockFsp.authorizer); User user = mockFsp.authenticator.login("fake", "fake"); assertEquals(MockAuthenticationService.FAKE_USER.getIdentifier(), user.getIdentifier()); final FileSystem mockfs = mock(FileSystem.class); final FileSystem mockedFSId = mock(FileSystem.class, withSettings().extraInterfaces(FileSystemId.class)); when(((FileSystemId) mockedFSId).id()).thenReturn("mockFS"); final Path rootPath = mock(Path.class); when(rootPath.toUri()).thenReturn(URI.create("/")); when(mockfs.getRootDirectories()).thenReturn(Arrays.asList(rootPath)); when(mockedFSId.getRootDirectories()).thenReturn(Arrays.asList(rootPath)); when(rootPath.getFileSystem()).thenReturn(mockedFSId); assertTrue(mockFsp.authorizer.authorize(mockfs, user)); }
@Test public void testCustomAuthenticatorBean() throws Exception { when(authenticationManagers.isUnsatisfied()).thenReturn(false); AuthenticationService mockAuthenticationService = mock(AuthenticationService.class); when(authenticationManagers.get()).thenReturn(mockAuthenticationService); setupBean.setup(); AuthenticationService authenticator = MockSecuredFilesystemProvider.LATEST_INSTANCE.authenticator; authenticator.login("fake", "fake"); verify(mockAuthenticationService).login("fake", "fake"); }
@Test public void testCustomAuthorizerBean() throws Exception { when(authenticationManagers.isUnsatisfied()).thenReturn(true); setupBean.setup(); FileSystemAuthorizer installedAuthorizer = MockSecuredFilesystemProvider.LATEST_INSTANCE.authorizer; AuthenticationService installedAuthenticator = MockSecuredFilesystemProvider.LATEST_INSTANCE.authenticator; FileSystem mockfs = mock(FileSystem.class); final FileSystem mockedFSId = mock(FileSystem.class, withSettings().extraInterfaces(FileSystemId.class)); final Path rootPath = mock(Path.class); when(rootPath.toUri()).thenReturn(URI.create("/")); when(mockfs.getRootDirectories()).thenReturn(Arrays.asList(rootPath)); when(mockedFSId.getRootDirectories()).thenReturn(Arrays.asList(rootPath)); when(rootPath.getFileSystem()).thenReturn(mockedFSId); User fileSystemUser = installedAuthenticator.login("fake", "fake"); installedAuthorizer.authorize(mockfs, fileSystemUser); verify(authorizationManager).authorize(any(FileSystemResourceAdaptor.class), any(User.class)); }