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.
386 */
387 public boolean isActive()
388 {
389 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
390 "active", AttributeValueResolver.BOOLEAN_RESOLVER);
391 }
392
393 /**
394 * Sets the User's administrative status.
395 *
396 * @param active The User's administrative status.
397 * @return this resource instance.
398 */
399 public UserResource setActive(final boolean active)
400 {
401 try {
402 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
403 "active", AttributeValueResolver.BOOLEAN_RESOLVER, active);
404 } catch (InvalidResourceException e) {
405 // This should never happen as these are core attributes...
406 throw new RuntimeException(e);
407 }
408 return this;
409 }
410
411 /**
412 * Retrieves the User's clear text password. This is intended to be used as a
413 * means to specify an initial password when creating a new User or to reset
414 * an existing User's password. This will never be returned by the service
415 * provider.
416 *
417 * @return The User's clear text password.
418 */
419 public String getPassword()
420 {
421 return getSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
422 "password", AttributeValueResolver.STRING_RESOLVER);
423 }
424
425 /**
426 * Sets the User's clear text password.
427 *
428 * @param password The User's clear text password
429 * @return this resource instance.
430 */
431 public UserResource setPassword(final String password)
432 {
433 try {
434 setSingularAttributeValue(SCIMConstants.SCHEMA_URI_CORE,
435 "password", AttributeValueResolver.STRING_RESOLVER, password);
436 } catch (InvalidResourceException e) {
437 // This should never happen as these are core attributes...
438 throw new RuntimeException(e);
439 }
440 return this;
441 }
442
443 /**
444 * Retrieves the E-mail addresses for the User.
445 *
446 * @return The E-mail addresses for the User or <code>null</code> if it is
447 * not specified.
448 */
449 public Collection<Entry<String>> getEmails()
450 {
451 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
452 "emails", Entry.STRINGS_RESOLVER);
453 }
454
455 /**
456 * Sets the E-mail addresses for the User.
457 *
458 * @param emails The E-mail addresses for the User.
459 * @return this resource instance.
460 */
461 public UserResource setEmails(final Collection<Entry<String>> emails)
462 {
463 try {
464 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
465 "emails", Entry.STRINGS_RESOLVER, emails);
466 } catch (InvalidResourceException e) {
467 // This should never happen as these are core attributes...
468 throw new RuntimeException(e);
469 }
470 return this;
471 }
472
473 /**
474 * Retrieves the Phone numbers for the User.
475 *
476 * @return The Phone numbers for the User or <code>null</code>
477 * if it is not specified.
478 */
479 public Collection<Entry<String>> getPhoneNumbers()
480 {
481 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
482 "phoneNumbers", Entry.STRINGS_RESOLVER);
483 }
484
485 /**
486 * Sets the Phone numbers for the User.
487 *
488 * @param phoneNumbers The Phone numbers for the User.
489 * @return this resource instance.
490 */
491 public UserResource setPhoneNumbers(
492 final Collection<Entry<String>> phoneNumbers)
493 {
494 try {
495 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
496 "phoneNumbers", Entry.STRINGS_RESOLVER, phoneNumbers);
497 } catch (InvalidResourceException e) {
498 // This should never happen as these are core attributes...
499 throw new RuntimeException(e);
500 }
501 return this;
502 }
503
504 /**
505 * Retrieves the Instant messaging address for the User.
506 *
507 * @return The Instant messaging address for the User or <code>null</code>
508 * if it is not specified.
509 */
510 public Collection<Entry<String>> getIms()
511 {
512 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
513 "ims", Entry.STRINGS_RESOLVER);
514 }
515
516 /**
517 * Sets the Instant messaging address for the User.
518 *
519 * @param ims The Instant messaging address for the User.
520 * @return this resource instance.
521 */
522 public UserResource setIms(final Collection<Entry<String>> ims)
523 {
524 try {
525 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
526 "ims", Entry.STRINGS_RESOLVER, ims);
527 } catch (InvalidResourceException e) {
528 // This should never happen as these are core attributes...
529 throw new RuntimeException(e);
530 }
531 return this;
532 }
533
534 /**
535 * Retrieves the URL of a photo of the User.
536 *
537 * @return The URL of a photo of the User or <code>null</code> if
538 * it is not specified.
539 */
540 public Collection<Entry<String>> getPhotos()
541 {
542 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
543 "photos", Entry.STRINGS_RESOLVER);
544 }
545
546 /**
547 * Sets the URL of a photo of the User.
548 *
549 * @param photos The URL of a photo of the User.
550 * @return this resource instance.
551 */
552 public UserResource setPhotos(final Collection<Entry<String>> photos)
553 {
554 try {
555 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
556 "photos", Entry.STRINGS_RESOLVER, photos);
557 } catch (InvalidResourceException e) {
558 // This should never happen as these are core attributes...
559 throw new RuntimeException(e);
560 }
561 return this;
562 }
563
564 /**
565 * Retrieves the physical mailing address for this User.
566 *
567 * @return The physical mailing address for this User or <code>null</code> if
568 * it is not specified.
569 */
570 public Collection<Address> getAddresses()
571 {
572 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
573 "addresses", Address.ADDRESS_RESOLVER);
574 }
575
576 /**
577 * Sets the physical mailing address for this User.
578 *
579 * @param addresses The physical mailing address for this User.
580 * @return this resource instance.
581 */
582 public UserResource setAddresses(final Collection<Address> addresses)
583 {
584 try {
585 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
586 "addresses", Address.ADDRESS_RESOLVER, addresses);
587 } catch (InvalidResourceException e) {
588 // This should never happen as these are core attributes...
589 throw new RuntimeException(e);
590 }
591 return this;
592 }
593
594 /**
595 * Retrieves the list of groups that the user belongs to.
596 *
597 * @return The list of groups that the user belongs to or <code>null</code> if
598 * it is not specified.
599 */
600 public Collection<Entry<String>> getGroups()
601 {
602 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
603 "groups", Entry.STRINGS_RESOLVER);
604 }
605
606 /**
607 * Sets the list of groups that the user belongs to.
608 *
609 * @param groups The list of groups that the user belongs to.
610 * @return this resource instance.
611 */
612 public UserResource setGroups(final Collection<Entry<String>> groups)
613 {
614 try {
615 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
616 "groups", Entry.STRINGS_RESOLVER, groups);
617 } catch (InvalidResourceException e) {
618 // This should never happen as these are core attributes...
619 throw new RuntimeException(e);
620 }
621 return this;
622 }
623
624 /**
625 * Retrieves the list of entitlements for the User that represent a thing
626 * the User has. That is, an entitlement is an additional right to a thing,
627 * object or service.
628 *
629 * @return The list of entitlements for the User or <code>null</code> if
630 * it is not specified.
631 */
632 public Collection<Entry<String>> getEntitlements()
633 {
634 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
635 "entitlements", Entry.STRINGS_RESOLVER);
636 }
637
638 /**
639 * Sets the list of entitlements for the User.
640 *
641 * @param entitlements The list of entitlements for the User
642 * @return this resource instance.
643 */
644 public UserResource setEntitlements(
645 final Collection<Entry<String>> entitlements)
646 {
647 try {
648 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
649 "entitlements", Entry.STRINGS_RESOLVER, entitlements);
650 } catch (InvalidResourceException e) {
651 // This should never happen as these are core attributes...
652 throw new RuntimeException(e);
653 }
654 return this;
655 }
656
657 /**
658 * Retrieves the list of roles for the User that collectively represent who
659 * the User is; e.g., 'Student', "Faculty".
660 *
661 * @return The list of roles for the User or <code>null</code> if
662 * it is not specified.
663 */
664 public Collection<Entry<String>> getRoles()
665 {
666 return getAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
667 "roles", Entry.STRINGS_RESOLVER);
668 }
669
670 /**
671 * Sets the list of roles for the User.
672 *
673 * @param roles The list of roles for the User.
674 * @return this resource instance.
675 */
676 public UserResource setRoles(final Collection<Entry<String>> roles)
677 {
678 try {
679 setAttributeValues(SCIMConstants.SCHEMA_URI_CORE,
680 "roles", Entry.STRINGS_RESOLVER, roles);
681 } catch (InvalidResourceException e) {
682 // This should never happen as these are core attributes...
683 throw new RuntimeException(e);
684 }
685 return this;
686 }
687 }