From af0f895ce9fac2fd5eb0faf4570881aace2198fa Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Wed, 29 Oct 2014 12:04:43 +0100 Subject: update STORK specific attribute build process --- .../id/protocols/stork2/MOAAttributeProvider.java | 48 ++++++++++++++------- .../moa/id/protocols/stork2/MOASTORKRequest.java | 49 +++++++++++++--------- 2 files changed, 63 insertions(+), 34 deletions(-) diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MOAAttributeProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MOAAttributeProvider.java index d7d6601c9..021eaee37 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MOAAttributeProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MOAAttributeProvider.java @@ -25,8 +25,11 @@ package at.gv.egovernment.moa.id.protocols.stork2; import at.gv.egovernment.moa.id.auth.builder.BPKBuilder; import at.gv.egovernment.moa.id.auth.data.IdentityLink; import at.gv.egovernment.moa.id.auth.exception.BuildException; +import at.gv.egovernment.moa.id.data.AuthenticationRole; import at.gv.egovernment.moa.id.data.IAuthData; +import at.gv.egovernment.moa.id.util.PVPtoSTORKRoleMapper; import at.gv.egovernment.moa.logging.Logger; +import at.gv.egovernment.moa.util.MiscUtil; import eu.stork.peps.auth.commons.PersonalAttribute; import eu.stork.peps.auth.commons.PersonalAttributeList; import eu.stork.peps.auth.commons.STORKStatusCode; @@ -58,11 +61,11 @@ public class MOAAttributeProvider { Map tempSimpleMap = new HashMap(); tempSimpleMap.put("givenName", "getGivenName"); tempSimpleMap.put("surname", "getFamilyName"); - tempSimpleMap.put("dateOfBirth", "getFormatedDateOfBirth"); storkAttributeSimpleMapping = Collections.unmodifiableMap(tempSimpleMap); Map tempFunctionMap = new HashMap(); tempFunctionMap.put("eIdentifier", "geteIdentifier"); tempFunctionMap.put("ECApplicationRole","getECApplicationRole"); + tempSimpleMap.put("dateOfBirth", "getFormatedDateOfBirth"); storkAttributeFunctionMapping = Collections.unmodifiableMap(tempFunctionMap); } @@ -112,23 +115,34 @@ public class MOAAttributeProvider { private List getECApplicationRole() { List storkRoles = null; - - if (authData.getAuthenticationRoles() != null + + if (true || authData.getAuthenticationRoles() != null && authData.getAuthenticationRoles().size() > 0) { - - - //TODO: implement PVP role -> STORK role mapping -// storkRoles = new ArrayList(); -// storkRoles.add("CIRCABC/viewer"); - - } - + + storkRoles = new ArrayList(); + PVPtoSTORKRoleMapper mapper = PVPtoSTORKRoleMapper.getInstance(); + for (AuthenticationRole el : authData.getAuthenticationRoles()) { + String storkRole = mapper.map(el); + if (MiscUtil.isNotEmpty(storkRole)) + storkRoles.add(storkRole); + + } + } return storkRoles; } + private String getFormatedDateOfBirth() { + if (authData.getDateOfBirth() != null) + return authData.getFormatedDateOfBirth(); + + else + return null; + + } + private void populateAttributeWithMethod(Method method, Object object, PersonalAttributeList attributeList, String storkAttribute, Boolean isRequired) { try { - Object attributeValue = method.invoke(object, new Class[]{}).toString(); + Object attributeValue = method.invoke(object, new Class[]{}); PersonalAttribute newAttribute = new PersonalAttribute(); newAttribute.setName(storkAttribute); @@ -143,9 +157,15 @@ public class MOAAttributeProvider { else if (attributeValue instanceof List) { List attributeValueList = (List) attributeValue; - if (attributeValueList.size() > 0 && attributeValueList.get(0) instanceof String) + if (attributeValueList.size() > 0 && attributeValueList.get(0) instanceof String) { newAttribute.setValue((List) attributeValueList); - + + } else { + Logger.info("Attribute " + storkAttribute + " is not available."); + newAttribute.setStatus(STORKStatusCode.STATUS_NOT_AVAILABLE.name()); + + } + } else { Logger.error("Receive an unsupported type for attribute " + storkAttribute); diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MOASTORKRequest.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MOASTORKRequest.java index f4b02ee2d..a92d02e08 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MOASTORKRequest.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MOASTORKRequest.java @@ -23,6 +23,7 @@ package at.gv.egovernment.moa.id.protocols.stork2; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.opensaml.saml2.core.Attribute; @@ -34,6 +35,7 @@ import at.gv.egovernment.moa.id.config.auth.IOAAuthParameters; import at.gv.egovernment.moa.id.config.auth.OAAuthParameter; import at.gv.egovernment.moa.id.config.auth.data.DynamicOAAuthParameters; import at.gv.egovernment.moa.id.moduls.RequestImpl; +import at.gv.egovernment.moa.id.protocols.pvp2x.PVPConstants; import at.gv.egovernment.moa.id.protocols.pvp2x.builder.AttributQueryBuilder; import at.gv.egovernment.moa.id.protocols.pvp2x.messages.MOAResponse; import at.gv.egovernment.moa.id.protocols.saml1.SAML1Protocol; @@ -51,6 +53,16 @@ import eu.stork.peps.auth.commons.STORKAuthnResponse; */ public class MOASTORKRequest extends RequestImpl { + public static final List DEFAULTREQUESTEDATTRFORINTERFEDERATION = Arrays.asList( + new String[] { + PVPConstants.BPK_NAME, + PVPConstants.EID_SECTOR_FOR_IDENTIFIER_NAME, + PVPConstants.GIVEN_NAME_NAME, + PVPConstants.PRINCIPAL_NAME_NAME, + PVPConstants.BIRTHDATE_NAME, + PVPConstants.EID_CITIZEN_QAA_LEVEL_NAME, + }); + /** The Constant serialVersionUID. */ private static final long serialVersionUID = 4581953368724501376L; @@ -220,27 +232,24 @@ public class MOASTORKRequest extends RequestImpl { */ @Override public List getRequestedAttributes() { -// //TODO: only for testing with MOA-ID as PVP Stammportal -// IOAAuthParameters oa; -// try { -// List reqAttr = new ArrayList(); -// reqAttr.addAll(SAML1Protocol.DEFAULTREQUESTEDATTRFORINTERFEDERATION); -// -// oa = AuthConfigurationProvider.getInstance().getOnlineApplicationParameter(getOAURL()); -// oa = DynamicOAAuthParameterBuilder.buildFromAuthnRequest(oa, this); -// -// DynamicOAAuthParameters tmp = (DynamicOAAuthParameters) oa; -// tmp.setBusinessTarget(Constants.URN_PREFIX_CDID + "+BF"); -// -// return AttributQueryBuilder.buildSAML2AttributeList(tmp, reqAttr.iterator()); -// -// } catch (ConfigurationException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// return null; -// } + //TODO: only for testing with MOA-ID as PVP Stammportal + IOAAuthParameters oa; + try { + oa = AuthConfigurationProvider.getInstance().getOnlineApplicationParameter(getOAURL()); + oa = DynamicOAAuthParameterBuilder.buildFromAuthnRequest(oa, this); + + DynamicOAAuthParameters tmp = (DynamicOAAuthParameters) oa; + tmp.setBusinessTarget(Constants.URN_PREFIX_CDID + "+BF"); + + return AttributQueryBuilder.buildSAML2AttributeList(tmp, DEFAULTREQUESTEDATTRFORINTERFEDERATION.iterator()); + + } catch (ConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } - return new ArrayList(); + //return new ArrayList(); } } -- cgit v1.2.3