diff options
Diffstat (limited to 'id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/protocols/eidas/eIDASAuthenticationRequest.java')
-rw-r--r-- | id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/protocols/eidas/eIDASAuthenticationRequest.java | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/protocols/eidas/eIDASAuthenticationRequest.java b/id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/protocols/eidas/eIDASAuthenticationRequest.java index 9e29c01f3..168cb42d9 100644 --- a/id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/protocols/eidas/eIDASAuthenticationRequest.java +++ b/id/server/modules/moa-id-module-eIDAS/src/main/java/at/gv/egovernment/moa/id/protocols/eidas/eIDASAuthenticationRequest.java @@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; +import org.opensaml.saml2.core.StatusCode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; @@ -50,6 +51,7 @@ import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.MiscUtil; import eu.eidas.auth.commons.EidasStringUtil; import eu.eidas.auth.commons.attribute.AttributeDefinition; +import eu.eidas.auth.commons.attribute.AttributeDefinition.Builder; import eu.eidas.auth.commons.attribute.AttributeValue; import eu.eidas.auth.commons.attribute.AttributeValueMarshaller; import eu.eidas.auth.commons.attribute.AttributeValueMarshallingException; @@ -89,36 +91,48 @@ public class eIDASAuthenticationRequest implements IAction { for(AttributeDefinition<?> attr : reqAttributeList.getDefinitions()) { String newValue = ""; - + boolean isUniqueID = false; // TODO make use of proper builder + switch(attr.getFriendlyName()) { - case Constants.eIDAS_ATTR_DATEOFBIRTH: newValue = new SimpleDateFormat("YYYY-MM-dd").format(authData.getDateOfBirth()); break; - case Constants.eIDAS_ATTR_CURRENTFAMILYNAME: newValue = authData.getFamilyName();break; - case Constants.eIDAS_ATTR_CURRENTGIVENNAME: newValue = authData.getGivenName();break; - case Constants.eIDAS_ATTR_PERSONALIDENTIFIER: newValue = authData.getBPK(); break; + case Constants.eIDAS_ATTR_DATEOFBIRTH: + newValue = new SimpleDateFormat("YYYY-MM-dd").format(authData.getDateOfBirth()); + break; + case Constants.eIDAS_ATTR_CURRENTFAMILYNAME: + newValue = authData.getFamilyName(); + break; + case Constants.eIDAS_ATTR_CURRENTGIVENNAME: + newValue = authData.getGivenName(); + break; + case Constants.eIDAS_ATTR_PERSONALIDENTIFIER: + newValue = authData.getBPK(); + isUniqueID = true; + break; } - + if(MiscUtil.isEmpty(newValue)) { -// current.getValue().setStatus(EIDASStatusCode.STATUS_NOT_AVAILABLE.toString()); Logger.info("eIDAS Attr:" + attr.getNameUri() + " is not available."); } else { - AttributeValueMarshaller<?> attributeValueMarshaller = attr.getAttributeValueMarshaller(); - ImmutableSet.Builder<AttributeValue<?>> builder = ImmutableSet.builder(); + Builder<?> attrBuilder = AttributeDefinition.builder(attr); + attrBuilder.uniqueIdentifier(isUniqueID); + AttributeDefinition<?> returnAttr = attrBuilder.build(); + AttributeValueMarshaller<?> attributeValueMarshaller = returnAttr.getAttributeValueMarshaller(); + ImmutableSet.Builder<AttributeValue<?>> builder = ImmutableSet.builder(); + AttributeValue<?> attributeValue = null; try { attributeValue = attributeValueMarshaller.unmarshal(newValue, false); + builder.add(attributeValue); } catch (AttributeValueMarshallingException e) { throw new IllegalStateException(e); } - - //TODO: check for 'isAvailable flag'! - attrMapBuilder.put((AttributeDefinition)attr, (ImmutableSet) builder.build()); + attrMapBuilder.put((AttributeDefinition)returnAttr, (ImmutableSet) builder.build()); } @@ -141,10 +155,16 @@ public class eIDASAuthenticationRequest implements IAction { //add attributes responseBuilder.attributes(attrMapBuilder.build()); + //set success statuscode + responseBuilder.statusCode(StatusCode.SUCCESS_URI); + + + //build response AuthenticationResponse response = responseBuilder.build(); String token = null; + IResponseMessage eIDASRespMsg = null; try { ProtocolEngineI engine = at.gv.egovernment.moa.id.auth.modules.eidas.utils.SAMLEngineUtils.createSAMLEngine(eIDASMetadataProvider); @@ -152,9 +172,9 @@ public class eIDASAuthenticationRequest implements IAction { // but we need to set the appropriate request issuer //engine.setRequestIssuer(eidasRequest.getEidasRequest().getIssuer()); - IResponseMessage eIDASRespMsg = engine.generateResponseMessage(eidasRequest.getEidasRequest(), + eIDASRespMsg = engine.generateResponseMessage(eidasRequest.getEidasRequest(), response, true, eidasRequest.getRemoteAddress()); - + // if(null == eidasRequest.getEidasRequest().getAssertionConsumerServiceURL()) { // String assertionConsumerUrl = MetadataUtil.getAssertionUrlFromMetadata( // new MOAeIDASMetadataProviderDecorator(eIDASMetadataProvider), @@ -169,8 +189,9 @@ public class eIDASAuthenticationRequest implements IAction { token = EidasStringUtil.encodeToBase64(eIDASRespMsg.getMessageBytes()); - } catch(Exception e) { - e.printStackTrace(); + } catch(Exception e) { + Logger.error("eIDAS Response encoding error." , e); + throw new MOAIDException("eIDAS.13", new Object[]{e.getMessage()}, e); } @@ -202,7 +223,9 @@ public class eIDASAuthenticationRequest implements IAction { httpResp.setContentType(MediaType.TEXT_HTML.getType()); } catch (Exception e) { - Logger.error("Velocity error: " + e.getMessage()); + Logger.error("Velocity error: " + e.getMessage()); + throw new MOAIDException("eIDAS.13", new Object[]{e.getMessage()}, e); + } return null; |