package org.example.shib_idp; ... public class TargetedIdSampleDataConnector extends AbstractDataConnector { private static final Logger LOG = LoggerFactory.getLogger(TargetedIdSampleDataConnector.class); private final String salt = "A secret, random string."; private String relyingPartyId; @Override protected Map doDataConnectorResolve( AttributeResolutionContext resolutionContext, AttributeResolverWorkContext workContext) throws ResolutionException { // compute SHA-1 Hash for eduPersonTargetedId: entityId of requester + uid + "string ... " relyingPartyId = resolutionContext.getAttributeRecipientID(); Map result = new HashMap(); String username = resolutionContext.getPrincipal(); IdPAttribute attribute = new IdPAttribute("eduPersonTargetedId"); result.put("eduPersonTargetedId", attribute); List> outputValues = new ArrayList<>(1); outputValues.add(new StringAttributeValue(getTargetedId(username))); attribute.setValues(outputValues); LOG.debug("Data connector added attribute: eduPersonTargetedId[" + getTargetedId(username) + "]"); return result; } private String getTargetedId(final String source) throws ResolutionException{ try { final MessageDigest md = MessageDigest.getInstance("SHA"); md.update(relyingPartyId.getBytes()); md.update((byte) '!'); md.update(source.getBytes()); md.update((byte) '!'); return Base64Support.encode(md.digest(salt.getBytes()), Base64Support.UNCHUNKED); } catch (final NoSuchAlgorithmException e) { LOG.error("Digest algorithm SHA is not supported"); throw new ResolutionException("Digest algorithm was not supported, unable to compute ID", e); } } }