package at.gv.egovernment.moa.id.proxy; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import at.gv.egovernment.moa.id.config.proxy.OAConfiguration; import at.gv.egovernment.moa.id.data.AuthenticationData; import at.gv.egovernment.moa.util.Base64Utils; /** * Implementation of interface LoginParameterResolver * @author Paul Ivancsics * @version $Id$ */ public class DefaultLoginParameterResolver implements LoginParameterResolver { /** * Constructor */ public DefaultLoginParameterResolver() { } /** * Configuration mehtod (not used) */ public void configure(String configuration) throws LoginParameterResolverException { } /** * @see at.gv.egovernment.moa.id.proxy.LoginParameterResolver#getAuthenticationHeaders(at.gv.egovernment.moa.id.config.proxy.OAConfiguration, at.gv.egovernment.moa.id.auth.data.AuthenticationData, java.lang.String) */ public Map getAuthenticationHeaders( OAConfiguration oaConf, AuthenticationData authData, String clientIPAddress) { Map result = new HashMap(); if (oaConf.getAuthType().equals(OAConfiguration.BASIC_AUTH)) { String useridPredicate = oaConf.getBasicAuthUserIDMapping(); String userid = resolveValue(useridPredicate, authData, clientIPAddress); String passwordPredicate = oaConf.getBasicAuthPasswordMapping(); String password = resolveValue(passwordPredicate, authData, clientIPAddress); try { String userIDPassword = userid + ":" + password; String credentials = Base64Utils.encode(userIDPassword.getBytes()); result.put("Authorization", "Basic " + credentials); } catch (IOException ignore) { } } else if (oaConf.getAuthType().equals(OAConfiguration.HEADER_AUTH)) { for (Iterator iter = oaConf.getHeaderAuthMapping().keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); String predicate = (String) oaConf.getHeaderAuthMapping().get(key); String resolvedValue = resolveValue(predicate, authData, clientIPAddress); result.put(key, resolvedValue); } } return result; } /** * @see at.gv.egovernment.moa.id.proxy.LoginParameterResolver#getAuthenticationParameters(at.gv.egovernment.moa.id.config.proxy.OAConfiguration, at.gv.egovernment.moa.id.auth.data.AuthenticationData, java.lang.String) */ public Map getAuthenticationParameters( OAConfiguration oaConf, AuthenticationData authData, String clientIPAddress) { Map result = new HashMap(); if (oaConf.getAuthType().equals(OAConfiguration.PARAM_AUTH)) { for (Iterator iter = oaConf.getParamAuthMapping().keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); String predicate = (String) oaConf.getParamAuthMapping().get(key); String resolvedValue = resolveValue(predicate, authData, clientIPAddress); result.put(key, resolvedValue); } } return result; } /** * Resolves a login header or parameter value. * @param predicate header or parameter predicate name from online application configuration * @param authData authentication data for current login * @param clientIPAddress client IP address * @return header or parameter value resolved; null if unknown name is given */ private static String resolveValue(String predicate, AuthenticationData authData, String clientIPAddress) { if (predicate.equals(MOAGivenName)) return authData.getGivenName(); else if (predicate.equals(MOAFamilyName)) return authData.getFamilyName(); else if (predicate.equals(MOADateOfBirth)) return authData.getDateOfBirth(); else if (predicate.equals(MOAVPK)) return authData.getVPK(); else if (predicate.equals(MOAPublicAuthority)) if (authData.isPublicAuthority()) return "true"; else return "false"; else if (predicate.equals(MOABKZ)) return authData.getPublicAuthorityCode(); else if (predicate.equals(MOAQualifiedCertificate)) if (authData.isQualifiedCertificate()) return "true"; else return "false"; else if (predicate.equals(MOAZMRZahl)) return authData.getIdentificationValue(); else if (predicate.equals(MOAIPAddress)) return clientIPAddress; else return null; } }