private static Map<String, String> createAuthorizationAttributeMap( String snaaName, Properties props) { Map<String, String> attributes = new HashMap<String, String>(); List<String> keys = new LinkedList<String>(); // getting keys from properties for (Object o : props.keySet()) { if (((String) o).startsWith(snaaName + authorizationAtt) && ((String) o).endsWith(authorizationKeyAtt)) { keys.add((String) o); } } for (String k : keys) { String key = props.getProperty(k); // getting plain key-number from properties String plainKeyProperty = k.replaceAll(snaaName + authorizationAtt + ".", ""); plainKeyProperty = plainKeyProperty.replaceAll(authorizationKeyAtt, ""); String keyPrefix = snaaName + authorizationAtt + "." + plainKeyProperty; // building value-property-string String value = props.getProperty(keyPrefix + authorizationValAtt); // finally put key and values attributes.put(key, value); } return attributes; }
private static AuthorizationDataSource getAuthorizationDataSource( String snaaName, Properties props) throws ClassNotFoundException, IllegalAccessException, InstantiationException { for (Object o : props.keySet()) { String dataSourceName = snaaName + authorizationAtt + authorizationDataSource; if (o.equals(dataSourceName)) { AuthorizationDataSource dataSource = (AuthorizationDataSource) Class.forName(props.getProperty((String) o)).newInstance(); String dataSourceUsername = props.getProperty(dataSourceName + authorizationDataSourceUsername); String dataSourcePassword = props.getProperty(dataSourceName + authorizationDataSourcePassword); String dataSourceUrl = props.getProperty(dataSourceName + authorizationDataSourceUrl); if (dataSourceUsername != null) { dataSource.setUsername(dataSourceUsername); } if (dataSourcePassword != null) { dataSource.setPassword(dataSourcePassword); } if (dataSourceUrl != null) { dataSource.setUrl(dataSourceUrl); } return dataSource; } } // set default return new ShibbolethDataSource(); }
private static ShibbolethProxy setOptionalShibbolethProxy(Properties props) { String shibbolethProxyHost = props.getProperty("config.shibboleth.proxyHost"); String shibbolethProxyPort = props.getProperty("config.shibboleth.proxyPort"); if (shibbolethProxyHost != null && shibbolethProxyPort != null) { return new ShibbolethProxy(shibbolethProxyHost, Integer.parseInt(shibbolethProxyPort)); } return null; }
public static HttpServer startFromProperties(Properties props) throws Exception { org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG); int port = Integer.parseInt(props.getProperty("config.port", "8080")); startHttpServer(port); Set<String> snaaNames = parseCSV(props.getProperty("config.snaas", "")); // set optional proxy for shibboleth ShibbolethProxy shibbolethProxy; shibbolethProxy = setOptionalShibbolethProxy(props); String type, urnprefix, path; for (String snaaName : snaaNames) { type = props.getProperty(snaaName + ".type", ""); path = props.getProperty(snaaName + ".path", "/snaa/" + snaaName); if ("dummy".equals(type)) { urnprefix = props.getProperty(snaaName + ".urnprefix", "urn:default:" + snaaName); startDummySNAA(path, urnprefix); } else if ("shibboleth".equals(type)) { urnprefix = props.getProperty(snaaName + ".urnprefix", "urn:default:" + snaaName); String authorizationClassName = props.getProperty( snaaName + ".authorization_class", "eu.wisebed.testbed.api.snaa.authorization.AlwaysAllowAuthorization"); IUserAuthorization authorization = getAuthorizationModule(authorizationClassName); if (authorizationClassName.endsWith(".AttributeBasedAuthorization")) { createAndSetAuthenticationAttributes(snaaName, props, authorization); } String secretAuthkeyUrl = props.getProperty(snaaName + ".authorization.url"); startShibbolethSNAA( path, urnprefix, secretAuthkeyUrl, authorization, shibbolethInjector, shibbolethProxy); } else if ("jaas".equals(type)) { urnprefix = props.getProperty(snaaName + ".urnprefix", "urn:default:" + snaaName); String jaasModuleName = props.getProperty(snaaName + ".module", null); String jaasConfigFile = props.getProperty(snaaName + ".configfile", null); String authorizationClassName = props.getProperty( snaaName + ".authorization_class", "eu.wisebed.testbed.api.snaa.authorization.AlwaysAllowAuthorization"); IUserAuthorization authorization = getAuthorizationModule(authorizationClassName); if (authorizationClassName.endsWith(".AttributeBasedAuthorization")) { createAndSetAuthenticationAttributes(snaaName, props, authorization); } if (jaasConfigFile == null) { throw new Exception(("Supply a value for " + snaaName + ".configfile")); } if (jaasModuleName == null) { throw new Exception(("Supply a value for " + snaaName + ".module")); } startJAASSNAA( path, urnprefix, jaasModuleName, jaasConfigFile, getAuthorizationModule(authorizationClassName)); } else if ("wisebed-federator".equals(type) || "federator".equals(type)) { FederatorType fedType = FederatorType.GENERIC; String secretAuthkeyUrl = null; if ("wisebed-federator".equals(type)) { fedType = FederatorType.WISEBED; secretAuthkeyUrl = props.getProperty(snaaName + ".authentication.url"); } // endpoint url -> set<urnprefix> Map<String, Set<String>> federatedUrnPrefixes = new HashMap<String, Set<String>>(); Set<String> federates = parseCSV(props.getProperty(snaaName + ".federates", "")); for (String federatedName : federates) { Set<String> urnPrefixes = parseCSV(props.getProperty(snaaName + "." + federatedName + ".urnprefixes")); String endpointUrl = props.getProperty(snaaName + "." + federatedName + ".endpointurl"); federatedUrnPrefixes.put(endpointUrl, urnPrefixes); } startFederator( fedType, path, secretAuthkeyUrl, shibbolethInjector, shibbolethProxy, federatedUrnPrefixes); } else { log.error("Found unknown type " + type + " for snaa name " + snaaName + ". Ignoring..."); } } return server; }