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 wo...@apache.org on 2008/09/09 16:42:52 UTC
svn commit: r693475 -
/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/registration/ForgottenPasswordPortlet.java
Author: woonsan
Date: Tue Sep 9 07:42:52 2008
New Revision: 693475
URL: http://svn.apache.org/viewvc?rev=693475&view=rev
Log:
Flattening Security APIs.
Modified ForgottenPasswordPortlet to use new security APIs.
Modified:
portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/registration/ForgottenPasswordPortlet.java
Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/registration/ForgottenPasswordPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/registration/ForgottenPasswordPortlet.java?rev=693475&r1=693474&r2=693475&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/registration/ForgottenPasswordPortlet.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/registration/ForgottenPasswordPortlet.java Tue Sep 9 07:42:52 2008
@@ -18,19 +18,14 @@
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.security.Principal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
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;
import javax.portlet.PortletConfig;
@@ -53,7 +48,6 @@
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.User;
import org.apache.jetspeed.security.UserManager;
-import org.apache.jetspeed.security.UserPrincipal;
import org.apache.portals.bridges.velocity.AbstractVelocityMessagingPortlet;
import org.apache.portals.gems.util.ValidationHelper;
import org.apache.velocity.context.Context;
@@ -181,8 +175,11 @@
// Here's where a break should be. The following code should be put into the RETURN portlet
try
{
- userManager.setPassword(userName, null, newPassword);
- userManager.setPasswordUpdateRequired(userName, true);
+ User user = userManager.getUser(userName);
+ PasswordCredential pwc = userManager.getPasswordCredential(user);
+ pwc.setPassword(null, newPassword);
+ pwc.setUpdateRequired(true);
+
// if we got here stuff is changed... removed the key from the map
admin.removeNewLoginInfo(guid);
} catch (SecurityException e)
@@ -276,24 +273,13 @@
try
{
- String userName = getUserName(user);
+ String userName = user.getName();
String newPassword = admin.generatePassword();
String urlGUID = makeGUID(userName, newPassword);
- Preferences pref = user.getUserAttributes();
- String[] keys = pref.keys();
- Map userAttributes = new HashMap();
- if (keys != null)
- {
- for (int ix = 0; ix < keys.length; ix++)
- {
- // TODO: how the hell do i tell the pref type
- // ASSuming they are all strings (sigh)
- userAttributes.put(keys[ix], pref.get(keys[ix], ""));
- }
- }
+ Map<String, String> userAttributes = user.getInfoMap();
// special attributes
userAttributes.put(CTX_RETURN_URL, generateReturnURL(request,
response, urlGUID));
@@ -311,7 +297,7 @@
//TODO this is currently hacked with a hashmap... needs to move to either a DB table
// or to some sort of credential
- Map map = new HashMap();
+ Map<String, String> map = new HashMap<String, String>();
map.put("user.name",userName);
map.put("password",newPassword);
admin.putNewLoginInfo(urlGUID, map);
@@ -369,43 +355,6 @@
return admin.getPortalURL(request, response, this.redirectPath);
}
- protected String getUserName(User user)
- {
- Principal principal = null;
- Iterator principals = user.getSubject().getPrincipals().iterator();
- while (principals.hasNext())
- {
- Object o = principals.next();
- if (o instanceof UserPrincipal)
- {
- principal = (Principal) o;
- return principal.toString();
- }
-
- }
- return null;
- }
-
- protected String getPassword(User user)
- {
- PasswordCredential credential = null;
-
- Set credentials = user.getSubject().getPrivateCredentials();
- Iterator iter = credentials.iterator();
- while (iter.hasNext())
- {
- Object o = iter.next();
- if (o instanceof PasswordCredential)
- {
- credential = (PasswordCredential) o;
- char[] charar = credential.getPassword();
-
- return new String(charar);
- }
- }
- return null;
- }
-
protected List makeMessage(String msg)
{
List errors = new LinkedList();
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org