/* * 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.elgamandates.config; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.opensaml.Configuration; import org.opensaml.saml2.core.AuthnContextComparisonTypeEnumeration; import org.opensaml.saml2.core.NameID; import org.opensaml.saml2.core.SubjectConfirmation; import org.opensaml.saml2.core.SubjectConfirmationData; import org.opensaml.saml2.metadata.EntityDescriptor; import org.opensaml.xml.io.Marshaller; import org.opensaml.xml.io.MarshallingException; import org.opensaml.xml.security.credential.Credential; import org.w3c.dom.Document; import org.w3c.dom.Element; import at.gv.egovernment.moa.id.auth.modules.elgamandates.ELGAMandatesAuthConstants; import at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation; import at.gv.egovernment.moa.id.protocols.pvp2x.utils.SAML2Utils; import at.gv.egovernment.moa.logging.Logger; /** * @author tlenz * */ public class ELGAMandatesRequestBuilderConfiguration implements IPVPAuthnRequestBuilderConfiguruation { private boolean isPassive = false; private String SPEntityID = null; private String QAA_Level = null; private EntityDescriptor idpEntity = null; private Credential signCred = null; private String subjectNameID = null; private String subjectNameIDQualifier = null; private String requestID = null; private Element subjectConformationDate = null; /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#isPassivRequest() */ @Override public Boolean isPassivRequest() { return this.isPassive; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getAssertionConsumerServiceId() */ @Override public Integer getAssertionConsumerServiceId() { return 0; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getEntityID() */ @Override public String getSPEntityID() { return this.SPEntityID; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getNameIDPolicy() */ @Override public String getNameIDPolicyFormat() { return NameID.PERSISTENT; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getNameIDPolicy() */ @Override public boolean getNameIDPolicyAllowCreation() { return false; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getAuthnContextClassRef() */ @Override public String getAuthnContextClassRef() { return this.QAA_Level; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getAuthnContextComparison() */ @Override public AuthnContextComparisonTypeEnumeration getAuthnContextComparison() { return AuthnContextComparisonTypeEnumeration.MINIMUM; } /** * @param isPassive the isPassive to set */ public void setPassive(boolean isPassive) { this.isPassive = isPassive; } /** * @param sPEntityID the sPEntityID to set */ public void setSPEntityID(String sPEntityID) { SPEntityID = sPEntityID; } /** * @param qAA_Level the qAA_Level to set */ public void setQAA_Level(String qAA_Level) { QAA_Level = qAA_Level; } /** * @param idpEntity the idpEntity to set */ public void setIdpEntity(EntityDescriptor idpEntity) { this.idpEntity = idpEntity; } /** * @param signCred the signCred to set */ public void setSignCred(Credential signCred) { this.signCred = signCred; } /** * @param subjectNameID the subjectNameID to set */ public void setSubjectNameID(String subjectNameID) { this.subjectNameID = subjectNameID; } /** * @param requestID the requestID to set */ public void setRequestID(String requestID) { this.requestID = requestID; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getAuthnRequestSigningCredential() */ @Override public Credential getAuthnRequestSigningCredential() { return this.signCred; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getIDPEntityDescriptor() */ @Override public EntityDescriptor getIDPEntityDescriptor() { return this.idpEntity; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getSubjectNameID() */ @Override public String getSubjectNameID() { return this.subjectNameID; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getSPNameForLogging() */ @Override public String getSPNameForLogging() { return ELGAMandatesAuthConstants.MODULE_NAME_FOR_LOGGING; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getSubjectNameIDFormat() */ @Override public String getSubjectNameIDFormat() { return NameID.PERSISTENT; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getRequestID() */ @Override public String getRequestID() { return this.requestID; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getSubjectNameIDQualifier() */ @Override public String getSubjectNameIDQualifier() { return this.subjectNameIDQualifier; } /** * @param subjectNameIDQualifier the subjectNameIDQualifier to set */ public void setSubjectNameIDQualifier(String subjectNameIDQualifier) { this.subjectNameIDQualifier = subjectNameIDQualifier; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getSubjectConformationMethode() */ @Override public String getSubjectConformationMethode() { return SubjectConfirmation.METHOD_BEARER; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.protocols.pvp2x.config.IPVPAuthnRequestBuilderConfiguruation#getSubjectConformationDate() */ @Override public Element getSubjectConformationDate() { return subjectConformationDate; } /** * @param subjectConformationDate the subjectConformationDate to set */ public void setSubjectConformationDate(String givenName, String familyName, String dateOfBirth) { try { Logger.trace("Build 'SubjectConfirmationData' for ELGA Mandate-Service request ..."); //build empty 'SubjectConfirmationData' element SubjectConfirmationData subjectConformDate = SAML2Utils.createSAMLObject(SubjectConfirmationData.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder builder = dbf.newDocumentBuilder(); Document doc = builder.newDocument(); Marshaller out = Configuration.getMarshallerFactory() .getMarshaller(subjectConformDate); out.marshall(subjectConformDate, doc); //build root element for personal information Element rootDom = doc.createElementNS( ELGAMandatesAuthConstants.SUBJECTCONFORMATIONDATE_ELEMENT_NAMESPACE_URI, ELGAMandatesAuthConstants.SUBJECTCONFORMATIONDATE_ELEMENT_ROOT); rootDom.setPrefix(ELGAMandatesAuthConstants.SUBJECTCONFORMATIONDATE_ELEMENT_NAMESPACE); rootDom.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + ELGAMandatesAuthConstants.SUBJECTCONFORMATIONDATE_ELEMENT_NAMESPACE, ELGAMandatesAuthConstants.SUBJECTCONFORMATIONDATE_ELEMENT_NAMESPACE_URI); //build personal information Element familyNameDom = doc.createElement(ELGAMandatesAuthConstants.SUBJECTCONFORMATIONDATE_ELEMENT_FAMILYNAME); Element givenNameDom = doc.createElement(ELGAMandatesAuthConstants.SUBJECTCONFORMATIONDATE_ELEMENT_GIVENNAME); Element dateOfBirthDom = doc.createElement(ELGAMandatesAuthConstants.SUBJECTCONFORMATIONDATE_ELEMENT_DATEOFBIRTH); familyNameDom.setTextContent(familyName); givenNameDom.setTextContent(givenName); dateOfBirthDom.setTextContent(dateOfBirth); //add personal information to 'SubjectConfirmationData' element doc.getFirstChild().appendChild(rootDom); rootDom.appendChild(givenNameDom); rootDom.appendChild(familyNameDom); rootDom.appendChild(dateOfBirthDom); this.subjectConformationDate = doc.getDocumentElement(); Logger.trace("'SubjectConfirmationData' for ELGA Mandate-Service is complete"); } catch (ParserConfigurationException | MarshallingException e) { Logger.error("Can not generate 'SubjectConformationDate' for " + ELGAMandatesAuthConstants.MODULE_NAME_FOR_LOGGING); } } }