package at.gv.egovernment.moa.id.protocols.pvp2x.builder.attributes; import org.opensaml.saml2.core.Attribute; import org.w3c.dom.Element; import at.gv.e_government.reference.namespace.mandates._20040701_.Mandate; import at.gv.e_government.reference.namespace.persondata._20020228_.CorporateBodyType; import at.gv.e_government.reference.namespace.persondata._20020228_.IdentificationType; import at.gv.egovernment.moa.id.auth.data.AuthenticationSession; import at.gv.egovernment.moa.id.config.auth.OAAuthParameter; import at.gv.egovernment.moa.id.data.AuthenticationData; import at.gv.egovernment.moa.id.protocols.pvp2x.exceptions.NoMandateDataAvailableException; import at.gv.egovernment.moa.id.protocols.pvp2x.exceptions.PVP2Exception; import at.gv.egovernment.moa.id.util.MandateBuilder; import at.gv.egovernment.moa.logging.Logger; public class MandateLegalPersonSourcePinTypeAttributeBuilder extends BaseAttributeBuilder { public String getName() { return MANDATE_LEG_PER_SOURCE_PIN_TYPE_NAME; } public Attribute build(AuthenticationSession authSession, OAAuthParameter oaParam, AuthenticationData authData) throws PVP2Exception { if (authSession.getUseMandate()) { Element mandate = authSession.getMandate(); if (mandate == null) { throw new NoMandateDataAvailableException(); } Mandate mandateObject = MandateBuilder.buildMandate(mandate); if (mandateObject == null) { throw new NoMandateDataAvailableException(); } CorporateBodyType corporation = mandateObject.getMandator() .getCorporateBody(); if (corporation == null) { Logger.error("No corporate mandate"); throw new NoMandateDataAvailableException(); } IdentificationType id = null; if(corporation.getIdentification().size() == 0) { Logger.error("Failed to generate IdentificationType"); throw new NoMandateDataAvailableException(); } id = corporation.getIdentification().get(0); /*id = MandateBuilder.getBPKIdentification(corporate); if (id == null) { Logger.error("Failed to generate IdentificationType"); throw new NoMandateDataAvailableException(); }*/ return buildStringAttribute( MANDATE_LEG_PER_SOURCE_PIN_TYPE_FRIENDLY_NAME, MANDATE_LEG_PER_SOURCE_PIN_TYPE_NAME, id.getType()); } return null; } public Attribute buildEmpty() { return buildemptyAttribute( MANDATE_LEG_PER_SOURCE_PIN_TYPE_FRIENDLY_NAME, MANDATE_LEG_PER_SOURCE_PIN_TYPE_NAME); } }