001: /**
002: * $Id: EditAuthlessBean.java,v 1.4 2005/09/21 15:29:57 fo160993 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.ssoa;
014:
015: import java.util.*;
016: import java.util.logging.Level;
017: import java.io.IOException;
018:
019: import javax.faces.application.FacesMessage;
020: import javax.faces.context.FacesContext;
021: import javax.faces.validator.ValidatorException;
022:
023: import javax.management.Attribute;
024: import javax.management.ObjectName;
025: import javax.management.MBeanServerConnection;
026: import javax.management.MalformedObjectNameException;
027:
028: import javax.servlet.http.HttpServletRequest;
029:
030: import com.sun.data.provider.DataProvider;
031: import com.sun.data.provider.impl.ObjectListDataProvider;
032: import com.sun.web.ui.component.RadioButton;
033: import com.sun.web.ui.component.Checkbox;
034: import com.sun.web.ui.model.Option;
035:
036: import com.sun.portal.admin.common.util.AdminClientUtil;
037:
038: import com.sun.portal.admin.console.common.PSBaseBean;
039:
040: public class EditAuthlessBean extends PSBaseBean {
041:
042: // public static final String ATTR_SELECTED_TEMPLATE = "ssoa.template.selected";
043: public static final String RB_NAME = "ssoa";
044:
045: protected Map rbMap;
046:
047: // users is the ObjectListDataProvider that is based off a list of UserDnBeans
048: protected DataProvider users = null;
049: // usersList is a list of UserDnBeans
050: protected List usersList = new ArrayList();
051: // authorizedUsers is the list returned by the server MBean
052: protected List authorizedUsers = null;
053:
054: protected ObjectName objectName = null;
055:
056: // Limit the search to users
057: private Option[] objTypes = null;
058:
059: /** Creates a new instance of EditAuthlessBean*/
060: public EditAuthlessBean() {
061: log(Level.FINEST, "Start constructor");
062: // Get resource bundle
063: rbMap = getResourceStringMap(RB_NAME);
064:
065: // MBean path of SSOAdapter.
066: LinkedList path = new LinkedList();
067: path.addFirst(getDomain());
068: path.addFirst("ssoadapter");
069:
070: try {
071: objectName = AdminClientUtil.getResourceMBeanObjectName(
072: AdminClientUtil.SSOADAPTER_MBEAN_TYPE, path);
073: } catch (MalformedObjectNameException e) {
074: log(
075: Level.SEVERE,
076: "EditAuthlessBean.EditAuthlessBean(): Exception when getting MBean object name",
077: e);
078: }
079: resetAuthlessList();
080:
081: objTypes = new Option[1];
082: objTypes[0] = new Option("1", "user");
083: }
084:
085: public DataProvider getUsers() {
086: return users;
087: }
088:
089: public Option[] getObjTypes() {
090: return objTypes;
091: }
092:
093: // Do the mbean server connection to pull the template names. Will also reset the data
094: // object to reflect the template names
095: private void resetAuthlessList() {
096: log(Level.FINEST, "Start resetting the Authless list");
097: // SSOA templates names are returned by SSOAdapter MBean method resetAuthlessList
098: MBeanServerConnection conn = getMBeanServerConnection();
099: try {
100: // This can throw AttributeNotFoundException, MBeanException, InstanceNotFoundException
101: // ReflectionException, RuntimeOperationsException, or IOException
102: authorizedUsers = (List) conn.getAttribute(objectName,
103: "AuthorizedAuthlessUsers");
104: } catch (Exception ex) {
105: log(
106: Level.SEVERE,
107: "EditAuthlessBean.resetAuthlessList(): Exception when trying to get the list of authorized authless users",
108: ex);
109: }
110: usersList = new ArrayList(authorizedUsers.size());
111: Collections.sort(authorizedUsers);
112: Iterator iter = authorizedUsers.iterator();
113: while (iter.hasNext()) {
114: String dn = (String) iter.next();
115: usersList.add(new UserDnBean(dn));
116: }
117: users = new ObjectListDataProvider(usersList);
118: }
119:
120: // Do the mbean server connection to save the current authless user list. Will also reset the data
121: // object to reflect the latest authless users
122: private void saveAuthlessList() {
123: log(Level.FINEST, "Save authless list start");
124: MBeanServerConnection conn = getMBeanServerConnection();
125: try {
126: // This can throw AttributeNotFoundException, MBeanException, InstanceNotFoundException
127: // ReflectionException, RuntimeOperationsException, or IOException
128: Attribute att = new Attribute("AuthorizedAuthlessUsers",
129: authorizedUsers);
130: conn.setAttribute(objectName, att);
131: } catch (Exception ex) {
132: log(
133: Level.SEVERE,
134: "EditAuthlessBean.saveAuthlessList(): Exception when trying to save the list of authorized authless users",
135: ex);
136: }
137: resetAuthlessList();
138: }
139:
140: public String gotoConfigurationsByDnHome() {
141: String userDn = (String) RadioButton.getSelected("rb");
142: setSessionAttribute(ATTR_CURRENT_LOCATION_DN, userDn);
143: log(Level.FINEST, "gotoConfigurationsByDnHome: " + userDn);
144: return "gotoConfigurationsByDnHome";
145: }
146:
147: public String gotoAddAuthlessUser() {
148: log(Level.FINEST, "EditAuthlessBean.gotoAddAuthlessUser start");
149: return "gotoAddAuthlessUser";
150: }
151:
152: // This will find the checkbox list of dns and add them one
153: // at a time. Then it will save the list and return the user to the
154: // edit authless page
155: public String addUsers() {
156: log(Level.FINEST, "EditAuthlessBean.addUsers start");
157: //RowKey[] rkey = amLocations.getRowKeys(1000, null);
158: List selectedcbs = Checkbox.getSelected("dncb");
159: for (Iterator i = selectedcbs.iterator(); i.hasNext();) {
160: String dn = (String) i.next();
161: addUser(dn);
162: }
163: saveAuthlessList();
164: return back();
165: }
166:
167: public String cancel() {
168: return "gotoAuthlessHome";
169: }
170:
171: public String back() {
172: return "back";
173: }
174:
175: // This is a private class to add one user to the authorizedUsers list
176: // It does not save the data to the store.
177: private void addUser(String dn) {
178: log(Level.FINEST, "EditAuthlessBean.addUser start");
179: if (authorizedUsers.size() == 0) {
180: authorizedUsers = new ArrayList();
181: }
182: for (Iterator i = authorizedUsers.iterator(); i.hasNext();) {
183: String userdn = (String) i.next();
184: if (userdn.equalsIgnoreCase(dn)) {
185: log(Level.FINEST,
186: "EditAuthlessBean.addUser duplicate dn found: "
187: + dn);
188: return;
189: }
190: }
191: log(Level.FINEST, "EditAuthlessBean.addUser adding dn: " + dn);
192: authorizedUsers.add(dn);
193: }
194:
195: public void removeUsers() {
196: log(Level.FINEST, "Remove users start");
197: List selectedcbs = Checkbox.getSelected("dncb");
198: for (Iterator i = selectedcbs.iterator(); i.hasNext();) {
199: String userDn = (String) i.next();
200: if ((userDn == null) || (userDn.length() == 0)) {
201: log(Level.WARNING, "Invalid user dn supplied");
202: continue;
203: }
204: log(Level.FINEST, "Removing user " + userDn + " from list");
205: authorizedUsers.remove(userDn);
206: }
207: //String userDn = (String)RadioButton.getSelected("rb");
208: saveAuthlessList();
209: }
210:
211: }
|