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