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.util.Arrays;
20
21 import org.opensaml.xml.util.DatatypeHelper;
22
23
24
25
26
27 public class SAML1ArtifactType0002 extends AbstractSAML1Artifact {
28
29
30 public static final byte[] TYPE_CODE = { 0, 2 };
31
32
33 private byte[] assertionHandle;
34
35
36 private String sourceLocation;
37
38
39 public SAML1ArtifactType0002() {
40 super(TYPE_CODE);
41 }
42
43
44
45
46
47
48
49
50
51
52 public SAML1ArtifactType0002(byte[] handle, String location) {
53 super(TYPE_CODE);
54
55 setAssertionHandle(handle);
56 setSourceLocation(location);
57 }
58
59
60
61
62
63
64
65
66
67 public static SAML1ArtifactType0002 parseArtifact(byte[] artifact) {
68 byte[] typeCode = { artifact[0], artifact[1] };
69 if (!Arrays.equals(typeCode, TYPE_CODE)) {
70 throw new IllegalArgumentException("Artifact is not of appropriate type.");
71 }
72
73 byte[] assertionHandle = new byte[20];
74 System.arraycopy(artifact, 2, assertionHandle, 0, 20);
75
76 int locationLength = artifact.length - 22;
77 byte[] sourceLocation = new byte[locationLength];
78 System.arraycopy(artifact, 22, sourceLocation, 0, locationLength);
79
80 return new SAML1ArtifactType0002(assertionHandle, new String(sourceLocation));
81 }
82
83
84
85
86
87
88 public byte[] getAssertionHandle() {
89 return assertionHandle;
90 }
91
92
93
94
95
96
97 public void setAssertionHandle(byte[] handle) {
98 if (handle.length != 20) {
99 throw new IllegalArgumentException("Artifact assertion handle must be 20 bytes long");
100 }
101 assertionHandle = handle;
102 }
103
104
105
106
107
108
109 public String getSourceLocation() {
110 return sourceLocation;
111 }
112
113
114
115
116
117
118
119
120 protected void setSourceLocation(String newLocation) {
121 String location = DatatypeHelper.safeTrimOrNullString(newLocation);
122 if (location == null) {
123 throw new IllegalArgumentException("Artifact source location may not be a null or empty string");
124 }
125
126 sourceLocation = location;
127 }
128
129
130 public byte[] getRemainingArtifact() {
131 byte[] location = getSourceLocation().getBytes();
132 byte[] remainingArtifact = new byte[20 + location.length];
133
134 System.arraycopy(getAssertionHandle(), 0, remainingArtifact, 0, 20);
135 System.arraycopy(location, 0, remainingArtifact, 20, location.length);
136
137 return remainingArtifact;
138 }
139 }