Skip to content

Commit 0c696dd

Browse files
committed
Remove XSAnyMarshaller AttributeValue Support
In favor of customizing the authentication converter Closes gh-8864
1 parent 7b3dda1 commit 0c696dd

File tree

3 files changed

+3
-50
lines changed

3 files changed

+3
-50
lines changed

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/authentication/OpenSamlAuthenticationProvider.java

+1-17
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,13 @@
3434

3535
import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
3636
import net.shibboleth.utilities.java.support.xml.ParserPool;
37-
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
3837
import org.apache.commons.logging.Log;
3938
import org.apache.commons.logging.LogFactory;
4039
import org.joda.time.DateTime;
4140
import org.opensaml.core.config.ConfigurationService;
4241
import org.opensaml.core.criterion.EntityIdCriterion;
4342
import org.opensaml.core.xml.XMLObject;
4443
import org.opensaml.core.xml.config.XMLObjectProviderRegistry;
45-
import org.opensaml.core.xml.io.Marshaller;
46-
import org.opensaml.core.xml.io.MarshallingException;
4744
import org.opensaml.core.xml.schema.XSAny;
4845
import org.opensaml.core.xml.schema.XSBoolean;
4946
import org.opensaml.core.xml.schema.XSBooleanValue;
@@ -520,7 +517,7 @@ private Map<String, List<Object>> getAssertionAttributes(Assertion assertion) {
520517

521518
private Object getXmlObjectValue(XMLObject xmlObject) {
522519
if (xmlObject instanceof XSAny) {
523-
return getXSAnyObjectValue((XSAny) xmlObject);
520+
return ((XSAny) xmlObject).getTextContent();
524521
}
525522
if (xmlObject instanceof XSString) {
526523
return ((XSString) xmlObject).getValue();
@@ -542,19 +539,6 @@ private Object getXmlObjectValue(XMLObject xmlObject) {
542539
return null;
543540
}
544541

545-
private Object getXSAnyObjectValue(XSAny xsAny) {
546-
Marshaller marshaller = this.registry.getMarshallerFactory().getMarshaller(xsAny);
547-
if (marshaller != null) {
548-
try {
549-
Element element = marshaller.marshall(xsAny);
550-
return SerializeSupport.nodeToString(element);
551-
} catch (MarshallingException e) {
552-
throw new Saml2Exception(e);
553-
}
554-
}
555-
return xsAny.getTextContent();
556-
}
557-
558542
private static class SignatureTrustEngineConverter implements Converter<Saml2AuthenticationToken, SignatureTrustEngine> {
559543

560544
@Override

saml2/saml2-service-provider/src/test/java/org/springframework/security/saml2/provider/service/authentication/OpenSamlAuthenticationProviderTests.java

-32
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@
4141
import org.junit.Test;
4242
import org.junit.rules.ExpectedException;
4343
import org.opensaml.core.xml.XMLObject;
44-
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
4544
import org.opensaml.core.xml.io.Marshaller;
4645
import org.opensaml.core.xml.io.MarshallingException;
4746
import org.opensaml.saml.common.assertion.ValidationContext;
4847
import org.opensaml.saml.saml2.core.Assertion;
4948
import org.opensaml.saml.saml2.core.AttributeStatement;
50-
import org.opensaml.saml.saml2.core.AttributeValue;
5149
import org.opensaml.saml.saml2.core.EncryptedAssertion;
5250
import org.opensaml.saml.saml2.core.EncryptedID;
5351
import org.opensaml.saml.saml2.core.NameID;
@@ -257,29 +255,6 @@ public void authenticateWhenAssertionContainsAttributesThenItSucceeds() {
257255
assertThat(principal.getAttributes()).isEqualTo(expected);
258256
}
259257

260-
@Test
261-
public void authenticateWhenAttributeValueMarshallerConfiguredThenUses() throws Exception {
262-
Response response = response();
263-
Assertion assertion = assertion();
264-
List<AttributeStatement> attributes = attributeStatements();
265-
assertion.getAttributeStatements().addAll(attributes);
266-
signed(assertion, assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
267-
response.getAssertions().add(assertion);
268-
Saml2AuthenticationToken token = token(response, relyingPartyVerifyingCredential());
269-
270-
Element attributeElement = element("<element>value</element>");
271-
Marshaller marshaller = mock(Marshaller.class);
272-
when(marshaller.marshall(any(XMLObject.class))).thenReturn(attributeElement);
273-
274-
try {
275-
XMLObjectProviderRegistrySupport.getMarshallerFactory().registerMarshaller(AttributeValue.DEFAULT_ELEMENT_NAME, marshaller);
276-
this.provider.authenticate(token);
277-
verify(marshaller, atLeastOnce()).marshall(any(XMLObject.class));
278-
} finally {
279-
XMLObjectProviderRegistrySupport.getMarshallerFactory().deregisterMarshaller(AttributeValue.DEFAULT_ELEMENT_NAME);
280-
}
281-
}
282-
283258
@Test
284259
public void authenticateWhenEncryptedAssertionWithoutSignatureThenItFails() throws Exception {
285260
this.exception.expect(authenticationMatcher(Saml2ErrorCodes.INVALID_SIGNATURE));
@@ -504,11 +479,4 @@ private Saml2AuthenticationToken token(String payload, Saml2X509Credential... cr
504479
return new Saml2AuthenticationToken(payload,
505480
DESTINATION, ASSERTING_PARTY_ENTITY_ID, RELYING_PARTY_ENTITY_ID, Arrays.asList(credentials));
506481
}
507-
508-
private static Element element(String xml) throws Exception {
509-
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
510-
DocumentBuilder builder = factory.newDocumentBuilder();
511-
Document doc = builder.parse(new InputSource(new StringReader(xml)));
512-
return doc.getDocumentElement();
513-
}
514482
}

saml2/saml2-service-provider/src/test/java/org/springframework/security/saml2/provider/service/authentication/TestOpenSamlObjects.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ static List<AttributeStatement> attributeStatements() {
312312

313313
Attribute emailAttr = attributeBuilder.buildObject();
314314
emailAttr.setName("email");
315-
XSAny email1 = new XSAnyBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
315+
XSAny email1 = new XSAnyBuilder()
316+
.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSAny.TYPE_NAME); // gh-8864
316317
email1.setTextContent("[email protected]");
317318
emailAttr.getAttributeValues().add(email1);
318319
XSAny email2 = new XSAnyBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);

0 commit comments

Comments
 (0)