1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.saml1.binding.artifact;
18
19 import java.security.NoSuchAlgorithmException;
20 import java.security.SecureRandom;
21
22 import org.opensaml.common.binding.BasicEndpointSelector;
23 import org.opensaml.common.binding.SAMLMessageContext;
24 import org.opensaml.common.xml.SAMLConstants;
25 import org.opensaml.saml1.core.Assertion;
26 import org.opensaml.saml1.core.NameIdentifier;
27 import org.opensaml.saml1.core.RequestAbstractType;
28 import org.opensaml.saml1.core.Response;
29 import org.opensaml.saml2.metadata.ArtifactResolutionService;
30 import org.opensaml.saml2.metadata.Endpoint;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34
35
36
37 public class SAML1ArtifactType0002Builder implements SAML1ArtifactBuilder<SAML1ArtifactType0002> {
38
39
40 private final Logger log = LoggerFactory.getLogger(SAML1ArtifactType0002Builder.class);
41
42
43 public SAML1ArtifactType0002 buildArtifact(byte[] artifact) {
44 return SAML1ArtifactType0002.parseArtifact(artifact);
45 }
46
47
48 public SAML1ArtifactType0002 buildArtifact(
49 SAMLMessageContext<RequestAbstractType, Response, NameIdentifier> requestContext, Assertion assertion) {
50 try {
51 String sourceLocation = getSourceLocation(requestContext);
52 if (sourceLocation == null) {
53 return null;
54 }
55
56 SecureRandom handleGenerator = SecureRandom.getInstance("SHA1PRNG");
57 byte[] assertionHandle = new byte[20];
58 handleGenerator.nextBytes(assertionHandle);
59 return new SAML1ArtifactType0002(assertionHandle, sourceLocation);
60 } catch (NoSuchAlgorithmException e) {
61 log.error("JVM does not support required cryptography algorithms: SHA1PRNG.", e);
62 throw new InternalError("JVM does not support required cryptography algorithms: SHA1PRNG.");
63 }
64 }
65
66
67
68
69
70
71
72
73 protected String getSourceLocation(SAMLMessageContext<RequestAbstractType, Response, NameIdentifier> requestContext) {
74 BasicEndpointSelector selector = new BasicEndpointSelector();
75 selector.setEndpointType(ArtifactResolutionService.DEFAULT_ELEMENT_NAME);
76 selector.getSupportedIssuerBindings().add(SAMLConstants.SAML1_SOAP11_BINDING_URI);
77 selector.setMetadataProvider(requestContext.getMetadataProvider());
78 selector.setEntityMetadata(requestContext.getLocalEntityMetadata());
79 selector.setEntityRoleMetadata(requestContext.getLocalEntityRoleMetadata());
80
81 Endpoint acsEndpoint = selector.selectEndpoint();
82
83 if (acsEndpoint == null) {
84 log.error("Unable to select source location for artifact. No artifact resolution service defined for issuer.");
85 return null;
86 }
87
88 return acsEndpoint.getLocation();
89 }
90 }