From b7bb75a4b642df6b8ce1c84cf5d4f8fea5d986b0 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 18 Feb 2019 10:07:40 +0100 Subject: add demo-mode functionality for 'Austria eID' --- .../builder/attributes/BPKAttributeBuilder.java | 71 ++++++++++++++++------ 1 file changed, 53 insertions(+), 18 deletions(-) (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java index 261fd211..a5c1e7d4 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java @@ -41,7 +41,8 @@ import at.gv.egiz.eaaf.core.exceptions.UnavailableAttributeException; @PVPMETADATA public class BPKAttributeBuilder implements IPVPAttributeBuilder { - private static final Logger log = LoggerFactory.getLogger(BPKAttributeBuilder.class); + private static final Logger log = LoggerFactory.getLogger(BPKAttributeBuilder.class); + protected static final String DELIMITER_BPKTYPE_BPK = ":"; public String getName() { return BPK_NAME; @@ -49,32 +50,66 @@ public class BPKAttributeBuilder implements IPVPAttributeBuilder { public ATT build(ISPConfiguration oaParam, IAuthData authData, IAttributeGenerator g) throws AttributeBuilderException { - String bpk = authData.getBPK(); - String type = authData.getBPKType(); + String result = getBpkForSP(authData); + log.trace("Authenticate user with bPK/wbPK: " + result); + return g.buildStringAttribute(BPK_FRIENDLY_NAME, BPK_NAME, result); + + } + + public ATT buildEmpty(IAttributeGenerator g) { + return g.buildEmptyAttribute(BPK_FRIENDLY_NAME, BPK_NAME); + } + + /** + * Generate the bPK String for this specific SP + * + * @param authData + * @return + * @throws UnavailableAttributeException + */ + protected String getBpkForSP(IAuthData authData) throws UnavailableAttributeException { + String bpk = attrMaxSize(authData.getBPK()); + String type = removeBpkTypePrefix(authData.getBPKType()); if (StringUtils.isEmpty(bpk)) throw new UnavailableAttributeException(BPK_NAME); - + + return type + DELIMITER_BPKTYPE_BPK + bpk; + + } + + /** + * Limit the attribute value to maximum size + * + * @param attr + * @return + */ + protected String attrMaxSize(String attr) { + if (attr != null && attr.length() > BPK_MAX_LENGTH) { + attr = attr.substring(0, BPK_MAX_LENGTH); + } + return attr; + + } + + /** + * Remove bPKType prefix if available + * + * @param type + * @return + */ + protected String removeBpkTypePrefix(String type) { if (type.startsWith(EAAFConstants.URN_PREFIX_WBPK)) - type = type.substring((EAAFConstants.URN_PREFIX_WBPK).length()); + return type.substring((EAAFConstants.URN_PREFIX_WBPK).length()); else if (type.startsWith(EAAFConstants.URN_PREFIX_CDID)) - type = type.substring((EAAFConstants.URN_PREFIX_CDID).length()); + return type.substring((EAAFConstants.URN_PREFIX_CDID).length()); else if (type.startsWith(EAAFConstants.URN_PREFIX_EIDAS)) - type = type.substring((EAAFConstants.URN_PREFIX_EIDAS).length()); - - if (bpk.length() > BPK_MAX_LENGTH) { - bpk = bpk.substring(0, BPK_MAX_LENGTH); - } + return type.substring((EAAFConstants.URN_PREFIX_EIDAS).length()); - log.trace("Authenticate user with bPK/wbPK " + bpk + " and Type=" + type); + else + return type; - return g.buildStringAttribute(BPK_FRIENDLY_NAME, BPK_NAME, type + ":" + bpk); } - - public ATT buildEmpty(IAttributeGenerator g) { - return g.buildEmptyAttribute(BPK_FRIENDLY_NAME, BPK_NAME); - } - } -- cgit v1.2.3