001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.subscriptions.providers;
007:
008: import java.net.URL;
009: import java.util.ResourceBundle;
010: import java.util.Locale;
011: import java.util.logging.Logger;
012: import java.util.logging.Level;
013: import java.util.logging.LogRecord;
014: import java.util.Map;
015: import java.util.HashMap;
016: import javax.servlet.http.HttpServletRequest;
017: import javax.servlet.http.HttpServletResponse;
018:
019: import com.sun.portal.providers.context.ProviderContext;
020: import com.sun.portal.providers.context.ProviderContextException;
021: import com.sun.portal.providers.ProviderException;
022: import com.sun.portal.providers.jsp.JSPProvider;
023: import com.sun.portal.log.common.PortalLogger;
024: import com.sun.portal.subscriptions.util.Utils;
025:
026: import com.iplanet.am.sdk.AMTemplate;
027: import com.iplanet.am.util.AdminUtils;
028: import java.security.AccessController;
029: import com.iplanet.sso.SSOTokenManager;
030: import com.iplanet.am.sdk.AMStoreConnection;
031: import com.iplanet.sso.SSOToken;
032: import com.iplanet.sso.SSOException;
033: import com.sun.identity.security.*;
034:
035: /**
036: *
037: */
038: public class SubscriptionsProvider extends JSPProvider {
039: // Create a logger for this class
040: private static Logger logger = PortalLogger
041: .getLogger(SubscriptionsProvider.class);
042: private static final String DEFAULT_SEARCH_SERVERS = "subsDefSrchSvr";
043:
044: public void init(String n, HttpServletRequest httpreq)
045: throws ProviderException {
046: super .init(n, httpreq);
047: }
048:
049: public String getPortalId() {
050: try {
051: return Utils.getPortalId();
052: } catch (Exception e) {
053: getLogger().log(Level.SEVERE, "PSCC_CSPPC0013", e);
054: return "";
055: }
056: }
057:
058: public String getDefaultSearchServer(String orgDN) {
059: String defSrchSvrUrl = null;
060: Map defSrchSvrs = null;
061: defSrchSvrs = (Map) getProviderContext().getSessionProperty(
062: DEFAULT_SEARCH_SERVERS);
063: if (defSrchSvrs == null) {
064: defSrchSvrs = new HashMap();
065: }
066: if (defSrchSvrs.containsKey(orgDN)) {
067: defSrchSvrUrl = (String) defSrchSvrs.get(orgDN);
068: } else {
069: // fetch the default Search server from subscription service's
070: // org attribute
071: try {
072: SSOTokenManager ssom = SSOTokenManager.getInstance();
073: SSOToken sso = ssom.createSSOToken(
074: new java.security.Principal() {
075: public String getName() {
076: return (String) AccessController
077: .doPrivileged(new AdminDNAction());
078: }
079: },
080: (String) AccessController
081: .doPrivileged(new AdminPasswordAction()));
082: AMStoreConnection amStore = new AMStoreConnection(sso);
083: if (amStore != null) {
084: AMTemplate orgSvcTmp = amStore.getOrganization(
085: orgDN).getTemplate(
086: "SunPortal" + getPortalId()
087: + "SubscriptionsService",
088: AMTemplate.ORGANIZATION_TEMPLATE);
089: defSrchSvrUrl = orgSvcTmp
090: .getStringAttribute("sunPortalProfilerDefaultSearch");
091: } else {
092: defSrchSvrUrl = null;
093: }
094: } catch (Exception e) {
095: // XXX log
096: defSrchSvrUrl = null;
097: }
098: try {
099: // save it in providerContext
100: // XXX saving a null value in the session will slow down
101: // the overall perf of the subscription channel as it'll
102: // check org service attribute each and every refresh of
103: // the subscriptions/profiler channels
104: defSrchSvrs.put(orgDN, defSrchSvrUrl);
105: getProviderContext().setSessionProperty(
106: DEFAULT_SEARCH_SERVERS, defSrchSvrs);
107: } catch (Exception e) {
108: // XXX log
109: }
110: }
111: return defSrchSvrUrl;
112: }
113:
114: public Logger getLogger() {
115: return logger;
116: }
117:
118: public void setLogger(Logger logger) {
119: this.logger = logger;
120: }
121: }
|