Browse code

Fix: implement equals/hashcode

Thomas Fricker authored on 22/06/2017 08:15:12
Showing 1 changed files
... ...
@@ -32,11 +32,11 @@ public class SecurityContext {
32 32
 
33 33
 	public static final String ROLE_ADMIN = "admin";
34 34
 
35
-	public static final SecurityContext ANONYMOUS = new SecurityContext(null, "anonymous", Arrays.<String>asList(),
36
-			Arrays.<String>asList(), Collections.emptyMap(), null, "en", "internal-anonymous", false);
35
+	public static final SecurityContext ANONYMOUS = new SecurityContext(null, "anonymous", Arrays.<String> asList(),
36
+			Arrays.<String> asList(), Collections.emptyMap(), null, "en", "internal-anonymous", false);
37 37
 
38
-	public static final SecurityContext SYSTEM = new SecurityContext(null, "system", Arrays.<String>asList(),
39
-			Arrays.<String>asList(ROLE_SYSTEM), Collections.emptyMap(), "global.virt", "en", "internal-system", false);
38
+	public static final SecurityContext SYSTEM = new SecurityContext(null, "system", Arrays.<String> asList(),
39
+			Arrays.<String> asList(ROLE_SYSTEM), Collections.emptyMap(), "global.virt", "en", "internal-system", false);
40 40
 
41 41
 	public static final String TOKEN_FAKE_DOMAIN = "token-fake-domain";
42 42
 
... ...
@@ -171,4 +171,75 @@ public class SecurityContext {
171 171
 	public void withRolesOnOrgUnit(String ouUid, Set<String> roles) {
172 172
 		orgUnitsRoles.put(ouUid, roles);
173 173
 	}
174
+
175
+	@Override
176
+	public int hashCode() {
177
+		final int prime = 31;
178
+		int result = 1;
179
+		result = prime * result + ((domainUid == null) ? 0 : domainUid.hashCode());
180
+		result = prime * result + (interactive ? 1231 : 1237);
181
+		result = prime * result + ((lang == null) ? 0 : lang.hashCode());
182
+		result = prime * result + ((memberOf == null) ? 0 : memberOf.hashCode());
183
+		result = prime * result + ((orgUnitsRoles == null) ? 0 : orgUnitsRoles.hashCode());
184
+		result = prime * result + ((origin == null) ? 0 : origin.hashCode());
185
+		result = prime * result + ((roles == null) ? 0 : roles.hashCode());
186
+		result = prime * result + ((sessionId == null) ? 0 : sessionId.hashCode());
187
+		result = prime * result + ((subject == null) ? 0 : subject.hashCode());
188
+		return result;
189
+	}
190
+
191
+	@Override
192
+	public boolean equals(Object obj) {
193
+		if (this == obj)
194
+			return true;
195
+		if (obj == null)
196
+			return false;
197
+		if (getClass() != obj.getClass())
198
+			return false;
199
+		SecurityContext other = (SecurityContext) obj;
200
+		if (domainUid == null) {
201
+			if (other.domainUid != null)
202
+				return false;
203
+		} else if (!domainUid.equals(other.domainUid))
204
+			return false;
205
+		if (interactive != other.interactive)
206
+			return false;
207
+		if (lang == null) {
208
+			if (other.lang != null)
209
+				return false;
210
+		} else if (!lang.equals(other.lang))
211
+			return false;
212
+		if (memberOf == null) {
213
+			if (other.memberOf != null)
214
+				return false;
215
+		} else if (!memberOf.equals(other.memberOf))
216
+			return false;
217
+		if (orgUnitsRoles == null) {
218
+			if (other.orgUnitsRoles != null)
219
+				return false;
220
+		} else if (!orgUnitsRoles.equals(other.orgUnitsRoles))
221
+			return false;
222
+		if (origin == null) {
223
+			if (other.origin != null)
224
+				return false;
225
+		} else if (!origin.equals(other.origin))
226
+			return false;
227
+		if (roles == null) {
228
+			if (other.roles != null)
229
+				return false;
230
+		} else if (!roles.equals(other.roles))
231
+			return false;
232
+		if (sessionId == null) {
233
+			if (other.sessionId != null)
234
+				return false;
235
+		} else if (!sessionId.equals(other.sessionId))
236
+			return false;
237
+		if (subject == null) {
238
+			if (other.subject != null)
239
+				return false;
240
+		} else if (!subject.equals(other.subject))
241
+			return false;
242
+		return true;
243
+	}
244
+
174 245
 }