package at.gv.egovernment.moa.id.proxy; import java.io.IOException; import java.io.UnsupportedEncodingException; 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; import at.gv.egovernment.moa.util.URLEncoder; /** * 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; try { resolvedValue = URLEncoder.encode(resolveValue(predicate, authData, clientIPAddress), "ISO-8859-1"); } catch (UnsupportedEncodingException e) { //ISO-8859-1 is supported resolvedValue = null; } 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(); if (predicate.equals(MOAFamilyName)) return authData.getFamilyName(); if (predicate.equals(MOADateOfBirth)) return authData.getDateOfBirth(); if (predicate.equals(MOABPK)) return authData.getPBK(); if (predicate.equals(MOAPublicAuthority)) if (authData.isPublicAuthority()) return "true"; else return "false"; if (predicate.equals(MOABKZ)) return authData.getPublicAuthorityCode(); if (predicate.equals(MOAQualifiedCertificate)) if (authData.isQualifiedCertificate()) return "true"; else return "false"; if (predicate.equals(MOAStammzahl)) return authData.getIdentificationValue(); if (predicate.equals(MOAIdentificationValueType)) return authData.getIdentificationType(); if (predicate.equals(MOAIPAddress)) return clientIPAddress; else return null; } }