01: /*
02: * JFolder, Copyright 2001-2006 Gary Steinmetz
03: *
04: * Distributable under LGPL license.
05: * See terms of license at gnu.org.
06: */
07:
08: package org.jfolder.security.model;
09:
10: //base classes
11:
12: //project specific classes
13:
14: //other classes
15:
16: public class UserIdentityHelper {
17:
18: private UserIdentityHelper() {
19: }
20:
21: public final static boolean isSameUserIdentity(
22: UserIdentity inFirstUi, UserIdentity inSecondUi) {
23: //
24: boolean outValue = true;
25:
26: if (inFirstUi != null && inSecondUi != null) {
27: //
28: String firstSecurityType = inFirstUi.getSecurityType();
29: String secondSecurityType = inSecondUi.getSecurityType();
30: //
31: String firstName = inFirstUi.getName();
32: String secondName = inSecondUi.getName();
33: //
34: if (firstSecurityType != null && secondSecurityType != null) {
35: //
36: if (firstName != null && secondName != null) {
37: //
38: outValue = (firstSecurityType
39: .equals(secondSecurityType)
40: && (firstName.equals(secondName))
41: && (inFirstUi.isAnonymous() == inSecondUi
42: .isAnonymous()) && (inFirstUi
43: .isValid() == inSecondUi.isValid()));
44: } else {
45: outValue = false;
46: }
47: } else {
48: outValue = false;
49: }
50: } else {
51: outValue = false;
52: }
53:
54: return outValue;
55: }
56:
57: public final static int getUserIdentityHashCode(UserIdentity inUi) {
58:
59: int outValue = 0;
60:
61: //
62: if (inUi.getSecurityType() != null) {
63: outValue = outValue + inUi.getSecurityType().hashCode();
64: }
65: //
66: if (inUi.getName() != null) {
67: outValue = outValue + inUi.getName().hashCode();
68: }
69: //
70: if (inUi.isAnonymous()) {
71: outValue++;
72: }
73: //
74: if (inUi.isValid()) {
75: outValue++;
76: }
77:
78: return outValue;
79: }
80: }
|