/* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.gv.egovernment.moa.id.util; import java.io.IOException; import java.util.Properties; import org.springframework.stereotype.Service; import at.gv.egiz.eaaf.core.api.data.ILoALevelMapper; import at.gv.egovernment.moa.id.data.AuthenticationRole; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.MiscUtil; /** * @author tlenz * */ @Service("MOAIDLoALevelMapper") public class LoALevelMapper implements ILoALevelMapper{ private static final String PVP_SECCLASS_PREFIX = "http://www.ref.gv.at/ns/names/agiz/pvp/"; private static final String STORK_QAA_PREFIX = "http://www.stork.gov.eu/1.0/"; private static final String eIDAS_QAA_PREFIX = "http://eidas.europa.eu/"; private static final String MAPPING_RESOURCE = "resources/properties/pvp-stork_mapping.properties"; private static final String MAPPING_SECCLASS_PREFIX = "secclass_"; private static final String MAPPING_EIDAS_PREFIX = "eidas_"; private Properties mapping = null; public LoALevelMapper() { try { mapping = new Properties(); mapping.load(this.getClass().getClassLoader().getResourceAsStream(MAPPING_RESOURCE)); Logger.debug("PVP -> STORK Role mapping initialisation finished."); } catch (IOException e) { Logger.error("PVP -> STORK Role mapping initialisation FAILED." , e); mapping = null; } } public String mapToeIDASLoA(String qaa) { if (qaa.startsWith(STORK_QAA_PREFIX)) return mapSTORKQAAToeIDASQAA(qaa); else if (qaa.startsWith(PVP_SECCLASS_PREFIX)) return mapSTORKQAAToeIDASQAA(mapSecClassToQAALevel(qaa)); else if (qaa.startsWith(MAPPING_EIDAS_PREFIX)) return qaa; else { Logger.info("QAA: " + qaa + " is NOT supported by LoA level mapper"); return null; } } public String mapToSecClass(String qaa) { if (qaa.startsWith(STORK_QAA_PREFIX)) return mapStorkQAAToSecClass(qaa); else if (qaa.startsWith(MAPPING_EIDAS_PREFIX)) return mapStorkQAAToSecClass(mapeIDASQAAToSTORKQAA(qaa)); else if (qaa.startsWith(PVP_SECCLASS_PREFIX)) return qaa; else { Logger.info("QAA: " + qaa + " is NOT supported by LoA level mapper"); return null; } } /** * Map STORK QAA level to eIDAS QAA level * * @param storkQAA STORK QAA level * @return */ public String mapSTORKQAAToeIDASQAA(String storkQAA) { if (mapping != null) { String input = storkQAA.substring(STORK_QAA_PREFIX.length()); String mappedQAA = mapping.getProperty(MAPPING_EIDAS_PREFIX + input); if (MiscUtil.isNotEmpty(mappedQAA)) { Logger.info("Map STORK-QAA " + storkQAA + " to eIDAS-QAA " + mappedQAA); return mappedQAA; } } Logger.warn("No eIDAS-QAA mapping for STORK-QAA " + storkQAA +" !"); return null; } /** * Map eIDAS QAA-level to STORK QAA-level * * @param qaaLevel eIDAS QAA-level * @return STORK QAA-level */ public String mapeIDASQAAToSTORKQAA(String qaaLevel) { if (mapping != null) { String input = qaaLevel.substring(eIDAS_QAA_PREFIX.length()); String mappedQAA = mapping.getProperty(input); if (MiscUtil.isNotEmpty(mappedQAA)) { Logger.info("Map eIDAS-QAA " + qaaLevel + " to STORK-QAA " + mappedQAA); return mappedQAA; } } Logger.warn("No eIDAS-QAA mapping for eIDAS-QAA " + qaaLevel +" !"); return null; } /**Map a STORK QAA level to PVP SecClass * * @param STORK-QAA level * @return PVP SecClass pvpQAALevel */ public String mapStorkQAAToSecClass(String storkQAALevel) { if (mapping != null) { String input = storkQAALevel.substring(STORK_QAA_PREFIX.length()); String mappedQAA = mapping.getProperty(MAPPING_SECCLASS_PREFIX + input); if (MiscUtil.isNotEmpty(mappedQAA)) { Logger.info("Map STORK-QAA " + storkQAALevel + " to PVP SecClass " + mappedQAA); return mappedQAA; } } Logger.warn("No mapping for STORK-QAA " + storkQAALevel +" !"); return null; } /**Map a PVP SecClass to STORK QAA level * * @param PVP SecClass pvpQAALevel * @return STORK-QAA level */ public String mapSecClassToQAALevel(String pvpQAALevel) { if (mapping != null) { String input = pvpQAALevel.substring(PVP_SECCLASS_PREFIX.length()); String mappedQAA = mapping.getProperty(input); if (MiscUtil.isNotEmpty(mappedQAA)) { Logger.info("Map PVP SecClass " + pvpQAALevel + " to STORK-QAA " + mappedQAA); return mappedQAA; } } Logger.warn("No mapping for PVP SecClass " + pvpQAALevel +" !"); return null; } /**Map a PVP Role attribute to STORK ECAuthenticationRole attribute values * * @param PVP Role attribute * @return STORK ECAuthenticationRole attribute value */ public String map(AuthenticationRole el) { if (mapping != null) { //String ecRole = mapping.getProperty(el.getRawRoleString()); String ecRole = mapping.getProperty(el.getRoleName()); if (MiscUtil.isNotEmpty(ecRole)) { //Logger.info("Map PVPRole " + el.getRawRoleString() + " to ECRole " + ecRole); Logger.info("Map PVPRole " + el.getRoleName() + " to ECRole " + ecRole); return ecRole; } } //Logger.warn("NO mapping for PVPRole "+ el.getRawRoleString() + " !"); Logger.warn("NO mapping for PVPRole "+ el.getRoleName() + " !"); return null; } }