001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * for use in the design, construction, operation or maintenance of
035: * any nuclear facility.
036: */
037: package com.sun.portal.siebelportlet.util;
038:
039: import java.util.Vector;
040: import java.util.Properties;
041: import javax.portlet.*;
042: import java.util.logging.*;
043: import javax.servlet.http.HttpServletRequest;
044:
045: public class SiebelAuthUtils implements SiebelConstants {
046:
047: static Logger logger = SiebelLogger.getLogger();
048:
049: public static void getUserInfo(RenderRequest request,
050: String configName, String channleName) {
051:
052: HttpServletRequest httpReq = (HttpServletRequest) request
053: .getAttribute(HTTPREQ_ATTR_NAME);
054: SiebelSSOAdapterUtils ssoUtils = new SiebelSSOAdapterUtils(
055: httpReq, configName, channleName);
056: String userName = ssoUtils.getSiebelUserName();
057: String userPass = ssoUtils.getSiebelPassword();
058: PortletSession session = request.getPortletSession();
059: checkForValidCredentials(userName, userPass, session, httpReq,
060: configName, channleName);
061: }
062:
063: public static void setUserConfig(ActionRequest request,
064: String configName, String channleName) {
065:
066: String userName = request.getParameter(HTML_FIELD_USER_NAME);
067: String userPass = request.getParameter(HTML_FIELD_USER_PASS);
068: PortletSession session = request.getPortletSession();
069: HttpServletRequest httpReq = (HttpServletRequest) request
070: .getAttribute(HTTPREQ_ATTR_NAME);
071: boolean valid = checkForValidCredentials(userName, userPass,
072: session, httpReq, configName, channleName);
073:
074: if (valid) {
075: debug("setUserConfig()",
076: "Valid User Credentials, Setting SSO Adapter Props");
077: addSSOAdapterConfigData(userName, userPass, httpReq,
078: configName, channleName);
079: }
080: }
081:
082: public static void addSSOAdapterConfigData(String userName,
083: String userPass, HttpServletRequest httpReq,
084: String configName, String channleName) {
085: SiebelSSOAdapterUtils ssoUtils = new SiebelSSOAdapterUtils(
086: httpReq, configName, channleName);
087: Properties props = ssoUtils.getSiebelProperties();
088: props.put(SSO_SIEBEL_USER, userName);
089: props.put(SSO_SIEBEL_PASSWORD, userPass);
090: ssoUtils.setSSOAdapterAttributes(props, httpReq);
091: }
092:
093: public static boolean checkForValidCredentials(String userName,
094: String userPass, PortletSession session,
095: HttpServletRequest httpReq, String configName,
096: String channleName) {
097:
098: boolean valid = false;
099:
100: String status = SiebelIwayUtils.setiWayProperties(userName,
101: userPass, httpReq, configName, channleName);
102: if (status == NO_SSOA_STATUS) {
103: session.setAttribute(SSOA_STATUS, NO_SSOA_STATUS,
104: PortletSession.APPLICATION_SCOPE);
105: } else {
106:
107: if ((userName != null) && (userPass != null)
108: && (session != null)) {
109: SiebelUserInfo config = new SiebelUserInfo(userName,
110: userPass);
111: Vector records = validateAndGetSiebelData(userName,
112: userPass);
113:
114: if (records != null) {
115: debug("setUserConfig()",
116: "Creating User Info Object");
117: session.setAttribute(SESSION_USERCONFIG, config,
118: PortletSession.APPLICATION_SCOPE);
119: session.setAttribute(HTML_FIELD_OPERATION,
120: OPERATION_LOGIN,
121: PortletSession.APPLICATION_SCOPE);
122: session.setAttribute(ACCOUNT_SUMMARY_RECORDS,
123: records, PortletSession.APPLICATION_SCOPE);
124: valid = true;
125: }
126: }
127: }
128: return valid;
129: }
130:
131: public static Vector validateAndGetSiebelData(String userName,
132: String userPass) {
133:
134: Vector records = null;
135:
136: try {
137: String query = DEFAULT_SUMMARY_QUERY;
138: debug("checkForValidCredentials()", "Query = " + query);
139: String reqStr = SiebelAccountRequestUtils
140: .getSiebelCustomerAccountsSummaryQuery(query);
141: String xmlOutput = SiebelIwayUtils
142: .getResponseString(reqStr);
143: records = SiebelResponseUtils.getAccountSummary(xmlOutput);
144: } catch (Exception ex) {
145: SiebelIwayUtils.resetiWayConnetcion();
146: debug("checkForValidCredentials()", "ex : " + ex);
147: records = null;
148: }
149: return records;
150: }
151:
152: /**
153: * This method will print the log the messages.
154: **/
155: private static void debug(String methodName, String msg) {
156: logger.log(Level.INFO,
157: "com.sun.portal.siebelportlet.util.SiebelAuthUtils :"
158: + methodName + ":" + msg);
159: }
160: }
|