public static Subject createSubject(NameID nameId) { Subject subject = subjectBuilder.buildObject(); subject.setNameID(nameId); return subject; }
/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) { int count = 0; for (final Assertion assertion : response.getAssertions()) { final Subject subject = getAssertionSubject(assertion); final NameID existing = subject.getNameID(); if (existing == null || overwriteExisting) { subject.setNameID(cloneNameID()); count ++; } } if (count > 0) { log.debug("{} Added NameID to {} assertion(s)", getLogPrefix(), count); } }
/** {@inheritDoc} */ protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException { Subject subject = (Subject) parentObject; if (childObject instanceof BaseID) { subject.setBaseID((BaseID) childObject); } else if (childObject instanceof NameID) { subject.setNameID((NameID) childObject); } else if (childObject instanceof EncryptedID) { subject.setEncryptedID((EncryptedID) childObject); } else if (childObject instanceof SubjectConfirmation) { subject.getSubjectConfirmations().add((SubjectConfirmation) childObject); } else { super.processChildElement(parentObject, childObject); } } }
/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) { final NameID nameId = generateNameID(profileRequestContext); if (nameId == null) { if (requiredFormat != null) { log.warn("{} Request specified use of an unsupportable identifier format: {}", getLogPrefix(), requiredFormat); ActionSupport.buildEvent(profileRequestContext, SAMLEventIds.INVALID_NAMEID_POLICY); } else { log.debug("{} Unable to generate a NameID, leaving empty", getLogPrefix()); } return; } int count = 0; for (final Assertion assertion : assertions) { final Subject subject = getAssertionSubject(assertion); final NameID existing = subject.getNameID(); if (existing == null || overwriteExisting) { subject.setNameID(count > 0 ? cloneNameID(nameId) : nameId); } count ++; } if (count > 0) { log.debug("{} Added NameID to {} assertion subject(s)", getLogPrefix(), count); } }
subject.setNameID(null); subject.getSubjectConfirmations().forEach(c -> c.setNameID(null));
final NameID decrypted = processEncryptedID(profileRequestContext, subject.getEncryptedID()); if (decrypted != null) { subject.setNameID(decrypted); subject.setEncryptedID(null);
/** * Encrypt any {@link NameID}s found in a subject and replace them with the result. * * @param subject subject to operate on * * @throws EncryptionException if an error occurs */ private void processSubject(@Nullable final Subject subject) throws EncryptionException { if (subject != null) { if (shouldEncrypt(subject.getNameID())) { log.debug("{} Encrypt NameID in Subject", getLogPrefix()); final EncryptedID encrypted = getEncrypter().encrypt(subject.getNameID()); subject.setEncryptedID(encrypted); subject.setNameID(null); } for (final SubjectConfirmation sc : subject.getSubjectConfirmations()) { if (shouldEncrypt(sc.getNameID())) { log.debug("{} Encrypt NameID in SubjectConfirmation", getLogPrefix()); final EncryptedID encrypted = getEncrypter().encrypt(sc.getNameID()); sc.setEncryptedID(encrypted); sc.setNameID(null); } } } }
/** * New subject element. * * @param nameIdFormat the name id format * @param nameIdValue the name id value * @param recipient the recipient * @param notOnOrAfter the not on or after * @param inResponseTo the in response to * @return the subject */ public Subject newSubject(final String nameIdFormat, final String nameIdValue, final String recipient, final DateTime notOnOrAfter, final String inResponseTo) { final SubjectConfirmation confirmation = newSamlObject(SubjectConfirmation.class); confirmation.setMethod(SubjectConfirmation.METHOD_BEARER); final SubjectConfirmationData data = newSamlObject(SubjectConfirmationData.class); data.setRecipient(recipient); data.setNotOnOrAfter(notOnOrAfter); data.setInResponseTo(inResponseTo); confirmation.setSubjectConfirmationData(data); final Subject subject = newSamlObject(Subject.class); subject.setNameID(getNameID(nameIdFormat, nameIdValue)); subject.getSubjectConfirmations().add(confirmation); return subject; }
subject.setNameID(nameID);
nameId.setFormat(NameIdentifier.EMAIL); subject.setNameID(nameId);
subject.setNameID(nameId);
buildSAMLObject(org.opensaml.saml.saml2.core.Subject.class); a.setSubject(subject); subject.setNameID(nid); subject.getSubjectConfirmations().add(confirmation);