001: /**
002: * $Id: AccessListBean.java,v 1.14 2006/09/05 11:24:39 vp154433 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.admin.console.sra.accesslist;
014:
015: import java.util.ArrayList;
016: import java.util.Iterator;
017: import java.util.List;
018:
019: import com.sun.data.provider.DataProvider;
020: import com.sun.portal.admin.console.sra.SraBaseBean;
021: import com.sun.portal.admin.console.sra.utils.SraObjectListDataProvider;
022: import com.sun.portal.admin.console.sra.utils.Util;
023: import com.sun.web.ui.model.Option;
024:
025: /**
026: * @author Sandeep Soni
027: *
028: */
029: public class AccessListBean extends SraBaseBean {
030: private static final String EMPTY_STRING = "";
031:
032: private static final String DENY_LIST = "sunPortalGatewayAccessDenyList";
033:
034: private static final String ALLOW_LIST = "sunPortalGatewayAccessAllowList";
035:
036: private static final String SSO_DISABLED_HOST_LIST = "sunPortalGatewayWWWDisableSSOHostList";
037:
038: private static final String DO_SSO_PER_SESSION = "sunPortalGatewayWWWDoSSOPerSession";
039:
040: private static final String ALLOWED_AUTH_LEVEL = "sunPortalGatewayAllowedAuthLevel";
041:
042: private static final String WWW_AUTHORIZATION = "sunPortalGatewayWWWAuthorization";
043:
044: static final String[] ATTR_LIST = { COS_PRIORITY, DENY_LIST,
045: ALLOW_LIST, SSO_DISABLED_HOST_LIST, DO_SSO_PER_SESSION,
046: ALLOWED_AUTH_LEVEL, WWW_AUTHORIZATION };
047:
048: private List sunPortalGatewayAccessDenyList;
049:
050: private List sunPortalGatewayAccessAllowList;
051:
052: private static List operations;
053:
054: private boolean sunPortalGatewayWWWDoSSOPerSession;
055:
056: private String[] sunPortalGatewayWWWDisableSSOHostList;
057:
058: private String sunPortalGatewayAllowedAuthLevel;
059:
060: private SraObjectListDataProvider _allowDenyDataProvider;
061:
062: static {
063: operations = new ArrayList();
064: operations.add(new Option(EMPTY_STRING, EMPTY_STRING));
065: operations
066: .add(new Option(
067: Boolean.TRUE,
068: (String) Util
069: .evaluateValueBinding("#{accesscontrol['option.allow.string']}")));
070: operations
071: .add(new Option(
072: Boolean.FALSE,
073: (String) Util
074: .evaluateValueBinding("#{accesscontrol['option.deny.string']}")));
075:
076: // Add Map values
077: setPropertyVisibility(ALLOWED_AUTH_LEVEL, SHOW, SHOW, SHOW);
078: setPropertyVisibility(DO_SSO_PER_SESSION, SHOW, SHOW, SHOW);
079: setPropertyVisibility(DENY_LIST, SHOW, SHOW, SHOW);
080: setPropertyVisibility(ALLOW_LIST, SHOW, SHOW, SHOW);
081: setPropertyVisibility(SSO_DISABLED_HOST_LIST, SHOW, SHOW, SHOW);
082: setPropertyVisibility(WWW_AUTHORIZATION, HIDE, HIDE, SHOW);
083: setPropertyVisibility(COS_PRIORITY, HIDE, SHOW, HIDE);
084: }
085:
086: public AccessListBean() {
087: super (ACCESSLIST_SVC, ATTR_LIST);
088: initData();
089: }
090:
091: public void initData() {
092: List denyList = getListValue(DENY_LIST);
093: List allowList = getListValue(ALLOW_LIST);
094:
095: sunPortalGatewayAccessDenyList = getAclList(denyList, false);
096: sunPortalGatewayAccessAllowList = getAclList(allowList, true);
097: sunPortalGatewayWWWDoSSOPerSession = getBooleanValue(DO_SSO_PER_SESSION);
098: sunPortalGatewayAllowedAuthLevel = getStringValue(ALLOWED_AUTH_LEVEL);
099: sunPortalGatewayWWWDisableSSOHostList = getStringArrayValue(SSO_DISABLED_HOST_LIST);
100:
101: List allowDenyList = new ArrayList(
102: sunPortalGatewayAccessAllowList);
103: allowDenyList.addAll(sunPortalGatewayAccessDenyList);
104: if (allowDenyList.size() == 0)
105: allowDenyList.add(new ACL("", false));
106:
107: _allowDenyDataProvider = new SraObjectListDataProvider(
108: ACL.class.getName(), allowDenyList);
109: }
110:
111: /**
112: * @param
113: * @return
114: */
115: private List getAclList(List thelist, boolean isAllowed) {
116: List list = new ArrayList();
117: Iterator iter = thelist.iterator();
118:
119: while (iter.hasNext()) {
120: String element = (String) iter.next();
121: list.add(new ACL(element, isAllowed));
122: }
123: return list;
124: }
125:
126: public void storeData() {
127: setAllowDenyList();
128: super .storeDataToStore();
129: }
130:
131: public String getSunPortalGatewayAllowedAuthLevel() {
132: return sunPortalGatewayAllowedAuthLevel;
133: }
134:
135: public void setSunPortalGatewayAllowedAuthLevel(String textValue) {
136: this .sunPortalGatewayAllowedAuthLevel = textValue;
137: updateAttributeNVMap(ALLOWED_AUTH_LEVEL,
138: this .sunPortalGatewayAllowedAuthLevel);
139: }
140:
141: public java.util.List getOperations() {
142: return operations;
143: }
144:
145: /**
146: * @return Returns the sunPortalGatewayWWWDoSSOPerSession.
147: */
148: public boolean getSunPortalGatewayWWWDoSSOPerSession() {
149: return sunPortalGatewayWWWDoSSOPerSession;
150: }
151:
152: /**
153: * @param
154: * The sunPortalGatewayWWWDoSSOPerSession to set.
155: */
156: public void setSunPortalGatewayWWWDoSSOPerSession(
157: boolean enableSingleSignonPerSession) {
158: this .sunPortalGatewayWWWDoSSOPerSession = enableSingleSignonPerSession;
159: updateAttributeNVMap(DO_SSO_PER_SESSION, EMPTY_STRING
160: + this .sunPortalGatewayWWWDoSSOPerSession);
161: }
162:
163: public String[] getSunPortalGatewayWWWDisableSSOHostList() {
164: return sunPortalGatewayWWWDisableSSOHostList;
165: }
166:
167: public void setSunPortalGatewayWWWDisableSSOHostList(
168: String[] ssoDisabledHosts) {
169: this .sunPortalGatewayWWWDisableSSOHostList = ssoDisabledHosts;
170: updateAttributeNVMap(SSO_DISABLED_HOST_LIST, ssoDisabledHosts);
171: super .storeDataToStore(SSO_DISABLED_HOST_LIST);
172: }
173:
174: private void setSunPortalGatewayAccessDenyList(
175: List sunPortalGatewayAccessDenyList) {
176: this .sunPortalGatewayAccessDenyList = sunPortalGatewayAccessDenyList;
177: List denyList = convertAclListToUrlList(this .sunPortalGatewayAccessDenyList);
178: updateAttributeNVMap(DENY_LIST, denyList);
179: }
180:
181: public DataProvider getAllowDenyList() {
182: return _allowDenyDataProvider;
183: }
184:
185: private void setAllowDenyList() {
186: _allowDenyDataProvider.commitChanges();
187: List allowList = new ArrayList();
188: List denyList = new ArrayList();
189: ACL[] allowDenyArray = (ACL[]) _allowDenyDataProvider.getList()
190: .toArray(new ACL[0]);
191:
192: for (int i = 0; i < allowDenyArray.length; i++) {
193: ACL element = allowDenyArray[i];
194: if (element.isEmpty())
195: continue;
196: if (element.getIsAllowed())
197: allowList.add(element);
198: else
199: denyList.add(element);
200: }
201: setSunPortalGatewayAccessAllowList(allowList);
202: setSunPortalGatewayAccessDenyList(denyList);
203: }
204:
205: private void setSunPortalGatewayAccessAllowList(
206: List sunPortalGatewayAccessAllowList) {
207: this .sunPortalGatewayAccessAllowList = sunPortalGatewayAccessAllowList;
208: List allowList = convertAclListToUrlList(this .sunPortalGatewayAccessAllowList);
209: updateAttributeNVMap(ALLOW_LIST, allowList);
210: }
211:
212: /**
213: * @param list
214: */
215: private List convertAclListToUrlList(List aclObjectlist) {
216: // Using a list of ACL objects, create a list of String objects of the
217: // URL's contained in the ACL object
218: List list = new ArrayList();
219: Iterator iter = aclObjectlist.iterator();
220: while (iter.hasNext()) {
221: ACL element = (ACL) iter.next();
222: if (!element.isEmpty())
223: list.add(element.getUrl());
224: }
225: /*This done so that when we save at a level other than top the setAttributes() call
226: // throws an exception. As per Prashant, if the list being passed to setAttributes() is empty
227: // we need to put an empty string in it.
228: if ( list.isEmpty())
229: list.add("");*/
230: return list;
231: }
232:
233: public void addNewURL() {
234: if (_allowDenyDataProvider.canAppendRow()) {
235: _allowDenyDataProvider.appendRow(new ACL(EMPTY_STRING,
236: false));
237: _allowDenyDataProvider.commitChanges();
238: }
239: }
240:
241: public void deleteURL() {
242: _allowDenyDataProvider.commitChanges();
243: ACL[] allowDenyArray = (ACL[]) _allowDenyDataProvider.getList()
244: .toArray(new ACL[0]);
245:
246: for (int i = 0; i < allowDenyArray.length; i++) {
247: ACL acl = allowDenyArray[i];
248:
249: if (acl.getSelected()) {
250: _allowDenyDataProvider.removeObject(acl);
251: }
252: }
253: _allowDenyDataProvider.commitChanges();
254: setAllowDenyList();
255:
256: storeDataToStore(ALLOW_LIST);
257: storeDataToStore(DENY_LIST);
258: }
259:
260: public boolean isServiceAssigned() {
261: return isServiceAssigned("srapGatewayAccessService");
262: }
263: }
|