001: package com.sun.portal.sra.test.provider;
002:
003: import com.iplanet.sso.*;
004: import com.sun.portal.sra.util.UserAttributes;
005: import java.util.*;
006: import javax.servlet.http.HttpServletRequest;
007: import javax.servlet.http.HttpServletResponse;
008:
009: public class sraStandaloneSeparationProvider {
010:
011: public sraStandaloneSeparationProvider() {
012: localTarget = null;
013: localIPAddress = null;
014: }
015:
016: public void init(String s, HttpServletRequest httpservletrequest) {
017: }
018:
019: public Map getContent(HttpServletRequest req,
020: HttpServletResponse res) {
021: UserAttributes attrs = getSRASeparationUserAttributes(req);
022: StringBuffer target = null;
023: StringBuffer ipAddress = null;
024: HashMap tagTable = new HashMap();
025: target = new StringBuffer(attrs
026: .getString("sunSRASeparationTarget"));
027: tagTable.put("target", target);
028: ipAddress = new StringBuffer(attrs
029: .getString("sunSRASeparationIP"));
030: tagTable.put("address", ipAddress);
031: return tagTable;
032: }
033:
034: public Map getEdit(HttpServletRequest req, HttpServletResponse res) {
035: UserAttributes attrs = getSRASeparationUserAttributes(req);
036: HashMap tagTable = new HashMap();
037: tagTable.put("target", attrs
038: .getUserAttribute("sunSRASeparationTarget"));
039: tagTable.put("address", attrs
040: .getUserAttribute("sunSRASeparationIP"));
041: return tagTable;
042: }
043:
044: public void processEdit(HttpServletRequest req,
045: HttpServletResponse res) {
046: Map params = getParameterMap(req);
047: if (null != params) {
048: setProcessParameters(params);
049: UserAttributes attrs = getSRASeparationUserAttributes(req);
050: commitNewValues(attrs);
051: }
052: }
053:
054: private SSOToken getSSOToken(HttpServletRequest req) {
055: SSOToken ssoToken = null;
056: try {
057: ssoToken = SSOTokenManager.getInstance()
058: .createSSOToken(req);
059: } catch (SSOException ssoe) {
060: System.out
061: .println("ProxyletProvider: Unable to create ssoToken -> "
062: + ssoe);
063: }
064: return ssoToken;
065: }
066:
067: private UserAttributes getSRASeparationUserAttributes(
068: HttpServletRequest req) {
069: return new UserAttributes(getSSOToken(req));
070: }
071:
072: private Map getParameterMap(HttpServletRequest req) {
073: Map map = null;
074: try {
075: map = new HashMap();
076: String name;
077: String val[];
078: for (Enumeration e = req.getParameterNames(); e
079: .hasMoreElements(); map.put(name, val)) {
080: name = (String) e.nextElement();
081: val = req.getParameterValues(name);
082: }
083:
084: } catch (Exception de) {
085: System.out
086: .println("sraSeparationProvider: Unable to get page parameters -> "
087: + de);
088: }
089: return map;
090: }
091:
092: private void setProcessParameters(Map params) {
093: String newTarget = (String) params.get("Target");
094: if (null != newTarget)
095: localTarget = newTarget;
096: else
097: localTarget = "";
098: String newAddress = (String) params.get("Address");
099: if (null != newAddress)
100: localIPAddress = newAddress;
101: else
102: localIPAddress = "";
103: }
104:
105: private void commitNewValues(UserAttributes attrs) {
106: String oldTarget = attrs.getString("sunSRASeparationTarget");
107: if (oldTarget == null && !localTarget.equals(oldTarget))
108: attrs.setString("sunSRASeparationTarget", localTarget);
109: String oldIPAddress = attrs.getString("sunSRASeparationIP");
110: if (oldIPAddress == null
111: && !localIPAddress.equals(oldIPAddress))
112: attrs.setString("sunSRASeparationIP", localIPAddress);
113: }
114:
115: private String localTarget;
116: private String localIPAddress;
117: }
|