1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.saml2.binding.artifact;
18
19 import java.util.Arrays;
20
21
22
23
24
25 public class SAML2ArtifactType0004 extends AbstractSAML2Artifact {
26
27
28 public static final byte[] TYPE_CODE = { 0, 4 };
29
30
31 private byte[] sourceID;
32
33
34 private byte[] messageHandle;
35
36
37 public SAML2ArtifactType0004() {
38 super(TYPE_CODE);
39 }
40
41
42
43
44
45
46
47
48
49
50
51 public SAML2ArtifactType0004(byte[] endpointIndex, byte[] source, byte[] handle) {
52 super(TYPE_CODE, endpointIndex);
53 setSourceID(source);
54 setMessageHandle(handle);
55 }
56
57
58
59
60
61
62
63
64
65
66 public static SAML2ArtifactType0004 parseArtifact(byte[] artifact) {
67 if (artifact.length != 44) {
68 throw new IllegalArgumentException("Artifact length must be 44 bytes it was " + artifact.length + "bytes");
69 }
70
71 byte[] typeCode = { artifact[0], artifact[1] };
72 if (!Arrays.equals(typeCode, TYPE_CODE)) {
73 throw new IllegalArgumentException("Illegal artifact type code");
74 }
75
76 byte[] endpointIndex = { artifact[2], artifact[3] };
77
78 byte[] sourceID = new byte[20];
79 System.arraycopy(artifact, 4, sourceID, 0, 20);
80
81 byte[] messageHandle = new byte[20];
82 System.arraycopy(artifact, 24, messageHandle, 0, 20);
83
84 return new SAML2ArtifactType0004(endpointIndex, sourceID, messageHandle);
85 }
86
87
88
89
90
91
92 public byte[] getSourceID() {
93 return sourceID;
94 }
95
96
97
98
99
100
101
102
103 public void setSourceID(byte[] newSourceID) {
104 if (newSourceID.length != 20) {
105 throw new IllegalArgumentException("Artifact source ID must be 20 bytes long");
106 }
107 sourceID = newSourceID;
108 }
109
110
111
112
113
114
115 public byte[] getMessageHandle() {
116 return messageHandle;
117 }
118
119
120
121
122
123
124 public void setMessageHandle(byte[] handle) {
125 if (handle.length != 20) {
126 throw new IllegalArgumentException("Artifact message handle must be 20 bytes long");
127 }
128 messageHandle = handle;
129 }
130
131
132 public byte[] getRemainingArtifact() {
133 byte[] remainingArtifact = new byte[40];
134
135 System.arraycopy(getSourceID(), 0, remainingArtifact, 0, 20);
136 System.arraycopy(getMessageHandle(), 0, remainingArtifact, 20, 20);
137
138 return remainingArtifact;
139 }
140 }