1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.shared.kerberos.components;
21
22 import java.security.MessageDigest;
23 import java.util.Arrays;
24
25 import org.apache.directory.api.util.Strings;
26 import org.apache.directory.shared.kerberos.codec.types.AuthorizationType;
27
28
29
30
31
32
33 public class AuthorizationDataEntry
34 {
35
36 private AuthorizationType adType;
37
38
39 private byte[] adData;
40
41
42
43
44
45 public AuthorizationDataEntry()
46 {
47
48 }
49
50
51
52
53
54
55
56
57 public AuthorizationDataEntry( AuthorizationType adType, byte[] adData )
58 {
59 this.adType = adType;
60
61 if ( adData != null )
62 {
63 this.adData = new byte[adData.length];
64 System.arraycopy( adData, 0, this.adData, 0, adData.length );
65 }
66 }
67
68
69
70
71
72 public AuthorizationType getAdType()
73 {
74 return adType;
75 }
76
77
78
79
80
81 public void setAdType( AuthorizationType adType )
82 {
83 this.adType = adType;
84 }
85
86
87
88
89
90 public byte[] getAdData()
91 {
92 if ( Strings.isEmpty( adData ) )
93 {
94 return Strings.EMPTY_BYTES;
95 }
96 else
97 {
98 byte[] copy = new byte[adData.length];
99
100 System.arraycopy( adData, 0, copy, 0, adData.length );
101
102 return copy;
103 }
104 }
105
106
107
108
109
110 public byte[] getAdDataRef()
111 {
112 return adData;
113 }
114
115
116
117
118
119 public void setAdData( byte[] adData )
120 {
121 if ( Strings.isEmpty( adData ) )
122 {
123 this.adData = Strings.EMPTY_BYTES;
124 }
125 else
126 {
127 this.adData = new byte[adData.length];
128
129 System.arraycopy( adData, 0, this.adData, 0, adData.length );
130 }
131 }
132
133
134
135
136
137 @Override
138 public int hashCode()
139 {
140 final int prime = 31;
141 int result = 17;
142 result = prime * result + Arrays.hashCode( adData );
143 result = prime * result + ( ( adType == null ) ? 0 : adType.hashCode() );
144 return result;
145 }
146
147
148
149
150
151 @Override
152 public boolean equals( Object obj )
153 {
154 if ( this == obj )
155 {
156 return true;
157 }
158
159 if ( !( obj instanceof AuthorizationDataEntry ) )
160 {
161 return false;
162 }
163
164 AuthorizationDataEntry./org/apache/directory/shared/kerberos/components/AuthorizationDataEntry.html#AuthorizationDataEntry">AuthorizationDataEntry other = ( AuthorizationDataEntry ) obj;
165
166 if ( !MessageDigest.isEqual( adData, other.adData ) )
167 {
168 return false;
169 }
170
171 return adType == other.adType;
172 }
173
174
175
176
177
178 public String toString( String tabs )
179 {
180 StringBuilder sb = new StringBuilder();
181
182 sb.append( tabs ).append( "AuthorizationDataEntry : {\n" );
183 sb.append( tabs ).append( " adType : " ).append( adType ).append( "\n" );
184 sb.append( tabs ).append( " adData : " ).append( Strings.dumpBytes( adData ) ).append( "\n" );
185 sb.append( tabs ).append( "}" );
186 return sb.toString();
187 }
188
189
190
191
192
193 public String toString()
194 {
195 return toString( "" );
196 }
197 }