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.search.admin;
007:
008: import java.io.IOException;
009: import javax.servlet.http.HttpServletRequest;
010: import javax.servlet.http.HttpServletResponse;
011: import javax.servlet.*;
012:
013: import com.iplanet.jato.RequestContext;
014: import com.iplanet.jato.RequestContextImpl;
015: import com.iplanet.jato.ViewBeanManager;
016: import com.iplanet.jato.ModelManager;
017: import com.iplanet.jato.ModelTypeMap;
018: import com.iplanet.jato.Log;
019: import com.iplanet.am.console.base.ConsoleServletBase;
020: import com.iplanet.am.console.base.model.AMAdminTypes;
021: import com.iplanet.am.util.SystemProperties;
022:
023: import com.iplanet.am.sdk.AMRole;
024: import com.iplanet.sso.SSOToken;
025: import com.iplanet.sso.SSOTokenManager;
026: import com.iplanet.sso.SSOException;
027: import com.sun.portal.log.common.PortalLogger;
028:
029: import java.net.*;
030: import java.util.*;
031: import java.util.logging.Level;
032: import java.util.logging.Logger;
033:
034: /**
035: * the front end controller servlet of base URI
036: */
037: public class AdminServlet extends ConsoleServletBase {
038: private static Logger debugLogger = PortalLogger
039: .getLogger(AdminServlet.class);
040: public static final String DEFAULT_MODULE_URL = "../searchadmin"; // TODO
041: public static String PACKAGE_NAME = getPackageName(AdminServlet.class
042: .getName());
043: private static ModelTypeMap MODEL_TYPE_MAP;
044: private String locationDN = null;
045: private String serviceName = null;
046:
047: protected String getDefaultHandlerName(HttpServletRequest request) {
048: return "Server";
049:
050: }
051:
052: protected void initializeRequestContext(
053: RequestContext requestContext) {
054: super .initializeRequestContext(requestContext);
055: // Set a model manager in the request context. This must be
056: // done at the application level because the MODEL_TYPE_MAP
057: // is application specific.
058: ModelManager modelManager = new ModelManager(requestContext,
059: MODEL_TYPE_MAP);
060: ((RequestContextImpl) requestContext)
061: .setModelManager(modelManager);
062:
063: ViewBeanManager viewBeanManager = new ViewBeanManager(
064: requestContext, PACKAGE_NAME);
065:
066: ((RequestContextImpl) requestContext)
067: .setViewBeanManager(viewBeanManager);
068: }
069:
070: /** gets the modules URL
071: *
072: * @param the modules URL
073: */
074: public String getModuleURL() {
075: return DEFAULT_MODULE_URL;
076: }
077:
078: public void init(ServletConfig svltconfig) throws ServletException {
079: super .init(svltconfig);
080: MODEL_TYPE_MAP = new ModelTypeMapImpl();
081: String serverRoot = svltconfig.getInitParameter("server.root");
082:
083: String deployURI = svltconfig.getServletContext()
084: .getInitParameter("dynamicContext");
085: String staticURI = svltconfig.getServletContext()
086: .getInitParameter("staticContext");
087: if (serverRoot != null && serverRoot.trim().length() > 0) {
088: // Logging is initialized using server root. Logging is NOT initialized
089: // in the init method as its being called from CLIs also
090: CSConfig.initLogging(serverRoot);
091: CSConfig.init(serverRoot);
092: return;
093: }
094: serverRoot = svltconfig.getServletContext().getInitParameter(
095: "server.root");
096: if (serverRoot != null && serverRoot.trim().length() > 0) {
097: // Logging is initialized using server root. Logging is NOT initialized
098: // in the init method as its being called from CLIs also
099: CSConfig.initLogging(serverRoot);
100: CSConfig.init(serverRoot);
101: }
102: }
103:
104: private void setAdminLocale(SSOToken ssoToken) {
105: java.util.Locale locale;
106: try {
107: String lstr = ssoToken.getProperty("Locale");
108: locale = com.iplanet.am.util.Locale.getLocale(lstr);
109: } catch (SSOException ssoe) {
110: locale = java.util.Locale.getDefault();
111: }
112: CSConfig.setAdminLocale(locale);
113: }
114:
115: public void doPost(HttpServletRequest request,HttpServletResponse response)
116: throws ServletException, IOException
117: {
118: String redirectURL = consoleURI + "/base/AMAdminFrame";
119: String pageName=null;
120: if (request.getPathInfo()!=null) {
121: pageName=parsePathInfo(request.getPathInfo());
122: }
123: try{
124: //Check if user is ok
125: SSOTokenManager manager = SSOTokenManager.getInstance();
126: SSOToken token = manager.createSSOToken(request);
127: manager.getInstance().validateToken(token);
128: int userType = new AMAdminTypes(token).getUserType();
129:
130: if (userType == AMRole.TOP_LEVEL_ADMIN_ROLE) {
131: setAdminLocale(token);
132: String tem = request.getParameter("Template");
133: String encodedDN = request.getParameter("Location");
134: String servName = request.getParameter("ServiceName");
135: if (tem!=null) { //org level
136: String uriStr ="/amconsole/service/SMData?";
137: Enumeration enum = request.getParameterNames();
138: while(enum.hasMoreElements()) {
139: String name = (String)enum.nextElement();
140: String value = request.getParameter(name);
141: uriStr = uriStr + URLEncoder.encode(name) + "=" + URLEncoder.encode(value) + "&";
142: }
143: debugLogger.log(Level.FINER, "PSSH_CSPSA0001", uriStr);
144: response.sendRedirect(uriStr);
145: }
146: else {
147: if(encodedDN != null) {
148: locationDN = URLDecoder.decode(encodedDN);
149: if (servName != null)
150: serviceName = servName;
151: }
152: if (locationDN != null) {
153: request.setAttribute("locationDN", locationDN);
154: }
155: if (serviceName != null) {
156: request.setAttribute("serviceName", serviceName);
157: }
158: super .doPost(request,response);
159: }
160: }
161: else {
162: if (pageName != null && pageName.equalsIgnoreCase("SearchUser")) {
163: super .doPost(request,response);
164: }
165: else {
166: response.sendRedirect(redirectURL);
167: }
168: }
169: //else redirect to login
170: } catch(SSOException soe) {
171: super.doPost(request,response);
172: }
173: }
174:
175: }
|