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.sapportlet.util.ssoa;
038:
039: import java.util.Properties;
040: import java.util.Enumeration;
041: import java.util.logging.*;
042: import javax.servlet.http.HttpServletRequest;
043: import com.sun.portal.iwayutil.ssoadapterutils.*;
044: import com.sun.portal.sapportlet.util.SAPLogger;
045: import com.sun.portal.sapportlet.SAPPortletConstants;
046: import com.sun.portal.sapportlet.config.UnConfiguredException;
047:
048: /*
049: * This class is a wrapper over the EAISSOAdapterConfigUtils class.
050: * It is used for setting/getting config parameters required for SAP.
051: * These are: username, password, endpoint host, endpoint port, client id.
052: */
053: public class SAPSSOAdapterUtils implements SAPPortletConstants {
054: Properties sapSSOProps = null;
055: EAISSOAdapterConfigUtils ssoUtils = null;
056: Logger logger = null;
057:
058: public SAPSSOAdapterUtils(HttpServletRequest httpReq,
059: String configName, String channelName)
060: throws UnConfiguredException {
061: logger = SAPLogger.getLogger();
062: ssoUtils = new EAISSOAdapterConfigUtils(configName, channelName);
063: sapSSOProps = ssoUtils.getSSOAdapterAttributes(httpReq);
064: if (sapSSOProps == null) {
065: throw new UnConfiguredException(
066: "SSO Adapter not configured");
067: }
068: }
069:
070: public String getSAPUserName() {
071: String name = null;
072:
073: if (sapSSOProps != null) {
074: name = (String) sapSSOProps.get(CONFIG_USERNAME);
075: }
076: debug("getSAPUserName()", "Name : " + name);
077: return name;
078: }
079:
080: public String getSAPPassword() {
081: String password = null;
082:
083: if (sapSSOProps != null) {
084: password = (String) sapSSOProps.get(CONFIG_PASSWORD);
085: }
086: return password;
087: }
088:
089: public String getSAPEndpointHost() {
090: String host = null;
091:
092: if (sapSSOProps != null) {
093: host = (String) sapSSOProps.get(CONFIG_ENDPOINT_HOST);
094: }
095: debug("getSAPEndpointHost()", "host : " + host);
096: return host;
097: }
098:
099: public String getSAPEndpointPort() {
100: String port = null;
101:
102: if (sapSSOProps != null) {
103: port = (String) sapSSOProps.get(CONFIG_ENDPOINT_PORT);
104: }
105: debug("getSAPEndpointPort()", "port : " + port);
106: return port;
107: }
108:
109: public String getSAPClientID() {
110: String id = null;
111:
112: if (sapSSOProps != null) {
113: id = (String) sapSSOProps.get(CONFIG_CLIENTID);
114: }
115: debug("getSAPClientID()", "id : " + id);
116: return id;
117: }
118:
119: public String getSAPEndPoint() {
120: String endPoint = null;
121:
122: if (sapSSOProps != null) {
123: String endHost = getSAPEndpointHost();
124: String endPort = getSAPEndpointPort();
125: String clientID = getSAPClientID();
126: endPoint = "http://" + endHost + ":" + endPort
127: + "/sap/bc/soap/rfc?sap-client=" + clientID;
128: }
129: debug("getSAPEndPoint()", "endPoint : " + endPoint);
130: return endPoint;
131: }
132:
133: public Properties getSAPProperties() {
134: Properties props = null;
135:
136: if (sapSSOProps != null) {
137: props = new Properties();
138: Enumeration enum = sapSSOProps.propertyNames();
139: String name = null;
140: String value = null;
141: while (enum.hasMoreElements()) {
142: name = (String) enum.nextElement();
143: value = (String) sapSSOProps.get(name);
144: props.put(name, value);
145: }
146: }
147: return props;
148: }
149:
150: public void removeSSOAdapterAttributes(HttpServletRequest httpReq) {
151: ssoUtils.removeSSOAdapterAttributes(httpReq);
152: }
153:
154: public void setSSOAdapterAttributes(Properties attrs,
155: HttpServletRequest httpReq) {
156: ssoUtils.setSSOAdapterAttributes(attrs, httpReq);
157: }
158:
159: /**
160: * This method will print the log the messages.
161: **/
162: private void debug(String methodName, String msg) {
163: logger.log(Level.INFO,
164: "com.sun.portal.sapportlet.util.ssoa.SAPSSOAdapterUtils :"
165: + methodName + ":" + msg);
166: }
167: }
|