001: /**
002: * $Id: SAPUserConfigPortlet.java,v 1.5 2005/10/19 10:25:58 ks161616 Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.sapportlet;
014:
015: import com.sun.portal.sapportlet.config.SAPUserConfig;
016: import com.sun.portal.sapportlet.employee.Employee;
017: import com.sun.portal.sapportlet.employee.EmployeeManager;
018: import javax.portlet.GenericPortlet;
019: import javax.portlet.PortletContext;
020: import javax.portlet.PortletConfig;
021: import javax.portlet.PortletException;
022: import javax.portlet.RenderRequest;
023: import javax.portlet.RenderResponse;
024: import javax.portlet.PortletRequestDispatcher;
025: import javax.portlet.ActionRequest;
026: import javax.portlet.ActionResponse;
027: import javax.portlet.*;
028: import java.io.IOException;
029: import java.util.Iterator;
030: import java.util.logging.Logger;
031: import java.rmi.RemoteException;
032: import com.sun.portal.sapportlet.customer.*;
033: import com.sun.portal.sapportlet.util.ssoa.SAPAuthUtils;
034: import com.sun.portal.sapportlet.util.ssoa.InvalidCredentialsException;
035:
036: /**
037: * This is the SAPUserConfigPortlet. It can be used
038: * to search for customers from an existing SAP system.
039: *
040: * @author nk137934
041: */
042:
043: public class SAPUserConfigPortlet extends GenericPortlet implements
044: SAPPortletConstants {
045:
046: private static Logger logger = Logger
047: .getLogger(SAPPortletConstants.LOGGER_NAMESPACE);
048:
049: /*
050: * On init, the portlet creates & initis a CusomerManager object.
051: * The actual queries are delegated to this object
052: */
053: public void init(PortletConfig config) throws PortletException {
054:
055: super .init(config);
056: }
057:
058: /*
059: * The doView method of the SAPCustSearchPortlet.
060: * If the query has already been executed, the results
061: * are available in the session. If not, execute the default
062: * query.
063: */
064: public void doView(RenderRequest request, RenderResponse response)
065: throws PortletException, IOException {
066:
067: PortletSession session = request.getPortletSession();
068: //boolean isValid = false;
069: response.setContentType(request.getResponseContentType());
070:
071: SAPUserConfig userConfig = (SAPUserConfig) session
072: .getAttribute(SESSION_USERCONFIG,
073: PortletSession.APPLICATION_SCOPE);
074: PortletRequestDispatcher dispatcher = null;
075:
076: if (userConfig == null) {
077: userConfig = SAPAuthUtils
078: .checkForUserAuthentication(request);
079: }
080:
081: if (userConfig != null) {
082: session.setAttribute(SESSION_USERCONFIG, userConfig,
083: PortletSession.APPLICATION_SCOPE);
084: SAPAuthUtils.setUserConfig(request);
085: dispatcher = getPortletContext().getRequestDispatcher(
086: USER_CONFIG_VIEW_PAGE);
087: } else {
088: dispatcher = getPortletContext().getRequestDispatcher(
089: USER_CONFIG_REDIRECT);
090: }
091: session.removeAttribute(PARAM_AUTH,
092: PortletSession.APPLICATION_SCOPE);
093: //logger.severe("PARAMETER IS =>"+request.getParameter(PARAM_CHANGE));
094: dispatcher.include(request, response);
095: }
096:
097: /*
098: * The doEdit method of the SAPCustSearchPortlet.
099: * This page displays the config page which asks for the username and password.
100: */
101: public void doEdit(RenderRequest request, RenderResponse response)
102: throws PortletException, IOException {
103:
104: PortletSession session = request.getPortletSession();
105: response.setContentType(request.getResponseContentType());
106: PortletRequestDispatcher dispatcher = null;
107: //logger.severe("PARAMETER IS =>"+request.getParameter(PARAM_CHANGE));
108: dispatcher = getPortletContext().getRequestDispatcher(
109: USER_CONFIG_PAGE);
110: dispatcher.include(request, response);
111: }
112:
113: /*
114: * processAction invokes the validateCredentials or simply transfers the control to doView
115: * depending on the action chosen in the jsp page displayed by the doEdit method.
116: */
117: public void processAction(ActionRequest request,
118: ActionResponse response) throws PortletException,
119: IOException {
120:
121: String action = request.getParameter(HTML_FIELD_OPERATION);
122: if (action.equals(OPERATION_CONFIGURE)) {
123: validateCredentials(request, response);
124: } else if (action.equals(OPERATION_CANCEL)) {
125: if (request.isPortletModeAllowed(PortletMode.VIEW)) {
126: logger.severe("SETTING PORTLET MODE IS ALLOWED");
127: response.setPortletMode(PortletMode.VIEW);
128: }
129: }
130: }
131:
132: public void doHelp(RenderRequest request, RenderResponse response)
133: throws PortletException, IOException {
134:
135: response.setContentType(request.getResponseContentType());
136: PortletRequestDispatcher dispatcher = getPortletContext()
137: .getRequestDispatcher(USERCONFIG_HELP_PAGE);
138: dispatcher.include(request, response);
139:
140: }
141:
142: private void validateCredentials(ActionRequest request,
143: ActionResponse response) throws PortletException,
144: IOException {
145: PortletSession session = request.getPortletSession();
146: session.removeAttribute(SESSION_USERCONFIG,
147: PortletSession.APPLICATION_SCOPE);
148: SAPUserConfig userConfig = null;
149: userConfig = SAPAuthUtils.checkForUserAuthentication(request);
150: if (userConfig != null) {
151: session.setAttribute(SESSION_USERCONFIG, userConfig,
152: PortletSession.APPLICATION_SCOPE);
153: SAPAuthUtils.setUserConfig(request);
154: if (request.isPortletModeAllowed(PortletMode.VIEW)) {
155: logger.severe("SETTING PORTLET MODE IS ALLOWED");
156: response.setPortletMode(PortletMode.VIEW);
157: }
158: } else {
159: session.removeAttribute(SESSION_USERCONFIG,
160: PortletSession.APPLICATION_SCOPE);
161: session.setAttribute(PARAM_AUTH, PARAM_AUTH_FAILED,
162: PortletSession.APPLICATION_SCOPE);
163: response.setPortletMode(PortletMode.EDIT);
164: }
165: }
166: }
|