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); }
public UsernamePasswordAuthenticationProviderConfig( UsernamePasswordAuthenticationProviderConfig other) { super(other); userGroupServiceName = other.getUserGroupServiceName(); }
@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()); }
protected SecurityAuthProviderConfig createAuthConfig( String name, Class<?> aClass, String userGroupServiceName) { SecurityAuthProviderConfig config = new UsernamePasswordAuthenticationProviderConfig(); config.setName(name); config.setClassName(aClass.getName()); config.setUserGroupServiceName(userGroupServiceName); /*SecurityAuthProviderConfig config = createNiceMock(SecurityAuthProviderConfig.class); expect(config.getName()).andReturn(name).anyTimes(); expect(config.getClassName()).andReturn(aClass.getName()).anyTimes(); expect(config.getUserGroupServiceName()).andReturn(userGroupServiceName).anyTimes(); replay(config);*/ return config; }
if (authProvider == null) { UsernamePasswordAuthenticationProviderConfig upAuthConfig = new UsernamePasswordAuthenticationProviderConfig(); upAuthConfig.setName(GeoServerAuthenticationProvider.DEFAULT_NAME); upAuthConfig.setClassName(UsernamePasswordAuthenticationProvider.class.getName()); upAuthConfig.setUserGroupServiceName(userGroupService.getName());
@Override public void initializeFromConfig(SecurityNamedServiceConfig config) throws IOException { UsernamePasswordAuthenticationProviderConfig upAuthConfig = (UsernamePasswordAuthenticationProviderConfig) config; GeoServerUserGroupService ugService = getSecurityManager().loadUserGroupService(upAuthConfig.getUserGroupServiceName()); if (ugService == null) { throw new IllegalArgumentException( "Unable to load user group service " + upAuthConfig.getUserGroupServiceName()); } userGroupServiceName = upAuthConfig.getUserGroupServiceName(); // create delegate auth provider authProvider = new DaoAuthenticationProvider(); authProvider.setUserDetailsService(ugService); // set up the password encoder // multiplex password encoder actually allows us to handle all types of passwords for // decoding purposes, regardless of whatever the current one used by the user group service // is authProvider.setPasswordEncoder( new GeoServerMultiplexingPasswordEncoder(getSecurityManager(), ugService)); try { authProvider.afterPropertiesSet(); } catch (Exception e) { throw new IOException(e); } }