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); }
upAuthConfig.setUserGroupServiceName(userGroupService.getName()); saveAuthenticationProvider(upAuthConfig); authProvider = loadAuthenticationProvider(GeoServerAuthenticationProvider.DEFAULT_NAME);
@Override public void doSave(T config) throws Exception { getSecurityManager().saveAuthenticationProvider(config); }
@Override public void doSave(T config) throws Exception { getSecurityManager().saveAuthenticationProvider(config); }
@Override public void doSave(T config) throws Exception { getSecurityManager().saveAuthenticationProvider(config); }
private void ensureProviderConfigFile() { if (securityManager == null) { LOGGER.severe("securityManager is null!"); return; } try { SecurityAuthProviderConfig loadedConfig = securityManager.loadAuthenticationProviderConfig("geofence"); if (loadedConfig == null) { LOGGER.warning("Configuration file not found, creating default config"); // config: create a default one GeoFenceAuthenticationProviderConfig defaultConfig = new GeoFenceAuthenticationProviderConfig(); defaultConfig.setName("geofence"); defaultConfig.setClassName(GeoFenceAuthenticationProvider.class.getName()); securityManager.saveAuthenticationProvider(defaultConfig); } } catch (Exception ex) { LOGGER.severe("Error in configuration: " + ex.getMessage()); } } }
private void ensureProviderConfigFile() { if (securityManager == null) { LOGGER.severe("securityManager is null!"); return; } try { SecurityAuthProviderConfig loadedConfig = securityManager.loadAuthenticationProviderConfig("geofence"); if (loadedConfig == null) { LOGGER.warning("Configuration file not found, creating default config"); // config: create a default one GeoFenceAuthenticationProviderConfig defaultConfig = new GeoFenceAuthenticationProviderConfig(); defaultConfig.setName("geofence"); defaultConfig.setClassName(GeoFenceAuthenticationProvider.class.getName()); securityManager.saveAuthenticationProvider(defaultConfig); } } catch (Exception ex) { LOGGER.severe("Error in configuration: " + ex.getMessage()); } } }
@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()); }
public void testAuthentificationWithoutUserGroupService() throws Exception { JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc1", null); getSecurityManager().saveAuthenticationProvider(config); GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc1"); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("sa",""); token.setDetails("details"); assertTrue(provider.supports(token.getClass())); assertFalse(provider.supports(RememberMeAuthenticationToken.class)); Authentication auth = provider.authenticate(token); assertNotNull(auth); assertEquals("sa", auth.getPrincipal()); assertNull(auth.getCredentials()); assertEquals("details", auth.getDetails()); assertEquals(1,auth.getAuthorities().size()); checkForAuthenticatedRole(auth); token = new UsernamePasswordAuthenticationToken("abc","def"); boolean fail = false; try { if (provider.authenticate(token)==null) fail = true; } catch (BadCredentialsException ex) { fail=true; } assertTrue(fail); }
@Test public void testAuthentificationWithoutUserGroupService() throws Exception { JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc1", null); getSecurityManager().saveAuthenticationProvider(config); GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc1"); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("sa", ""); token.setDetails("details"); assertTrue(provider.supports(token.getClass())); assertTrue(!provider.supports(RememberMeAuthenticationToken.class)); Authentication auth = provider.authenticate(token); assertNotNull(auth); assertEquals("sa", auth.getPrincipal()); assertNull(auth.getCredentials()); assertEquals("details", auth.getDetails()); assertEquals(1, auth.getAuthorities().size()); checkForAuthenticatedRole(auth); token = new UsernamePasswordAuthenticationToken("abc", "def"); boolean fail = false; try { if (provider.authenticate(token) == null) fail = true; } catch (BadCredentialsException ex) { fail = true; } assertTrue(fail); }
public void testAuthentificationWithRoleAssociation() throws Exception { GeoServerRoleService roleService = createRoleService("jdbc2"); JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc2", null); getSecurityManager().saveAuthenticationProvider(config); GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc2");
try { config.setDriverClassName(""); getSecurityManager().saveAuthenticationProvider(config); } catch (SecurityConfigException ex) { assertEquals( DRIVER_CLASSNAME_REQUIRED,ex.getId()); fail=false; try { getSecurityManager().saveAuthenticationProvider(config); } catch (SecurityConfigException ex) { assertEquals( DRIVER_CLASS_NOT_FOUND_$1,ex.getId()); try { config.setConnectURL(null); getSecurityManager().saveAuthenticationProvider(config); } catch (SecurityConfigException ex) { assertEquals( JDBCURL_REQUIRED,ex.getId());
GeoServerRoleService roleService = createRoleService("jdbc3"); JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc3", null); getSecurityManager().saveAuthenticationProvider(config); GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc3");
GeoServerUserGroupService ugService = createUserGroupService("jdbc2"); JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc2", ugService.getName()); getSecurityManager().saveAuthenticationProvider(config); GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc2");
GeoServerUserGroupService ugService = createUserGroupService("jdbc2"); JDBCConnectAuthProviderConfig config = createAuthConfg("jdbc2", ugService.getName()); getSecurityManager().saveAuthenticationProvider(config); GeoServerAuthenticationProvider provider = getSecurityManager().loadAuthenticationProvider("jdbc2");