public GeoServerAuthenticationProvider createAuthProvider( String name, String userGroupServiceName) throws Exception { UsernamePasswordAuthenticationProviderConfig config = new UsernamePasswordAuthenticationProviderConfig(); config.setClassName(UsernamePasswordAuthenticationProvider.class.getName()); config.setUserGroupServiceName(userGroupServiceName); config.setName(name); getSecurityManager().saveAuthenticationProvider(config); return getSecurityManager().loadAuthenticationProvider(name); }
UsernamePasswordAuthenticationProviderConfig upAuthConfig = new UsernamePasswordAuthenticationProviderConfig(); upAuthConfig.setName(GeoServerAuthenticationProvider.DEFAULT_NAME); upAuthConfig.setClassName(UsernamePasswordAuthenticationProvider.class.getName()); upAuthConfig.setUserGroupServiceName(userGroupService.getName());
@Test public void testActive() throws Exception { GeoServerSecurityManager secMgr = getSecurityManager(); UsernamePasswordAuthenticationProviderConfig config = new UsernamePasswordAuthenticationProviderConfig(); config.setName("custom"); config.setClassName(AuthProvider.class.getName()); secMgr.saveAuthenticationProvider(config); SecurityManagerConfig mgrConfig = secMgr.getSecurityConfig(); mgrConfig.getAuthProviderNames().add("custom"); mgrConfig.setConfigPasswordEncrypterName(getPlainTextPasswordEncoder().getName()); secMgr.saveSecurityConfig(mgrConfig); Authentication auth = new UsernamePasswordAuthenticationToken("foo", "bar"); auth = getSecurityManager().authenticationManager().authenticate(auth); assertTrue(auth.isAuthenticated()); }