taylor 2004/09/19 16:54:31
Modified:
applications/pam/src/java/org/apache/jetspeed/portlets/security/resources
SecurityResources_en.properties
SecurityResources.properties
applications/pam/src/java/org/apache/jetspeed/portlets/security
UserDetailsPortlet.java
applications/pam/src/java/org/apache/jetspeed/portlets/security/users
JetspeedUserBean.java
Log:
User Attributes tab UI maintenance
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.3 +11 -1
jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_en.properties
Index: SecurityResources_en.properties
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_en.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SecurityResources_en.properties 17 Sep 2004 23:26:20 -0000 1.2
+++ SecurityResources_en.properties 19 Sep 2004 23:54:31 -0000 1.3
@@ -15,12 +15,22 @@
# $Id$
#
+## general security strings
+security.name=Name
+security.value=Value
+security.update=Update
+security.remove=Remove
+security.add=Add
+
## User Information Tabs
pam.details.tabs.user_attributes=Attributes
pam.details.tabs.user_security=Security
pam.details.tabs.user_profile=Profile
+## tree
tree.security.root=Jetspeed Security
tree.user.root=Users
+## user
user.principal.name=Principal
+
1.4 +11 -1
jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources.properties
Index: SecurityResources.properties
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SecurityResources.properties 17 Sep 2004 23:26:20 -0000 1.3
+++ SecurityResources.properties 19 Sep 2004 23:54:31 -0000 1.4
@@ -15,12 +15,22 @@
# $Id$
#
+## general security strings
+security.name=Name
+security.value=Value
+security.update=Update
+security.remove=Remove
+security.add=Add
+
## User Information Tabs
pam.details.tabs.user_attributes=Attributes
pam.details.tabs.user_security=Security
pam.details.tabs.user_profile=Profile
+## tree
tree.security.root=Jetspeed Security
tree.user.root=Users
+## user
user.principal.name=Principal
+
1.4 +119 -2
jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserDetailsPortlet.java
Index: UserDetailsPortlet.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserDetailsPortlet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UserDetailsPortlet.java 17 Sep 2004 23:26:20 -0000 1.3
+++ UserDetailsPortlet.java 19 Sep 2004 23:54:31 -0000 1.4
@@ -16,7 +16,11 @@
package org.apache.jetspeed.portlets.security;
import java.io.IOException;
+import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.prefs.Preferences;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
@@ -30,6 +34,7 @@
import org.apache.jetspeed.portlets.pam.PortletApplicationResources;
import org.apache.jetspeed.portlets.pam.beans.TabBean;
import org.apache.jetspeed.portlets.security.users.JetspeedUserBean;
+import org.apache.jetspeed.portlets.security.users.JetspeedUserBean.StringAttribute;
import org.apache.jetspeed.security.User;
import org.apache.jetspeed.security.UserManager;
@@ -44,6 +49,10 @@
public class UserDetailsPortlet extends ServletPortlet
{
private final String VIEW_USER = "user";
+ private final String USER_ACTION_PREFIX = "security_user.";
+ private final String ACTION_UPDATE_ATTRIBUTE = "update_user_attribute";
+ private final String ACTION_REMOVE_ATTRIBUTE = "remove_user_attribute";
+ private final String ACTION_ADD_ATTRIBUTE = "add_user_attribute";
private UserManager manager;
@@ -115,9 +124,117 @@
actionRequest.getPortletSession().setAttribute(
PortletApplicationResources.REQUEST_SELECT_TAB, tab);
}
- }
+ }
+ String action =
actionRequest.getParameter(PortletApplicationResources.PORTLET_ACTION);
+ if (action != null && isUserPortletAction(action))
+ {
+ action = getAction(USER_ACTION_PREFIX, action);
+ if (action.endsWith(ACTION_UPDATE_ATTRIBUTE))
+ {
+ updateUserAttribute(actionRequest, actionResponse);
+ }
+ else if(action.endsWith(ACTION_REMOVE_ATTRIBUTE))
+ {
+ removeUserAttributes(actionRequest, actionResponse);
+ }
+ else if(action.endsWith(ACTION_ADD_ATTRIBUTE))
+ {
+ addUserAttribute(actionRequest, actionResponse);
+ }
+ }
}
+ private void updateUserAttribute(ActionRequest actionRequest, ActionResponse
actionResponse)
+ {
+ String userName = (String)
+
actionRequest.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_USER,
+ PortletSession.APPLICATION_SCOPE);
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String[] userAttrNames =
actionRequest.getParameterValues("user_attr_id");
+ if(userAttrNames != null)
+ {
+ for (int i=0; i<userAttrNames.length; i++)
+ {
+ String userAttrName = userAttrNames[i];
+ String value = actionRequest.getParameter(userAttrName +
":value");
+ user.getUserAttributes().put(userAttrName, value);
+ }
+ }
+ }
+ }
+
+ private void addUserAttribute(ActionRequest actionRequest, ActionResponse
actionResponse)
+ {
+ String userName = (String)
+
actionRequest.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_USER,
+ PortletSession.APPLICATION_SCOPE);
+
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String userAttrName = actionRequest.getParameter("user_attr_name");
+ String userAttrValue = actionRequest.getParameter("user_attr_value");
+ if (userAttrName != null && userAttrName.trim().length() > 0)
+ {
+ Preferences attributes = user.getUserAttributes();
+ attributes.put(userAttrName, userAttrValue);
+ }
+ }
+ }
+
+ private void removeUserAttributes(ActionRequest actionRequest, ActionResponse
actionResponse)
+ {
+ String userName = (String)
+
actionRequest.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_USER,
+ PortletSession.APPLICATION_SCOPE);
+ List deletes = new LinkedList();
+
+ User user = lookupUser(userName);
+ if (user != null)
+ {
+ String[] userAttrNames =
actionRequest.getParameterValues("user_attr_id");
+
+ if(userAttrNames != null)
+ {
+ JetspeedUserBean bean = new JetspeedUserBean(user);
+ Preferences attributes = user.getUserAttributes();
+ Iterator userAttrIter = bean.getAttributes().iterator();
+ while (userAttrIter.hasNext())
+ {
+ StringAttribute userAttr = (StringAttribute)
userAttrIter.next();
+ for(int ix = 0; ix < userAttrNames.length; ix++)
+ {
+ String userAttrName = userAttrNames[ix];
+ if(userAttr.getName().equals(userAttrName))
+ {
+ deletes.add(userAttrName);
+ break;
+ }
+ }
+ }
+ Iterator it = deletes.iterator();
+ while (it.hasNext())
+ {
+ String attribute = (String)it.next();
+ attributes.remove(attribute);
+ }
+
+ }
+ }
+ }
+
+ private String getAction(String prefix, String action)
+ {
+ return action.substring(prefix.length());
+ }
+
+ private boolean isUserPortletAction(String action)
+ {
+ return action.startsWith(USER_ACTION_PREFIX);
+ }
+
private User lookupUser(String userName)
{
User user = null;
1.3 +57 -3
jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.java
Index: JetspeedUserBean.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JetspeedUserBean.java 17 Sep 2004 23:26:21 -0000 1.2
+++ JetspeedUserBean.java 19 Sep 2004 23:54:31 -0000 1.3
@@ -16,7 +16,11 @@
package org.apache.jetspeed.portlets.security.users;
import java.security.Principal;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;
import javax.security.auth.Subject;
@@ -31,13 +35,25 @@
*/
public class JetspeedUserBean
{
- private String principal;
+ private String principal;
+ private List attributes = new ArrayList();
public JetspeedUserBean(User user)
{
Principal userPrincipal = createPrincipal(user.getSubject(),
UserPrincipal.class);
-
this.principal = userPrincipal.getName();
+ try
+ {
+ Preferences userAttributes = user.getUserAttributes();
+ String[] keys = userAttributes.keys();
+ for (int ix = 0; ix < keys.length; ix++)
+ {
+ attributes.add(new StringAttribute(keys[ix],
userAttributes.get(keys[ix], "n/a")));
+ }
+ }
+ catch (BackingStoreException e)
+ {
+ }
}
/**
@@ -71,4 +87,42 @@
return principal;
}
+ /**
+ * @return Returns the attributes.
+ */
+ public List getAttributes()
+ {
+ return attributes;
+ }
+
+ /**
+ * TODO: support all attributes types (int, double, date, etc..)
+ * @author David Sean Taylor
+ *
+ */
+ public class StringAttribute
+ {
+ private String name;
+ private String value;
+
+ public StringAttribute(String name, String value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+ /**
+ * @return Returns the value.
+ */
+ public String getValue()
+ {
+ return value;
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]