/*
* 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.auth.modules.eidas.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import at.gv.egiz.eaaf.core.impl.data.Trible;
import at.gv.egovernment.moa.id.auth.modules.eidas.Constants;
import at.gv.egovernment.moa.logging.Logger;
/**
* @author tlenz
*
*/
public class eIDASAttributeProcessingUtils {
public static final String PERSONALIDENIFIER_VALIDATION_PATTERN = "^[A-Z,a-z]{2}/[A-Z,a-z]{2}/.*";
/**
* Validate a eIDAS PersonalIdentifier attribute value
* This validation is done according to eIDAS SAML Attribute Profile - Section 2.2.3 Unique Identifier
*
* @param uniqueID eIDAS attribute value of a unique identifier
* @return true if the uniqueID matches to eIDAS to Unique Identifier specification, otherwise false
*/
public static boolean validateEidasPersonalIdentifier(String uniqueID) {
Pattern pattern = Pattern.compile(PERSONALIDENIFIER_VALIDATION_PATTERN );
Matcher matcher = pattern.matcher(uniqueID);
return matcher.matches();
}
/**
* Parse an eIDAS PersonalIdentifier attribute value into it components.
* This processing is done according to eIDAS SAML Attribute Profile - Section 2.2.3 Unique Identifier
*
* @param uniqueID eIDAS attribute value of a unique identifier
* @return {@link Trible} that contains:
*
First : citizen country
*
Second: destination country
*
Third : unique identifier
*
or null if the attribute value has a wrong format
*/
public static Trible parseEidasPersonalIdentifier(String uniqueID) {
if (!validateEidasPersonalIdentifier(uniqueID)) {
Logger.error("eIDAS attribute value for " + Constants.eIDAS_ATTR_PERSONALIDENTIFIER
+ " looks wrong formated. Value:" + ((String)uniqueID));
return null;
}
return Trible.newInstance(uniqueID.substring(0, 2), uniqueID.substring(3, 5), uniqueID.substring(6));
}
}