1
2
3
4
5
6
7 package gov.bnl.gums;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 /*** Represent a GRID Identity in GUMS, which is a certificate with its DN and FQAN.
13 *
14 * @author Gabriele Carcassi
15 */
16 public class GridUser {
17 private Log log = LogFactory.getLog(GridUser.class);
18
19 private String certificateDN;
20 private FQAN voFQAN;
21
22 /***
23 * Creates a GRID credentail with no DN and FQAN.
24 */
25 public GridUser() {
26 }
27
28 /***
29 * Creates a new object representing a Grid credential.
30 * @param userDN the DN of the user certificate (i.e. "/DC=org/DC=doegrids/OU=People/CN=Gabriele Carcassi")
31 * @param fqan The Fully Qualified Attribute name String representation (i.e. "/atlas/production/Role=Leader")
32 */
33 public GridUser(String userDN, String fqan) {
34 setCertificateDN(userDN);
35 if (fqan != null)
36 setVoFQAN(new FQAN(fqan));
37 }
38
39 /***
40 * Retrieve the certificate DN of the user.
41 * @return The certificate DN (i.e. "/DC=org/DC=doegrids/OU=People/CN=Gabriele Carcassi")
42 */
43 public String getCertificateDN() {
44 return this.certificateDN;
45 }
46
47 /***
48 * Changes the certificate DN for the Grid credential.
49 * @param certificateDN A GRID certificate DN (i.e. "/DC=org/DC=doegrids/OU=People/CN=Gabriele Carcassi")
50 */
51 public void setCertificateDN(String certificateDN) {
52 this.certificateDN = certificateDN;
53 }
54
55 /***
56 * Retrieve the VOMS Fully Qualified Attribute name.
57 * @return The VOMS FQAN selected with voms-proxy-init (i.e. "/atlas/production/Role=Leader")
58 */
59 public FQAN getVoFQAN() {
60 return this.voFQAN;
61 }
62
63 /***
64 * Sets the VOMS Fully Qualified Attribute name for the credential.
65 * @param voFQAN The VOMS FQAN selected with voms-proxy-init (i.e. "/atlas/production/Role=Leader")
66 */
67 public void setVoFQAN(FQAN voFQAN) {
68 this.voFQAN = voFQAN;
69 }
70
71 /***
72 * Changed to reflect the change in equals, as in Object contract.
73 * @return A hash created from the DN and FQAN.
74 */
75 public int hashCode() {
76 if (certificateDN != null) {
77 return certificateDN.hashCode();
78 }
79 if (voFQAN != null) {
80 return voFQAN.getFqan().hashCode();
81 }
82 return 0;
83 }
84
85 /***
86 * A GridUser will be equal only to another GridUser with the same DN and FQAN.
87 * @param obj another object
88 * @return true if the object was a GridUser with equivalent credentials
89 */
90 public boolean equals(Object obj) {
91 GridUser user = (GridUser) obj;
92 if ((user.getCertificateDN() == null) ? certificateDN != null : (!user.getCertificateDN().equals(certificateDN))) {
93 if (log.isTraceEnabled()) {
94 log.trace(this + " !equals " + obj + " for different DN");
95 }
96 return false;
97 }
98 if ((user.voFQAN == null) ? voFQAN != null : (!user.voFQAN.equals(voFQAN))) {
99 if (log.isTraceEnabled()) {
100 log.trace(this + " !equals " + obj + " for dirrent FQAN");
101 }
102 return false;
103 }
104 if (log.isTraceEnabled()) {
105 log.trace(this + " equals " + obj);
106 }
107 return true;
108 }
109
110 /***
111 * Returns a legible String representation for the credentail.
112 * @return String reprentation of the credential (i.e. "GridID[/DC=org/DC=doegrids/OU=People/CN=Gabriele Carcassi]")
113 */
114 public String toString() {
115 if (voFQAN == null) {
116 return "GridID[" + certificateDN + "]";
117 }
118 return "GridID[" + certificateDN + ", " + voFQAN + "]";
119 }
120
121 }