001: package com.sun.portal.rproxy.configservlet.server;
002:
003: import java.rmi.RemoteException;
004: import java.util.Map;
005:
006: import com.iplanet.am.sdk.AMException;
007: import com.iplanet.am.sdk.AMStoreConnection;
008: import com.iplanet.am.sdk.AMUser;
009: import com.iplanet.sso.SSOException;
010: import com.iplanet.sso.SSOToken;
011: import com.iplanet.sso.SSOTokenManager;
012: import com.sun.portal.rproxy.configservlet.Request;
013: import com.sun.portal.rproxy.configservlet.Response;
014: import com.sun.portal.rproxy.configservlet.ServiceHandler;
015:
016: public class UserAttributesServiceHandler implements ServiceHandler {
017:
018: public UserAttributesServiceHandler() {
019: }
020:
021: public Response handleRequest(Request request)
022: throws RemoteException {
023: // iDSAME Migration
024: // Servlet User Profile Caching added
025: // So modifying to use the cache instead of directly fetching.
026: // - Mridul
027: /*
028: * try { SSOToken token = getSSOToken(request); AMStoreConnection
029: * connection = new AMStoreConnection(token); AMUser user =
030: * connection.getUser(token.getPrincipal().getName()); Map attrs =
031: * user.getAttributes(); Response response = new
032: * Response(request.getServiceName(), request.getRequestType(), attrs);
033: * return response; } catch (SSOException ssoe) { throw new
034: * RemoteException("Not able to get Global Attributes", ssoe); } catch
035: * (AMException dpe) { throw new RemoteException("Not able to get Global
036: * Attributes", dpe); }
037: */
038: // TODO::
039: // Must add code here to check if this is a get request or a set
040: // request.
041: // Check this profile is present in the cache and if not fetch it and
042: // add to cache.
043: String tokid = request.getSSOTokenId();
044: Response resp = UserProfileCache.getResponse(tokid);
045: boolean valid = true;
046:
047: // As a side-effect of the cache-cleaner thread in the UserProfileCache,
048: // we don't need this.
049: // When SessionListener gets properly implemented by iDSAME , this code
050: // will have to come back.
051: /*
052: * if (resp == null){
053: *
054: * SSOToken token = getSSOToken(request); if (token != null){ // See
055: * whether this is a valid token. resp =
056: * fetchUserAttributes(request,token); try{ long dummy =
057: * token.getIdleTime(); UserProfileCache.addEntry(token , tokid , resp);
058: * }catch(SSOException ex){ valid = false; } } }
059: */
060: resp.setRequestType(request.getRequestType());
061: resp.setServiceName(request.getServiceName());
062: resp.setNormal(valid);
063: return resp;
064: }
065:
066: // private Response fetchUserAttributes(Request request,SSOToken token)
067: // throws RemoteException{
068: protected Response fetchUserAttributes(Request request,
069: SSOToken token) throws RemoteException {
070:
071: try {
072: // SSOToken token = getSSOToken(request);
073: AMStoreConnection connection = new AMStoreConnection(token);
074: AMUser user = connection.getUser(token.getPrincipal()
075: .getName());
076: Map attrs = user.getAttributes();
077: Response response = new Response(request.getServiceName(),
078: request.getRequestType(), attrs);
079: return response;
080: } catch (SSOException ssoe) {
081: throw new RemoteException(
082: "Not able to get Global Attributes", ssoe);
083: } catch (AMException dpe) {
084: throw new RemoteException(
085: "Not able to get Global Attributes", dpe);
086: }
087: }
088:
089: // private SSOToken getSSOToken(Request request) throws RemoteException {
090: protected SSOToken getSSOToken(Request request)
091: throws RemoteException {
092: try {
093: String tokenId = request.getSSOTokenId();
094: SSOTokenManager tokenManager = SSOTokenManager
095: .getInstance();
096: return tokenManager.createSSOToken(tokenId);
097: } catch (SSOException ssoe) {
098: throw new RemoteException("Not able to get the token", ssoe);
099: }
100: }
101: }
|