Results 1 to 10 of 10

Thread: how to change password without logging out

  1. #1
    Join Date
    Jun 2005
    Posts
    22

    Default how to change password without logging out

    hi,

    when my application users change their password, they should relogin again!

    I get current user from SecurityContext change the password in the UserDetail object and persist it using Hibernate, but at this point the user is logged out and should relogin with new password,

    how should I solve this problem?

    I'm using Acegi 0.7.
    Amir Pashazadeh
    Payeshgaran MT.
    پايشگران مديريت طرح
    www.payeshgaran.org
    www.payeshgaran.net

  2. #2
    Join Date
    Mar 2005
    Posts
    13

    Default

    Code:
    net.sf.acegisecurity.context.ContextHolder.setContext(null);
    and direct the user to a secured page to trigger authentication.

  3. #3

    Default

    I'd like to keep my users logged-in after a password change.

    Currently, I update the user by using a Hibernate DAO.
    I also update the current Acegi user:
    Code:
    ((User) auth.getPrincipal()).setPassword(newPassword);
    However, after this step, my users are presented are redirected to a login page ("Authentication failed due to incorrect password for user: ...").

    What's the correct way to handle this scenario.

  4. #4
    Join Date
    Jun 2005
    Posts
    22

    Default

    Quote Originally Posted by plethora
    I'd like to keep my users logged-in after a password change.

    Currently, I update the user by using a Hibernate DAO.
    I also update the current Acegi user:
    Code:
    ((User) auth.getPrincipal()).setPassword(newPassword);
    However, after this step, my users are presented are redirected to a login page ("Authentication failed due to incorrect password for user: ...").

    What's the correct way to handle this scenario.
    just the same problem I have.
    Amir Pashazadeh
    Payeshgaran MT.
    پايشگران مديريت طرح
    www.payeshgaran.org
    www.payeshgaran.net

  5. #5
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    The DAOAuthenticationProvider makes use of a cache to avoid having to go to the database on each request. So it isn't enough to change the password in the database, you have to remove the cached user info too, otherwise the provider will make the comparison of your new against this stale version and find they don't match.

    I think this is likely to be causing your problem.

    The UserCache interface has a method to allow you to remove a user:

    http://acegisecurity.sourceforge.net...UserCache.html

  6. #6

    Default

    Using the following solved my problem:
    Code:
            final SecureContextImpl newContext = new SecureContextImpl();
            newContext.setAuthentication(new UsernamePasswordAuthenticationToken(username, newPassword));
            ContextHolder.setContext(newContext);

  7. #7
    Join Date
    Mar 2005
    Posts
    13

    Default

    As an aside: I think another implication of password change is the impact on RememberMe. RememberMe encrypts the username and password in a cookie. The next time you login it will query the database to make sure the password still matches the username. Since the password in the database has changed, the rememberMe doesn't kick in and the user is forced to authenticate. A crafty solution would be to rebuild the cookie with the new password when the user changes the password.

  8. #8

    Default

    All this seems a lot of work for the most basic of functionalities - changing a users password.

    Improved documentation on topics like these would be a welcome addition to the documentation.

  9. #9
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Please feel free to submit documentation improvements to JIRA and we will be pleased to apply them. Alternatively, write a blog/WWW article on them and we will be pleased to link them.

    This topic (changing a user's password) is covered frequently in the forums and a quick search will show you the required steps.
    Ben Alex
    Project Founder, Spring UAA, Spring Roo and Spring Security

  10. #10
    Join Date
    Jun 2005
    Posts
    22

    Default

    I believe the thing about Remember Me is how it should be, a user may login on different computers using Remember Me option, so it is good to ask for password after changing it.
    Amir Pashazadeh
    Payeshgaran MT.
    پايشگران مديريت طرح
    www.payeshgaran.org
    www.payeshgaran.net

Similar Threads

  1. change password with dao not being refreshed
    By tractis_rectis in forum Security
    Replies: 6
    Last Post: Oct 26th, 2005, 03:14 PM
  2. Forgot password (e.g. secret question) using Acegi
    By lowerymb77 in forum Security
    Replies: 1
    Last Post: Oct 16th, 2005, 10:46 PM
  3. Change Password interim step
    By markstgodard in forum Security
    Replies: 5
    Last Post: Jul 19th, 2005, 02:59 AM
  4. Replies: 4
    Last Post: Jun 14th, 2005, 09:28 PM
  5. Change password
    By jivesociety in forum Security
    Replies: 6
    Last Post: Nov 5th, 2004, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •