1 /*
2 * The MIT License
3 *
4 * Original work sponsored and donated by National Board of e-Health (NSI), Denmark (http://www.nsi.dk)
5 *
6 * Copyright (C) 2011 National Board of e-Health (NSI), Denmark (http://www.nsi.dk)
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy of
9 * this software and associated documentation files (the "Software"), to deal in
10 * the Software without restriction, including without limitation the rights to
11 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 * of the Software, and to permit persons to whom the Software is furnished to do
13 * so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in all
16 * copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 * $HeadURL: https://svn.softwareborsen.dk/sosi/trunk/modules/seal/src/main/java/dk/sosi/seal/model/UserIDCard.java $
27 * $Id: UserIDCard.java 8697 2011-09-02 10:33:55Z chg@lakeside.dk $
28 */
29 package dk.sosi.seal.model;
30
31 import org.w3c.dom.Element;
32
33 import java.util.Date;
34
35 /**
36 * Represents personal ID-cards. This type includes both information about the
37 * user and the system through which the user is requesting the ID-card.
38 *
39 * @author Jan Riis
40 * @author $LastChangedBy: chg@lakeside.dk $
41 * @since 1.0
42 */
43 public class UserIDCard extends SystemIDCard {
44 private static final long serialVersionUID = -3844876145617148725L;
45
46 private final UserInfo userInfo;
47
48 // ===============================
49 // Constructors
50 // ===============================
51
52 /**
53 * Creates a brand new <code>UserIDCard</code> (no deserialization).
54 * @param version
55 * The version of this IDCard, corresponds to DGWS version
56 * @param authenticationLevel
57 * The level of trust a system can have to this ID card.
58 * @param issuer
59 * A <code>String</code> representing the system that issues
60 * the ID-Card
61 * @param systemInfo
62 * A reference to a <code>SystemInfo</code> object containing
63 * information about the system the user is operating on
64 * @param userInfo
65 * A reference to a <code>UserInfo</code> object containing
66 * specific information about the user
67 * @param certHash
68 * A SHA-1 digest of the certificate that can validate this
69 * ID-card. May be <code>null</code>.
70 * @param alternativeIdentifier
71 * A <code>String</code> denoting an alternative identifier that
72 * will be used as SAML Subject (of type medcom:other) when serializing
73 * this IDCard instead. May be <code>null</null>.
74 * @param username
75 * The username to employ when creating an idcard with authenticationLeve 2. May be <code>null</code>.
76 * @param password
77 * The password to employ when creating an idcard with authenticationLeve 2. May be <code>null</code>.
78 */
79 public UserIDCard(String version, AuthenticationLevel authenticationLevel, String issuer, SystemInfo systemInfo, UserInfo userInfo, String certHash, String alternativeIdentifier, String username, String password) {
80
81 super(version, authenticationLevel, issuer, systemInfo, certHash, alternativeIdentifier, username, password);
82 ModelUtil.validateNotNull(userInfo, "UserInfo must be specified");
83 this.userInfo = userInfo;
84 }
85
86 /**
87 * Creates a new <code>UserIDCard</code> from deserializing a DOM element.
88 * @param version
89 * The version of this IDCard, corresponds to DGWS version
90 * @param domElement
91 * A reference to the DOM element that contains the values for
92 * this ID card.
93 * @param cardID
94 * The unmarshalled card ID.
95 * @param authenticationLevel
96 * The level of trust a system can have to this ID card.
97 * @param certHash
98 * A secure Hash value (SHA-1) of the certificate that has been
99 * used to verify the credentials when issuing this IDCard.
100 * @param issuer
101 * A <code>String</code> representing the system that issues
102 * the ID-Card
103 * @param userInfo
104 * A reference to the unmarshalled <code>UserInfo</code> object
105 * containing specific information about the user
106 * @param createdDate
107 * The expirydate (and time) for this IDCard
108 * @param expiryDate
109 * The creationdate (and time) for this IDCard
110 * @param alternativeIdentifier
111 * The unmarshalled alternative identifier for this <code>IDCard</code>
112 * or <code>null</code>.
113 * @param username
114 * The username to employ when creating an idcard with authenticationLeve 2. May be <code>null</code>.
115 * @param password
116 * The password to employ when creating an idcard with authenticationLeve 2. May be <code>null</code>.
117 */
118 public UserIDCard(String version, Element domElement, String cardID, AuthenticationLevel authenticationLevel, String certHash, String issuer,
119 SystemInfo systemInfo, UserInfo userInfo, Date createdDate, Date expiryDate, String alternativeIdentifier, String username, String password) {
120
121 super(version, domElement, cardID, authenticationLevel, certHash, issuer, systemInfo, createdDate, expiryDate, alternativeIdentifier, username, password);
122 ModelUtil.validateNotNull(userInfo, "UserInfo must be specified");
123 this.userInfo = userInfo;
124 }
125
126 /**
127 * Creates a new <code>UserIDCard</code> using an existing UserIDCard.
128 *
129 * @param original
130 * the <code>UserIDCard</code> to copy
131 * @param issuer
132 * A <code>String</code> representing the system that issues
133 * the ID-Card
134 */
135 public UserIDCard(UserIDCard original, String issuer) {
136 this(original, issuer, null);
137 }
138
139 /**
140 * Creates a new <code>UserIDCard</code> using an existing UserIDCard.
141 *
142 * @param original
143 * the <code>UserIDCard</code> to copy
144 * @param issuer
145 * A <code>String</code> representing the system that issues
146 * the ID-Card
147 * @param cpr
148 * optional cpr to add if origCard doesnt contain it
149 */
150 public UserIDCard(UserIDCard original, String issuer, String cpr) {
151 super(original, issuer);
152 this.userInfo = handleUserInfo(original, cpr);
153 }
154
155 /**
156 * Creates a new <code>UserIDCard</code> using an existing UserIDCard.
157 *
158 * @param original
159 * the <code>UserIDCard</code> to copy
160 * @param issuer
161 * A <code>String</code> representing the system that issues
162 * the ID-Card
163 * @param cpr
164 * optional cpr to add if origCard doesnt contain it
165 * @param certHash
166 * The hash code of the certificate that was used as credentials
167 * for the issuance this IDCard. May be <code>null</code>.
168 */
169 public UserIDCard(UserIDCard original, String issuer, String cpr, String certHash) {
170 super(original, issuer, certHash);
171 this.userInfo = handleUserInfo(original, cpr);
172 }
173
174 /**
175 * Creates a new <code>UserIDCard</code> using an existing UserIDCard.
176 *
177 * @param original
178 * the <code>UserIDCard</code> to copy
179 * @param issuer
180 * A <code>String</code> representing the system that issues
181 * the ID-Card
182 * @param newUserInfo
183 * optional newUserInfo to use instead of th original info set on the original UserIDCard
184 * @param certHash
185 * The hash code of the certificate that was used as credentials
186 * for the issuance this IDCard. May be <code>null</code>.
187 */
188 public UserIDCard(UserIDCard original, String issuer, UserInfo newUserInfo, String certHash) {
189 super(original, issuer, certHash);
190 this.userInfo = newUserInfo != null ? newUserInfo : original.userInfo;
191 }
192
193 /**
194 * Handles UserInfo creation
195 */
196 private static UserInfo handleUserInfo(UserIDCard original, String cpr) {
197 if(cpr == null || "".equals(cpr))
198 return original.getUserInfo();
199 else {
200 UserInfo ui = original.getUserInfo();
201 return new UserInfo(ui, cpr);
202 }
203 }
204
205 // ===============================
206 // Public methods
207 // ===============================
208
209 /**
210 * Returns information about the user, that this <code>UserIDCard</code>
211 * represents.
212 */
213 public UserInfo getUserInfo() {
214
215 return userInfo;
216 }
217
218 // ==========================================
219 // Overridden parts
220 // ==========================================
221
222 public boolean equals(Object obj) { // NOPMD
223
224 return super.equals(obj) && obj.getClass() == getClass() && getUserInfo().equals(((UserIDCard) obj).getUserInfo());
225 }
226 }