diff options
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id')
3 files changed, 129 insertions, 23 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AuthenticationRequest.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AuthenticationRequest.java index 52db1c240..a537a7708 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AuthenticationRequest.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/AuthenticationRequest.java @@ -36,9 +36,15 @@ public class AuthenticationRequest implements IAction { private VelocityEngine velocityEngine; + private AuthenticationSession moaSession; + private MOASTORKAuthnRequest moaStorkAuthnRequest; public String processRequest(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp, AuthenticationSession moasession) throws MOAIDException { + + this.moaSession = moasession; + this.moaStorkAuthnRequest = (MOASTORKAuthnRequest)req; + Logger.debug("Starting AuthenticationRequest"); //AuthenticationServer.getInstance().startSTORKAuthentication(httpReq, httpResp, moasession); Logger.debug("Http Response: " + httpResp.toString() + ", "); @@ -85,29 +91,12 @@ public class AuthenticationRequest implements IAction { //httpResp.setStatus(200); //VPEPSInboundPostHandler - // - prepare attribute list - PersonalAttributeList attributeList = new PersonalAttributeList(); STORKAuthnResponse authnResponse = new STORKAuthnResponse(); authnResponse.setCountry("AT"); - IPersonalAttributeList attrLst = ((MOASTORKAuthnRequest)req).getStorkAuthnRequest().getPersonalAttributeList(); - Logger.info("Found number of authnreq personal attributes: " + attrLst.size()); - - try { - for (PersonalAttribute personalAttribute : attrLst) { - Logger.info("Personal authnreq attribute found: " + personalAttribute.getName() + " status: " + personalAttribute.getStatus() + " isrequired: " + personalAttribute.isRequired() + " type: " + personalAttribute.getType()); - if (personalAttribute.getValue().size() > 0) { - for (String value : personalAttribute.getValue()) { - Logger.info(" Value found: " + value); - } - } - } - } catch (Exception e) { - Logger.error("Exception, attributes: " + e.getMessage()); - } try { @@ -128,12 +117,7 @@ public class AuthenticationRequest implements IAction { Logger.error("Exception, attributes: " + e.getMessage()); } - PersonalAttribute newAttribute = new PersonalAttribute(); - newAttribute.setName("eIdentifier"); - newAttribute.setValue(new ArrayList<String>(Collections.singletonList("xxxxxxxxxxxxxxx"))); - attributeList.add(newAttribute); - authnResponse.setPersonalAttributeList(attributeList); - + authnResponse.setPersonalAttributeList(populateAttributes()); try { //Get SAMLEngine instance @@ -212,7 +196,59 @@ public class AuthenticationRequest implements IAction { } + public PersonalAttributeList populateAttributes() { + IPersonalAttributeList attrLst = moaStorkAuthnRequest.getStorkAuthnRequest().getPersonalAttributeList(); + Logger.info("Found " + attrLst.size() + " personal attributes in the request." ); + + // Define attribute list to be populated + PersonalAttributeList attributeList = new PersonalAttributeList(); + MOAAttributeProvider moaAttributeProvider = new MOAAttributeProvider(moaSession.getIdentityLink()); + + try { + for (PersonalAttribute personalAttribute : attrLst) { + Logger.debug("Personal attribute found: " + personalAttribute.getName() + " status: " + personalAttribute.getStatus() + " isrequired: " + personalAttribute.isRequired() + " type: " + personalAttribute.getType()); + + if ("givenName".equals(personalAttribute.getName())) { + Logger.debug("Providing new attribute: " + personalAttribute.getName()); + PersonalAttribute newAttribute = new PersonalAttribute(); + newAttribute.setName("givenName"); + newAttribute.setValue(new ArrayList<String>(Collections.singletonList(moaSession.getIdentityLink().getGivenName()))); + attributeList.add(newAttribute); + } + + if (personalAttribute.getValue().size() > 0) { + for (String value : personalAttribute.getValue()) { + Logger.info(" Value found: " + value); + } + } + } + } catch (Exception e) { + Logger.error("Exception, attributes: " + e.getMessage()); + } + + + Logger.debug("AUTHBLOCK " + moaSession.getAuthBlock()); + Logger.debug("TARGET " + moaSession.getTarget() + " " + moaSession.getTargetFriendlyName()); + + + Logger.debug("SESSION IDENTIFIER " + moaSession.getCcc() + " " + moaSession.getDomainIdentifier()); + + + Logger.debug("AUTHBLOCKTOKKEN" + moaSession.getAuthBlockTokken()); + + // moaAttributeProvider.populateAttribute(attributeList, personalAttribute.getName()); + + moaAttributeProvider.populateAttribute(attributeList, "givenName"); + + moaAttributeProvider.populateAttribute(attributeList, "surname"); + + moaAttributeProvider.populateAttribute(attributeList, "xxname"); + + moaAttributeProvider.populateAttribute(attributeList, "dateOfBirth"); + + return attributeList; + } public String getDefaultActionName() { return STORKProtocol.AUTHENTICATIONREQUEST; 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 new file mode 100644 index 000000000..33c1ffcd2 --- /dev/null +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/MOAAttributeProvider.java @@ -0,0 +1,69 @@ +package at.gv.egovernment.moa.id.protocols.stork2; + +import at.gv.egovernment.moa.id.auth.data.IdentityLink; +import at.gv.egovernment.moa.logging.Logger; +import eu.stork.peps.auth.commons.PersonalAttribute; +import eu.stork.peps.auth.commons.PersonalAttributeList; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * @author bsuzic + * Date: 2/19/14, Time: 4:42 PM + */ +public class MOAAttributeProvider { + private final IdentityLink identityLink; + private static final Map<String, String> storkAttributeMapping; + + static { + Map<String, String> tempMap = new HashMap<String, String>(); + tempMap.put("givenName", "getGivenName"); + tempMap.put("surname", "getFamilyName"); + tempMap.put("dateOfBirth", "getDateOfBirth"); + storkAttributeMapping = Collections.unmodifiableMap(tempMap); + } + + + public MOAAttributeProvider(IdentityLink identityLink) { + this.identityLink = identityLink; + Logger.debug("identity " + identityLink.getIdentificationType() + " " + identityLink.getIdentificationValue()); + } + + public void populateAttribute(PersonalAttributeList attributeList, String storkAttribute) { + + if (storkAttributeMapping.containsKey(storkAttribute)) { + Method method = null; + Logger.debug("Trying to get value for attribute: " + storkAttribute); + + try { + method = identityLink.getClass().getDeclaredMethod(storkAttributeMapping.get(storkAttribute)); + String attributeValue = method.invoke(identityLink, new Class[]{}).toString(); + PersonalAttribute newAttribute = new PersonalAttribute(); + newAttribute.setName(storkAttribute); + Logger.debug("Got attribute value: " + attributeValue); + newAttribute.setValue(new ArrayList<String>(edu.emory.mathcs.backport.java.util.Collections.singletonList(attributeValue))); + attributeList.add(newAttribute); + } catch (NoSuchMethodException e) { + Logger.error("Could not found MOA extraction method while getting attribute: " + storkAttribute); + e.printStackTrace(); + } catch (InvocationTargetException e) { + Logger.error("Invocation target expcetiion while getting attribute: " + storkAttribute); + e.printStackTrace(); + } catch (IllegalAccessException e) { + Logger.error("Illegal access exception while getting attribute: " + storkAttribute); + e.printStackTrace(); + } + + } else { + Logger.debug("MOA method for extraction of attribute " + storkAttribute + " not defined."); + } + + } + + +} diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/STORKProtocol.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/STORKProtocol.java index 33d2040eb..3d7852c4b 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/STORKProtocol.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/STORKProtocol.java @@ -153,6 +153,7 @@ public class STORKProtocol implements IModulInfo, MOAIDAuthConstants { STORK2Request.setSTORKAuthnRequest(authnRequest); + return STORK2Request; } |