001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * any nuclear facility.
035: */
036:
037: package com.sun.portal.community.impl;
038:
039: import com.iplanet.am.sdk.AMException;
040: import com.iplanet.am.sdk.AMStoreConnection;
041: import com.iplanet.sso.SSOException;
042: import com.iplanet.sso.SSOToken;
043: import com.iplanet.sso.SSOTokenManager;
044: import com.sun.identity.security.AdminTokenAction;
045: import java.security.AccessController;
046: import com.sun.portal.util.ResourceLoader;
047: import com.iplanet.am.sdk.AMUser;
048:
049: import com.sun.portal.community.CommunityException;
050:
051: /**
052: *
053: * @author ac120954
054: */
055: public class DSAMEUserInfo {
056:
057: public class UserNotFoundException extends Exception {
058: public UserNotFoundException(String msg) {
059: super (msg);
060: }
061: }
062:
063: static public final String ATTTR_FULLNAME = "cn";
064: static public final String ATTTR_EMAIL = "mail";
065: static public final String ATTTR_LOCALE = "preferredlocale";
066:
067: private static final String portalId = ResourceLoader.getInstance(
068: System.getProperties()).getPortalId();
069:
070: private static final SSOTokenManager tokenManager;
071: protected static final AMStoreConnection adminConnection;
072:
073: //
074: // initialize AM connections
075: // these are static and shared between all object instances
076: //
077: static {
078: if (portalId == null) {
079: throw new Error("portal ID was null");
080: }
081: try {
082: tokenManager = SSOTokenManager.getInstance();
083:
084: //
085: // get the admin connection
086: // this impl uses the AM admin connection, always
087: // this is necessary because we are accessing attributes from
088: // roles and orgs. a user token does not allow use to do this
089: //
090: SSOToken ssot = (SSOToken) AccessController
091: .doPrivileged(AdminTokenAction.getInstance());
092: adminConnection = new AMStoreConnection(ssot);
093:
094: } catch (SSOException ssoe) {
095: throw new Error("error in static initializer", ssoe);
096: }
097: }
098:
099: private AMUser amUser;
100:
101: /**
102: * Creates a new instance of DSAMEUserInfo
103: */
104: public DSAMEUserInfo(String userId) throws UserNotFoundException,
105: CommunityException {
106: try {
107: amUser = adminConnection.getUser(userId);
108: if (amUser == null) {
109: throw new UserNotFoundException(
110: "unable to find am user object for uid: "
111: + userId);
112: }
113: } catch (SSOException ssoE) {
114: throw new CommunityException("fail to obtain amUser: "
115: + ssoE);
116: }
117: }
118:
119: public String getUserStringAttribute(String name)
120: throws CommunityException {
121: if (amUser != null) {
122: try {
123: return amUser.getStringAttribute(name);
124: } catch (SSOException ssoE) {
125: throw new CommunityException(
126: "fail to obtain amUser string attribute: "
127: + ssoE);
128: } catch (AMException amE) {
129: throw new CommunityException(
130: "fail to obtain amUser string attribute: "
131: + amE);
132: }
133: }
134: return null;
135: }
136:
137: }
|