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.MessageDigest;
20 import java.security.NoSuchAlgorithmException;
21 import java.security.SecureRandom;
22
23 import org.opensaml.common.binding.SAMLMessageContext;
24 import org.opensaml.saml1.core.Assertion;
25 import org.opensaml.saml1.core.NameIdentifier;
26 import org.opensaml.saml1.core.RequestAbstractType;
27 import org.opensaml.saml1.core.Response;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31
32
33
34 public class SAML1ArtifactType0001Builder implements SAML1ArtifactBuilder<SAML1ArtifactType0001> {
35
36
37 private final Logger log = LoggerFactory.getLogger(SAML1ArtifactType0001Builder.class);
38
39
40 public SAML1ArtifactType0001 buildArtifact(byte[] artifact) {
41 return SAML1ArtifactType0001.parseArtifact(artifact);
42 }
43
44
45 public SAML1ArtifactType0001 buildArtifact(
46 SAMLMessageContext<RequestAbstractType, Response, NameIdentifier> requestContext, Assertion assertion) {
47 try {
48 MessageDigest sha1Digester = MessageDigest.getInstance("SHA-1");
49 byte[] source = sha1Digester.digest(requestContext.getLocalEntityId().getBytes());
50
51 SecureRandom handleGenerator = SecureRandom.getInstance("SHA1PRNG");
52 byte[] assertionHandle = new byte[20];
53 handleGenerator.nextBytes(assertionHandle);
54
55 return new SAML1ArtifactType0001(source, assertionHandle);
56 } catch (NoSuchAlgorithmException e) {
57 log.error("JVM does not support required cryptography algorithms.", e);
58 throw new InternalError("JVM does not support required cryptography algorithms: SHA-1 and/or SHA1PRNG.");
59 }
60 }
61 }