summaryrefslogtreecommitdiff
path: root/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java')
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/attributes/BPKAttributeBuilder.java71
1 files changed, 53 insertions, 18 deletions
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> ATT build(ISPConfiguration oaParam, IAuthData authData,
IAttributeGenerator<ATT> 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> ATT buildEmpty(IAttributeGenerator<ATT> 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> ATT buildEmpty(IAttributeGenerator<ATT> g) {
- return g.buildEmptyAttribute(BPK_FRIENDLY_NAME, BPK_NAME);
- }
-
}