001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.rewriter.admin;
006:
007: import java.io.IOException;
008: import com.iplanet.am.console.base.AMMessageViewBean;
009: import com.iplanet.am.console.base.ConsoleServletBase;
010: import com.iplanet.am.console.base.model.AMAdminTypes;
011: import com.iplanet.am.console.components.view.html.MessageBox;
012: import com.sun.portal.rewriter.admin.model.RewriterModel;
013: import com.sun.portal.rewriter.admin.model.RewriterModelImpl;
014: import com.iplanet.am.sdk.AMRole;
015: import com.iplanet.jato.RequestContext;
016: import com.iplanet.jato.RequestContextImpl;
017: import com.iplanet.jato.CompleteRequestException;
018: import com.iplanet.jato.ViewBeanManager;
019: import com.iplanet.jato.view.ViewBean;
020: import com.iplanet.sso.SSOToken;
021: import com.iplanet.sso.SSOTokenManager;
022: import com.iplanet.sso.SSOException;
023:
024: /**
025: * The servlet class that will be used for all requests
026: * for the customized rewriter admin ui.
027: */
028: public class RewriterServlet extends ConsoleServletBase {
029: public static final String DEFAULT_MODULE_URL = "../rwadmin";
030: public static String PACKAGE_NAME = getPackageName(RewriterServlet.class
031: .getName());
032:
033: /**
034: * Default constructor
035: */
036: public RewriterServlet() {
037: super ();
038: }
039:
040: /**
041: * One time initialization of Rewriter Module is necessary for choosing
042: * IDSAME as the DataSource
043: * @author Nagendra Kumar Raja
044: */
045: public void init() throws javax.servlet.ServletException {
046: com.sun.portal.rewriter.RewriterModule.initIDSAME();
047: }//init()
048:
049: /**
050: * Initializes the request.
051: */
052: protected void initializeRequestContext(
053: RequestContext requestContext) {
054: super .initializeRequestContext(requestContext);
055:
056: /* Set a view bean manager in the request context. This must be
057: * done at the module level because the view bean manager is
058: * module specifc.
059: */
060: ViewBeanManager viewBeanManager = new ViewBeanManager(
061: requestContext, PACKAGE_NAME);
062: ((RequestContextImpl) requestContext)
063: .setViewBeanManager(viewBeanManager);
064:
065: try {
066: SSOTokenManager manager = SSOTokenManager.getInstance();
067: SSOToken ssoToken = manager.createSSOToken(requestContext
068: .getRequest());
069: int userType = new AMAdminTypes(ssoToken).getUserType();
070: if (userType != AMRole.TOP_LEVEL_ADMIN_ROLE) {
071: RewriterModel rwm = new RewriterModelImpl(
072: requestContext.getRequest());
073: AMMessageViewBean msgBoxVB = (AMMessageViewBean) viewBeanManager
074: .getViewBean(com.iplanet.am.console.base.AMMessageViewBean.class);
075: msgBoxVB
076: .setTitle(rwm
077: .getLocalizedString("notsuperadminmsgbox.title"));
078: msgBoxVB.setMessage(rwm
079: .getLocalizedString("notsuperadminmsgbox.msg"));
080: msgBoxVB.setMessageType(MessageBox.TYPE_ERROR);
081: msgBoxVB.forwardTo(requestContext);
082: throw new CompleteRequestException();
083: }
084: } catch (SSOException ssoe) {
085: debug
086: .warning("Rewriter servlet base msg: Non authenticated user");
087: /*
088: String redirectURL =
089: serverURI + "/login" + "?module=dproadmin&goto=" +
090: consoleURI + "/base/AMAdminFrame";
091:
092: if (debug.warningEnabled()) {
093: debug.warning("Rewriter servlet base msg: Non authenticated user,"
094: + "redirecting to "
095: + redirectURL);
096: }
097: try {
098: requestContext.getResponse().sendRedirect(redirectURL);
099: } catch (IOException ioe) {
100: if (debug.warningEnabled()) {
101: debug.warning("Rewriter servlet base msg: cannot redirect non authenticated user to:"
102: + redirectURL + "exception:" + ioe);
103: }
104: }
105: */
106: }
107: }
108:
109: /**
110: * Returns the model URL.
111: * @return the module URL as a String object.
112: */
113: public String getModuleURL() {
114: return DEFAULT_MODULE_URL;
115: }
116: }
|