You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2008/09/18 12:05:11 UTC
svn commit: r696619 - in
/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets:
localeselector/ security/users/
Author: ate
Date: Thu Sep 18 03:05:11 2008
New Revision: 696619
URL: http://svn.apache.org/viewvc?rev=696619&view=rev
Log:
Simplifying SecurityAttributes handing for adding/updating attributes
Modified:
portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/localeselector/LocaleSelectorPortlet.java
portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java
portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserDetails.java
Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/localeselector/LocaleSelectorPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/localeselector/LocaleSelectorPortlet.java?rev=696619&r1=696618&r2=696619&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/localeselector/LocaleSelectorPortlet.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/localeselector/LocaleSelectorPortlet.java Thu Sep 18 03:05:11 2008
@@ -34,7 +34,8 @@
import org.apache.jetspeed.CommonPortletServices;
import org.apache.jetspeed.PortalReservedParameters;
import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.security.AttributeTypeNotFoundException;
+import org.apache.jetspeed.security.AttributeReadOnlyException;
+import org.apache.jetspeed.security.AttributesNotExtendableException;
import org.apache.jetspeed.security.AttributesReadOnlyException;
import org.apache.jetspeed.security.SecurityAttributes;
import org.apache.jetspeed.security.SecurityException;
@@ -132,12 +133,17 @@
// TODO Auto-generated catch block
e.printStackTrace();
}
- catch (AttributeTypeNotFoundException e)
+ catch (SecurityException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
- catch (SecurityException e)
+ catch (AttributeReadOnlyException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (AttributesNotExtendableException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java?rev=696619&r1=696618&r2=696619&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java Thu Sep 18 03:05:11 2008
@@ -28,7 +28,6 @@
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
-import java.util.prefs.Preferences;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
@@ -59,8 +58,8 @@
import org.apache.jetspeed.profiler.Profiler;
import org.apache.jetspeed.profiler.rules.PrincipalRule;
import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.security.AttributeAlreadyExistsException;
-import org.apache.jetspeed.security.AttributeTypeAlreadyDefinedException;
+import org.apache.jetspeed.security.AttributeReadOnlyException;
+import org.apache.jetspeed.security.AttributeRequiredException;
import org.apache.jetspeed.security.AttributesNotExtendableException;
import org.apache.jetspeed.security.AttributesReadOnlyException;
import org.apache.jetspeed.security.Group;
@@ -71,7 +70,7 @@
import org.apache.jetspeed.security.PasswordCredential;
import org.apache.jetspeed.security.Role;
import org.apache.jetspeed.security.RoleManager;
-import org.apache.jetspeed.security.SecurityAttributeType;
+import org.apache.jetspeed.security.SecurityAttribute;
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.User;
import org.apache.jetspeed.security.UserManager;
@@ -788,29 +787,37 @@
{
try
{
- user.getSecurityAttributes().addNewInfoAttribute(attr.getName(),SecurityAttributeType.DataType.STRING).setStringValue(value);
+ user.getSecurityAttributes().getAttribute(attr.getName(),true).setStringValue(value);
+ //user.getInfoMap().put(attr.getName(), value);
+ audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
+ AuditActivity.USER_ADD_ATTRIBUTE, attr.getName(), value, value, USER_ADMINISTRATION);
}
catch (AttributesReadOnlyException aroe)
{
- SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"ReadOnly expecton");
- }
- catch (AttributeTypeAlreadyDefinedException e)
- {
- SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Alreadydefined expecton");
- }
- catch (AttributeAlreadyExistsException e)
- {
- SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"AlreadyExits expecton");
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attributes read only");
+ return;
}
catch (AttributesNotExtendableException e)
{
- SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"NotExtendable expecton");
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attributes not extendable");
+ return;
}
- //user.getInfoMap().put(attr.getName(), value);
- audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
- AuditActivity.USER_ADD_ATTRIBUTE, attr.getName(), value, value, USER_ADMINISTRATION);
+ catch (AttributeReadOnlyException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attribute read only");
+ return;
+ }
}
}
+ try
+ {
+ userManager.updateUser(user);
+ }
+ catch (SecurityException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER, e.getMessage());
+ return;
+ }
}
if ("true".equals(actionRequest.getPreferences().getValue("showPasswordOnUserTab", "false")))
{
@@ -827,15 +834,48 @@
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");
- String before = user.getInfoMap().get(userAttrName);
- user.getSecurityAttributes().getAttribute(userAttrName).setStringValue(value);
- audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
- AuditActivity.USER_UPDATE_ATTRIBUTE, userAttrName, before, value, USER_ADMINISTRATION);
- }
+ for (int i = 0; i < userAttrNames.length; i++)
+ {
+ String userAttrName = userAttrNames[i];
+ String value = actionRequest.getParameter(userAttrName + ":value");
+ String before = null;
+ SecurityAttribute attr;
+ try
+ {
+ attr = user.getSecurityAttributes().getAttribute(userAttrName, true);
+ before = attr.getStringValue();
+ if (before == null)
+ {
+ before = "";
+ }
+ attr.setStringValue(value);
+ audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
+ AuditActivity.USER_UPDATE_ATTRIBUTE, userAttrName, before, value, USER_ADMINISTRATION);
+ }
+ catch (AttributeReadOnlyException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attribute read only");
+ return;
+ }
+ catch (AttributesReadOnlyException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attributes read only");
+ return;
+ }
+ catch (AttributesNotExtendableException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attributes not extendable");
+ return;
+ }
+ }
+ try
+ {
+ this.userManager.updateUser(user);
+ }
+ catch (SecurityException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER, e.getMessage());
+ }
}
}
}
@@ -850,34 +890,29 @@
String userAttrValue = actionRequest.getParameter("user_attr_value");
if (userAttrName != null && userAttrName.trim().length() > 0)
{
- Map<String,String> attributes = user.getInfoMap();
try
{
- user.getSecurityAttributes().addNewInfoAttribute(userAttrName, SecurityAttributeType.DataType.STRING).setStringValue(userAttrValue);
- }
- catch (AttributesReadOnlyException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (AttributeTypeAlreadyDefinedException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (AttributeAlreadyExistsException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (AttributesNotExtendableException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- attributes.put(userAttrName, userAttrValue);
- audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
- AuditActivity.USER_ADD_ATTRIBUTE, userAttrName, "", userAttrValue, USER_ADMINISTRATION);
+ user.getSecurityAttributes().getAttribute(userAttrName, true).setStringValue(userAttrValue);
+ this.userManager.updateUser(user);
+ audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
+ AuditActivity.USER_ADD_ATTRIBUTE, userAttrName, "", userAttrValue, USER_ADMINISTRATION);
+ }
+ catch (SecurityException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER, e.getMessage());
+ }
+ catch (AttributeReadOnlyException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attribute read only");
+ }
+ catch (AttributesReadOnlyException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attributes read only");
+ }
+ catch (AttributesNotExtendableException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attributes not extendable");
+ }
}
}
}
@@ -893,22 +928,54 @@
if (userAttrNames != null)
{
+ boolean save = false;
// Preferences attributes = user.getUserAttributes();
for (int ix = 0; ix < userAttrNames.length; ix++)
{
- Map<String, String> userAttributes = user.getInfoMap();
- try
- {
- String before = userAttributes.get(userAttrNames[ix]);
- user.getSecurityAttributes().removeAttribute(userAttrNames[ix]);
- audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
- AuditActivity.USER_DELETE_ATTRIBUTE, userAttrNames[ix], before, "", USER_ADMINISTRATION);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
+ SecurityAttribute attr;
+ try
+ {
+ attr = user.getSecurityAttributes().getAttribute(userAttrNames[ix], false);
+ if (attr != null)
+ {
+ user.getSecurityAttributes().removeAttribute(userAttrNames[ix]);
+ save = true;
+ audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
+ AuditActivity.USER_DELETE_ATTRIBUTE, userAttrNames[ix], attr.getStringValue(), "", USER_ADMINISTRATION);
+ }
+ }
+ catch (AttributeReadOnlyException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attribute read only");
+ return;
+ }
+ catch (AttributesReadOnlyException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attributes read only");
+ return;
+ }
+ catch (AttributesNotExtendableException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attributes not extendable");
+ return;
+ }
+ catch (AttributeRequiredException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Attribute is required");
+ return;
+ }
+ }
+ if (save)
+ {
+ try
+ {
+ this.userManager.updateUser(user);
+ }
+ catch (SecurityException e)
+ {
+ SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER, e.getMessage());
+ }
+ }
}
}
}
Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserDetails.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserDetails.java?rev=696619&r1=696618&r2=696619&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserDetails.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserDetails.java Thu Sep 18 03:05:11 2008
@@ -27,7 +27,6 @@
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
-import java.util.prefs.BackingStoreException;
import javax.security.auth.Subject;
@@ -40,8 +39,8 @@
import org.apache.jetspeed.portlets.wicket.component.TextFieldPropertyColumn;
import org.apache.jetspeed.profiler.rules.PrincipalRule;
import org.apache.jetspeed.profiler.rules.ProfilingRule;
-import org.apache.jetspeed.security.AttributeAlreadyExistsException;
-import org.apache.jetspeed.security.AttributeTypeAlreadyDefinedException;
+import org.apache.jetspeed.security.AttributeReadOnlyException;
+import org.apache.jetspeed.security.AttributeRequiredException;
import org.apache.jetspeed.security.AttributesNotExtendableException;
import org.apache.jetspeed.security.AttributesReadOnlyException;
import org.apache.jetspeed.security.Group;
@@ -50,7 +49,7 @@
import org.apache.jetspeed.security.PasswordAlreadyUsedException;
import org.apache.jetspeed.security.PasswordCredential;
import org.apache.jetspeed.security.Role;
-import org.apache.jetspeed.security.SecurityAttributeType;
+import org.apache.jetspeed.security.SecurityAttribute;
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.User;
import org.apache.portals.messaging.PortletMessaging;
@@ -370,9 +369,7 @@
{
public void onSubmit()
{
- //Preferences prefs = user.getUserAttributes();
- Map<String,String> attribs = user.getInfoMap();
-
+ boolean save = false;
for (Iterator it = userAttributes.iterator(); it.hasNext(); )
{
Map userAttrMap = (Map) it.next();
@@ -381,12 +378,52 @@
{
String userAttrName = (String) userAttrMap.get("name");
String userAttrValue = (String) userAttrMap.get("value");
- attribs.remove(userAttrName);
-
- getAuditActivity().logAdminAttributeActivity(getPortletRequest().getUserPrincipal().getName(), getIPAddress(), getUserName(), AuditActivity.USER_DELETE_ATTRIBUTE, userAttrName, userAttrValue, "", USER_ADMINISTRATION);
+ SecurityAttribute attr = user.getSecurityAttributes().getAttribute(userAttrName);
+ if ( attr != null)
+ {
+ userAttrValue = attr.getStringValue();
+ try
+ {
+ user.getSecurityAttributes().removeAttribute(userAttrName);
+ getAuditActivity().logAdminAttributeActivity(getPortletRequest().getUserPrincipal().getName(), getIPAddress(), getUserName(), AuditActivity.USER_DELETE_ATTRIBUTE, userAttrName, userAttrValue, "", USER_ADMINISTRATION);
+ save = true;
+ }
+ catch (AttributesReadOnlyException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ save = false;
+ break;
+ }
+ catch (AttributeReadOnlyException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ save = false;
+ break;
+ }
+ catch (AttributeRequiredException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ save = false;
+ break;
+ }
+ }
+ }
+ }
+ if (save)
+ {
+ try
+ {
+ getUserManager().updateUser(user);
+ }
+ catch (SecurityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
}
-
refreshData();
}
};
@@ -409,29 +446,30 @@
//prefs.put(userAttrName, userAttrValue);
try
{
- user.getSecurityAttributes().addNewInfoAttribute(userAttrName,SecurityAttributeType.DataType.STRING).setStringValue(userAttrValue);
+ user.getSecurityAttributes().getAttribute(userAttrName, true).setStringValue(userAttrValue);
+ getUserManager().updateUser(user);
+ getAuditActivity().logAdminAttributeActivity(getPortletRequest().getUserPrincipal().getName(), getIPAddress(), getUserName(), AuditActivity.USER_ADD_ATTRIBUTE, userAttrName, "", userAttrValue, USER_ADMINISTRATION);
}
catch (AttributesReadOnlyException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
- catch (AttributeTypeAlreadyDefinedException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (AttributeAlreadyExistsException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
catch (AttributesNotExtendableException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
- getAuditActivity().logAdminAttributeActivity(getPortletRequest().getUserPrincipal().getName(), getIPAddress(), getUserName(), AuditActivity.USER_ADD_ATTRIBUTE, userAttrName, "", userAttrValue, USER_ADMINISTRATION);
+ catch (AttributeReadOnlyException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (SecurityException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
refreshData();
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org