001 /*
002 * Copyright 2011-2012 UnboundID Corp.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License (GPLv2 only)
006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
007 * as published by the Free Software Foundation.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program; if not, see <http://www.gnu.org/licenses>.
016 */
017
018 package com.unboundid.scim.data;
019
020 import com.unboundid.scim.schema.ResourceDescriptor;
021 import com.unboundid.scim.sdk.InvalidResourceException;
022 import com.unboundid.scim.sdk.SCIMConstants;
023 import com.unboundid.scim.sdk.SCIMObject;
024
025 import java.util.Collection;
026
027 /**
028 * This class represents a User resource.
029 */
030 public class UserResource extends BaseResource
031 {
032 /**
033 * A <code>ResourceFactory</code> for creating <code>UserResource</code>
034 * instances.
035 */
036 public static final ResourceFactory<UserResource> USER_RESOURCE_FACTORY =
037 new ResourceFactory<UserResource>() {
038 /**
039 * {@inheritDoc}
040 */
041 public UserResource createResource(
042 final ResourceDescriptor resourceDescriptor,
043 final SCIMObject scimObject) {
044 return new UserResource(resourceDescriptor, scimObject);
045 }
046 };
047
048 /**
049 * Construct an empty <code>UserResource</code> with the specified
050 * <code>ResourceDescriptor</code>.
051 *
052 * @param resourceDescriptor The resource descriptor for this SCIM resource.
053 */
054 public UserResource(final ResourceDescriptor resourceDescriptor) {
055 super(resourceDescriptor);
056 }
057
058 /**
059 * Construct a <code>UserResource</code> with the specified
060 * <code>ResourceDescriptor</code> and backed by the given
061 * <code>SCIMObject</code>.
062 *
063 * @param resourceDescriptor The resource descriptor for this SCIM resource.
064 * @param scimObject The <code>SCIMObject</code> containing all the
065 * SCIM attributes and their values.
066 */
067 public UserResource(final ResourceDescriptor resourceDescriptor,
068 final SCIMObject scimObject) {
069 super(resourceDescriptor, scimObject);
070 }
071
072 /**
073 * Retrieves the Unique identifier for the User, typically used by the user
074 * to directly authenticate to the service provider. Often displayed to the
075 * user as their unique identifier within the system (as opposed to id o
076 * r externalId, which are generally opaque and not user-friendly
077 * identifiers).
078 *
079 * @return The Unique identifier for the User.
080 */
081 public String getUserName()
082 {
083 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
084 "userName", AttributeValueResolver.STRING_RESOLVER);
085 }
086
087 /**
088 * Sets the Unique identifier for the User.
089 *
090 * @param userName The Unique identifier for the User
091 * @return this resource instance.
092 */
093 public UserResource setUserName(final String userName)
094 {
095 try {
096 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
097 "userName", AttributeValueResolver.STRING_RESOLVER, userName);
098 } catch (InvalidResourceException e) {
099 // This should never happen as these are core attributes...
100 throw new RuntimeException(e);
101 }
102 return this;
103 }
104
105 /**
106 * Retrieves the components of the User's real name.
107 *
108 * @return The components of the User's real name or <code>null</code> if
109 * it is not specified.
110 */
111 public Name getName()
112 {
113 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
114 "name", Name.NAME_RESOLVER);
115 }
116
117 /**
118 * Sets the components of the User's real name.
119 *
120 * @param name The components of the User's real name.
121 * @return this resource instance.
122 */
123 public UserResource setName(final Name name)
124 {
125 try {
126 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
127 "name", Name.NAME_RESOLVER, name);
128 } catch (InvalidResourceException e) {
129 // This should never happen as these are core attributes...
130 throw new RuntimeException(e);
131 }
132 return this;
133 }
134
135 /**
136 * Retrieves the name of the User, suitable for display to end-users.
137 *
138 * @return The name of the User, suitable for display to end-users or
139 * <code>null</code> if it is not specified.
140 */
141 public String getDisplayName()
142 {
143 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
144 "displayName", AttributeValueResolver.STRING_RESOLVER);
145 }
146
147 /**
148 * Sets the name of the User, suitable for display to end-users.
149 *
150 * @param displayName The name of the User, suitable for display to end-users.
151 * @return this resource instance.
152 */
153 public UserResource setDisplayName(final String displayName)
154 {
155 try {
156 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
157 "displayName", AttributeValueResolver.STRING_RESOLVER, displayName);
158 } catch (InvalidResourceException e) {
159 // This should never happen as these are core attributes...
160 throw new RuntimeException(e);
161 }
162 return this;
163 }
164
165 /**
166 * Retrieves the casual way to address the user in real life, e.g. "Bob" or
167 * "Bobby" instead of "Robert".
168 *
169 * @return The casual way to address the user in real life.
170 */
171 public String getNickName()
172 {
173 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
174 "nickName", AttributeValueResolver.STRING_RESOLVER);
175 }
176
177 /**
178 * Sets the casual way to address the user in real life, e.g. "Bob" or
179 * "Bobby" instead of "Robert".
180 *
181 * @param nickName The casual way to address the user in real life.
182 * @return this resource instance.
183 */
184 public UserResource setNickName(final String nickName)
185 {
186 try {
187 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
188 "nickName", AttributeValueResolver.STRING_RESOLVER, nickName);
189 } catch (InvalidResourceException e) {
190 // This should never happen as these are core attributes...
191 throw new RuntimeException(e);
192 }
193 return this;
194 }
195
196 /**
197 * Retrieves the URL to a page representing the User's online profile.
198 *
199 * @return The URL to a page representing the User's online profile or
200 * <code>null</code> if it is not specified.
201 */
202 public String getProfileUrl()
203 {
204 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
205 "profileUrl", AttributeValueResolver.STRING_RESOLVER);
206 }
207
208 /**
209 * Sets the URL to a page representing the User's online profile.
210 *
211 * @param url The URL to a page representing the User's online profile.
212 * @return this resource instance.
213 */
214 public UserResource setProfileUrl(final String url)
215 {
216 try {
217 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
218 "profileUrl", AttributeValueResolver.STRING_RESOLVER, url);
219 } catch (InvalidResourceException e) {
220 // This should never happen as these are core attributes...
221 throw new RuntimeException(e);
222 }
223 return this;
224 }
225
226 /**
227 * Retrieves the user's title, such as "Vice President".
228 *
229 * @return The user's title or <code>null</code> if it is not specified.
230 */
231 public String getTitle()
232 {
233 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
234 "title", AttributeValueResolver.STRING_RESOLVER);
235 }
236
237 /**
238 * Sets the user's title, such as "Vice President".
239 *
240 * @param title The user's title.
241 * @return this resource instance.
242 */
243 public UserResource setTitle(final String title)
244 {
245 try {
246 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
247 "title", AttributeValueResolver.STRING_RESOLVER, title);
248 } catch (InvalidResourceException e) {
249 // This should never happen as these are core attributes...
250 throw new RuntimeException(e);
251 }
252 return this;
253 }
254
255 /**
256 * Retrieves the the organization to user relationship. Typical values used
257 * might be "Contractor", "Employee", "Intern", "Temp", "External", and
258 * "Unknown" but any value may be used.
259 *
260 * @return The the organization to user relationship or <code>null</code>
261 * if it is not specified.
262 */
263 public String getUserType()
264 {
265 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
266 "userType", AttributeValueResolver.STRING_RESOLVER);
267 }
268
269 /**
270 * Sets the the organization to user relationship.
271 *
272 * @param userType The the organization to user relationship.
273 * @return this resource instance.
274 */
275 public UserResource setUserType(final String userType)
276 {
277 try {
278 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
279 "userType", AttributeValueResolver.STRING_RESOLVER, userType);
280 } catch (InvalidResourceException e) {
281 // This should never happen as these are core attributes...
282 throw new RuntimeException(e);
283 }
284 return this;
285 }
286
287 /**
288 * Retrieves the User's preferred written or spoken language. Generally
289 * used for localizing the interface presented to the user.
290 *
291 * @return The User's preferred written or spoken language or
292 * <code>null</code> if it is not specified.
293 */
294 public String getPreferredLanguage()
295 {
296 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
297 "preferredLanguage", AttributeValueResolver.STRING_RESOLVER);
298 }
299
300 /**
301 * Sets the User's preferred written or spoken language.
302 *
303 * @param language The User's preferred written or spoken language.
304 * @return this resource instance.
305 */
306 public UserResource setPreferredLanguage(final String language)
307 {
308 try {
309 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
310 "preferredLanguage", AttributeValueResolver.STRING_RESOLVER,
311 language);
312 } catch (InvalidResourceException e) {
313 // This should never happen as these are core attributes...
314 throw new RuntimeException(e);
315 }
316 return this;
317 }
318
319 /**
320 * Retrieves the User's default location for purposes of localizing items
321 * such as currency, date time format, numerical representations, etc.
322 *
323 * @return The User's default location for purposes of localizing items or
324 * <code>null</code> if it is not specified.
325 */
326 public String getLocale()
327 {
328 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
329 "locale", AttributeValueResolver.STRING_RESOLVER);
330 }
331
332 /**
333 * Sets the User's default location for purposes of localizing items.
334 *
335 * @param locale The User's default location for purposes of localizing items.
336 * @return this resource instance.
337 */
338 public UserResource setLocale(final String locale)
339 {
340 try {
341 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
342 "locale", AttributeValueResolver.STRING_RESOLVER, locale);
343 } catch (InvalidResourceException e) {
344 // This should never happen as these are core attributes...
345 throw new RuntimeException(e);
346 }
347 return this;
348 }
349
350 /**
351 * Retrieves the User's time zone in the public-domain time zone database
352 * format; e.g.,'America/Denver'.
353 *
354 * @return The User's time zone or <code>null</code> if it is not specified.
355 */
356 public String getTimeZone()
357 {
358 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
359 "timezone", AttributeValueResolver.STRING_RESOLVER);
360 }
361
362 /**
363 * Sets the User's time zone in the public-domain time zone database
364 * format; e.g.,'America/Denver'.
365 *
366 * @param timeZone The User's time zone
367 * @return this resource instance.
368 */
369 public UserResource setTimeZone(final String timeZone)
370 {
371 try {
372 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
373 "timezone", AttributeValueResolver.STRING_RESOLVER, timeZone);
374 } catch (InvalidResourceException e) {
375 // This should never happen as these are core attributes...
376 throw new RuntimeException(e);
377 }
378 return this;
379 }
380
381 /**
382 * Retrieves the User's administrative status.
383 *
384 * @return <code>true</code> if the User's administrative status is active or
385 * <code>false</code> otherwise or <code>null</code> if it is not
386 * specified.
387 */
388 public Boolean isActive()
389 {
390 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
391 "active", AttributeValueResolver.BOOLEAN_RESOLVER);
392 }
393
394 /**
395 * Sets the User's administrative status.
396 *
397 * @param active The User's administrative status.
398 * @return this resource instance.
399 */
400 public UserResource setActive(final Boolean active)
401 {
402 try {
403 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
404 "active", AttributeValueResolver.BOOLEAN_RESOLVER, active);
405 } catch (InvalidResourceException e) {
406 // This should never happen as these are core attributes...
407 throw new RuntimeException(e);
408 }
409 return this;
410 }
411
412 /**
413 * Retrieves the User's clear text password. This is intended to be used as a
414 * means to specify an initial password when creating a new User or to reset
415 * an existing User's password. This will never be returned by the service
416 * provider.
417 *
418 * @return The User's clear text password.
419 */
420 public String getPassword()
421 {
422 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
423 "password", AttributeValueResolver.STRING_RESOLVER);
424 }
425
426 /**
427 * Sets the User's clear text password.
428 *
429 * @param password The User's clear text password
430 * @return this resource instance.
431 */
432 public UserResource setPassword(final String password)
433 {
434 try {
435 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
436 "password", AttributeValueResolver.STRING_RESOLVER, password);
437 } catch (InvalidResourceException e) {
438 // This should never happen as these are core attributes...
439 throw new RuntimeException(e);
440 }
441 return this;
442 }
443
444 /**
445 * Retrieves the E-mail addresses for the User.
446 *
447 * @return The E-mail addresses for the User or <code>null</code> if it is
448 * not specified.
449 */
450 public Collection<Entry<String>> getEmails()
451 {
452 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
453 "emails", Entry.STRINGS_RESOLVER);
454 }
455
456 /**
457 * Sets the E-mail addresses for the User.
458 *
459 * @param emails The E-mail addresses for the User.
460 * @return this resource instance.
461 */
462 public UserResource setEmails(final Collection<Entry<String>> emails)
463 {
464 try {
465 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
466 "emails", Entry.STRINGS_RESOLVER, emails);
467 } catch (InvalidResourceException e) {
468 // This should never happen as these are core attributes...
469 throw new RuntimeException(e);
470 }
471 return this;
472 }
473
474 /**
475 * Retrieves the Phone numbers for the User.
476 *
477 * @return The Phone numbers for the User or <code>null</code>
478 * if it is not specified.
479 */
480 public Collection<Entry<String>> getPhoneNumbers()
481 {
482 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
483 "phoneNumbers", Entry.STRINGS_RESOLVER);
484 }
485
486 /**
487 * Sets the Phone numbers for the User.
488 *
489 * @param phoneNumbers The Phone numbers for the User.
490 * @return this resource instance.
491 */
492 public UserResource setPhoneNumbers(
493 final Collection<Entry<String>> phoneNumbers)
494 {
495 try {
496 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
497 "phoneNumbers", Entry.STRINGS_RESOLVER, phoneNumbers);
498 } catch (InvalidResourceException e) {
499 // This should never happen as these are core attributes...
500 throw new RuntimeException(e);
501 }
502 return this;
503 }
504
505 /**
506 * Retrieves the Instant messaging address for the User.
507 *
508 * @return The Instant messaging address for the User or <code>null</code>
509 * if it is not specified.
510 */
511 public Collection<Entry<String>> getIms()
512 {
513 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
514 "ims", Entry.STRINGS_RESOLVER);
515 }
516
517 /**
518 * Sets the Instant messaging address for the User.
519 *
520 * @param ims The Instant messaging address for the User.
521 * @return this resource instance.
522 */
523 public UserResource setIms(final Collection<Entry<String>> ims)
524 {
525 try {
526 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
527 "ims", Entry.STRINGS_RESOLVER, ims);
528 } catch (InvalidResourceException e) {
529 // This should never happen as these are core attributes...
530 throw new RuntimeException(e);
531 }
532 return this;
533 }
534
535 /**
536 * Retrieves the URL of a photo of the User.
537 *
538 * @return The URL of a photo of the User or <code>null</code> if
539 * it is not specified.
540 */
541 public Collection<Entry<String>> getPhotos()
542 {
543 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
544 "photos", Entry.STRINGS_RESOLVER);
545 }
546
547 /**
548 * Sets the URL of a photo of the User.
549 *
550 * @param photos The URL of a photo of the User.
551 * @return this resource instance.
552 */
553 public UserResource setPhotos(final Collection<Entry<String>> photos)
554 {
555 try {
556 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
557 "photos", Entry.STRINGS_RESOLVER, photos);
558 } catch (InvalidResourceException e) {
559 // This should never happen as these are core attributes...
560 throw new RuntimeException(e);
561 }
562 return this;
563 }
564
565 /**
566 * Retrieves the physical mailing address for this User.
567 *
568 * @return The physical mailing address for this User or <code>null</code> if
569 * it is not specified.
570 */
571 public Collection<Address> getAddresses()
572 {
573 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
574 "addresses", Address.ADDRESS_RESOLVER);
575 }
576
577 /**
578 * Sets the physical mailing address for this User.
579 *
580 * @param addresses The physical mailing address for this User.
581 * @return this resource instance.
582 */
583 public UserResource setAddresses(final Collection<Address> addresses)
584 {
585 try {
586 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
587 "addresses", Address.ADDRESS_RESOLVER, addresses);
588 } catch (InvalidResourceException e) {
589 // This should never happen as these are core attributes...
590 throw new RuntimeException(e);
591 }
592 return this;
593 }
594
595 /**
596 * Retrieves the list of groups that the user belongs to.
597 *
598 * @return The list of groups that the user belongs to or <code>null</code> if
599 * it is not specified.
600 */
601 public Collection<Entry<String>> getGroups()
602 {
603 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
604 "groups", Entry.STRINGS_RESOLVER);
605 }
606
607 /**
608 * Sets the list of groups that the user belongs to.
609 *
610 * @param groups The list of groups that the user belongs to.
611 * @return this resource instance.
612 */
613 public UserResource setGroups(final Collection<Entry<String>> groups)
614 {
615 try {
616 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
617 "groups", Entry.STRINGS_RESOLVER, groups);
618 } catch (InvalidResourceException e) {
619 // This should never happen as these are core attributes...
620 throw new RuntimeException(e);
621 }
622 return this;
623 }
624
625 /**
626 * Retrieves the list of entitlements for the User that represent a thing
627 * the User has. That is, an entitlement is an additional right to a thing,
628 * object or service.
629 *
630 * @return The list of entitlements for the User or <code>null</code> if
631 * it is not specified.
632 */
633 public Collection<Entry<String>> getEntitlements()
634 {
635 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
636 "entitlements", Entry.STRINGS_RESOLVER);
637 }
638
639 /**
640 * Sets the list of entitlements for the User.
641 *
642 * @param entitlements The list of entitlements for the User
643 * @return this resource instance.
644 */
645 public UserResource setEntitlements(
646 final Collection<Entry<String>> entitlements)
647 {
648 try {
649 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
650 "entitlements", Entry.STRINGS_RESOLVER, entitlements);
651 } catch (InvalidResourceException e) {
652 // This should never happen as these are core attributes...
653 throw new RuntimeException(e);
654 }
655 return this;
656 }
657
658 /**
659 * Retrieves the list of roles for the User that collectively represent who
660 * the User is; e.g., 'Student', "Faculty".
661 *
662 * @return The list of roles for the User or <code>null</code> if
663 * it is not specified.
664 */
665 public Collection<Entry<String>> getRoles()
666 {
667 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
668 "roles", Entry.STRINGS_RESOLVER);
669 }
670
671 /**
672 * Sets the list of roles for the User.
673 *
674 * @param roles The list of roles for the User.
675 * @return this resource instance.
676 */
677 public UserResource setRoles(final Collection<Entry<String>> roles)
678 {
679 try {
680 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
681 "roles", Entry.STRINGS_RESOLVER, roles);
682 } catch (InvalidResourceException e) {
683 // This should never happen as these are core attributes...
684 throw new RuntimeException(e);
685 }
686 return this;
687 }
688 }