/******************************************************************************* *******************************************************************************/ package at.gv.egiz.eaaf.core.impl.idp.builder.attributes; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.gv.egiz.eaaf.core.api.data.EAAFConstants; import at.gv.egiz.eaaf.core.api.idp.IAttributeGenerator; import at.gv.egiz.eaaf.core.api.idp.IAuthData; import at.gv.egiz.eaaf.core.api.idp.IPVPAttributeBuilder; import at.gv.egiz.eaaf.core.api.idp.ISPConfiguration; import at.gv.egiz.eaaf.core.exceptions.AttributeBuilderException; import at.gv.egiz.eaaf.core.exceptions.UnavailableAttributeException; @PVPMETADATA public class BPKAttributeBuilder implements IPVPAttributeBuilder { private static final Logger log = LoggerFactory.getLogger(BPKAttributeBuilder.class); public String getName() { return BPK_NAME; } public ATT build(ISPConfiguration oaParam, IAuthData authData, IAttributeGenerator g) throws AttributeBuilderException { String bpk = authData.getBPK(); String type = authData.getBPKType(); if (StringUtils.isEmpty(bpk)) throw new UnavailableAttributeException(BPK_NAME); if (type.startsWith(EAAFConstants.URN_PREFIX_WBPK)) type = type.substring((EAAFConstants.URN_PREFIX_WBPK).length()); else if (type.startsWith(EAAFConstants.URN_PREFIX_CDID)) type = 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); } log.trace("Authenticate user with bPK/wbPK " + bpk + " and Type=" + type); return g.buildStringAttribute(BPK_FRIENDLY_NAME, BPK_NAME, type + ":" + bpk); } public ATT buildEmpty(IAttributeGenerator g) { return g.buildEmptyAttribute(BPK_FRIENDLY_NAME, BPK_NAME); } }