Skip to content

Commit

Permalink
Adding IAdmin.changePasswordWithOldPassword (See #911, Fix #3201)
Browse files Browse the repository at this point in the history
git-svn-id: file:///home/svn/omero/trunk@8479 05709c45-44f0-0310-885b-81a1db45b4a6
  • Loading branch information
joshmoore committed Nov 2, 2010
1 parent 75f28a7 commit 41cfa46
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
1 change: 1 addition & 0 deletions components/blitz/resources/omero/api/IAdmin.ice
Expand Up @@ -71,6 +71,7 @@ module omero {

// UAuth
idempotent void changePassword(omero::RString newPassword) throws ServerError;
idempotent void changePasswordWithOldPassword(string oldPassword, omero::RString newPassword) throws ServerError;
idempotent void changeUserPassword(string omeName, omero::RString newPassword) throws ServerError;
idempotent void synchronizeLoginCache() throws ServerError;
void changeExpiredCredentials(string name, string oldCred, string newCred) throws ServerError;
Expand Down
6 changes: 6 additions & 0 deletions components/blitz/src/ome/services/blitz/impl/AdminI.java
Expand Up @@ -24,6 +24,7 @@
import omero.api.AMD_IAdmin_changeGroup;
import omero.api.AMD_IAdmin_changeOwner;
import omero.api.AMD_IAdmin_changePassword;
import omero.api.AMD_IAdmin_changePasswordWithOldPassword;
import omero.api.AMD_IAdmin_changePermissions;
import omero.api.AMD_IAdmin_changeUserPassword;
import omero.api.AMD_IAdmin_containedExperimenters;
Expand Down Expand Up @@ -133,6 +134,11 @@ public void changePassword_async(AMD_IAdmin_changePassword __cb,
callInvokerOnRawArgs(__cb, __current, newPassword);
}

public void changePasswordWithOldPassword_async(AMD_IAdmin_changePasswordWithOldPassword __cb,
String oldPassword, RString newPassword, Current __current) throws ServerError {
callInvokerOnRawArgs(__cb, __current, oldPassword, newPassword);
}

public void changePermissions_async(AMD_IAdmin_changePermissions __cb,
IObject obj, Permissions perms, Current __current)
throws ServerError {
Expand Down
31 changes: 26 additions & 5 deletions components/common/src/ome/api/IAdmin.java
Expand Up @@ -551,19 +551,40 @@ void changeExpiredCredentials(String name, String oldCred, String newCred)
throws AuthenticationException;

/**
* change the password for the current user
*
* change the password for the current user.
* <p>
* <em>Warning:</em>This method requires the user to be authenticated
* with a password and not with a one-time session id. To avoid this
* problem, use {@link #changePasswordWithOldPassword(String, String)}.
* </p>
*
* @param newPassword
* Not-null. Must pass validation in the security sub-system.
* Possibly null to allow logging in with no password.
* @throws ome.conditions.SecurityViolation
* if the new password is too weak.
* if the user is not authenticated with a password.
* @see <a href="http://trac.openmicroscopy.org.uk/omero/ticket/911">ticket:911</a>
* @see <a href="http://trac.openmicroscopy.org.uk/omero/ticket/3201">ticket:3201</a>
*/
void changePassword(@Hidden
String newPassword);

/**
* change the password for the current user by passing the old password.
*
* @param newPassword
* Not-null. Must pass validation in the security sub-system.
* @param newPassword
* Possibly null to allow logging in with no password.
* @throws ome.conditions.SecurityViolation
* if the oldPassword is incorrect.
*/
void changePasswordWithOldPassword(
@Hidden @NotNull String oldPassword,
@Hidden String newPassword);

/**
* change the password for the a given user.
*
*
* @param newPassword
* Not-null. Might must pass validation in the security
* sub-system.
Expand Down
11 changes: 10 additions & 1 deletion components/server/src/ome/logic/AdminImpl.java
Expand Up @@ -1088,12 +1088,21 @@ public void changeExpiredCredentials(String name, String oldCred,
throw new UnsupportedOperationException();
}

@RolesAllowed({"guest", "user", "HasPassword"})
@RolesAllowed({"user", "HasPassword"})
public void changePassword(String newPassword) {
String user = getSecuritySystem().getEventContext().getCurrentUserName();
_changePassword(user, newPassword);
}

@RolesAllowed({"user"})
public void changePasswordWithOldPassword(String oldPassword, String newPassword) {
String user = getSecuritySystem().getEventContext().getCurrentUserName();
if (!checkPassword(user, oldPassword)) {
throw new SecurityViolation("Old password is invalid");
}
_changePassword(user, newPassword);
}

@RolesAllowed("user")
public void changeUserPassword(final String user, final String newPassword) {
adminOrPiOfUser(userProxy(user));
Expand Down
32 changes: 32 additions & 0 deletions components/tools/OmeroPy/test/integration/admin.py
Expand Up @@ -58,5 +58,37 @@ def testThumbnail(self):
tstore.setPixelsId(pixel.id.val)
tstore.getThumbnail(rint(16), rint(16))

def testChangePassword(self):
"""
See ticket:3201
"""

client = self.new_client()

admin = client.sf.getAdminService()
admin.changePassword(rstring("ome"))

uuid = client.getSessionId()

# Now login without a passowrd
client2 = client.createClient(True)
try:
admin = client2.sf.getAdminService()

self.assertRaises(omero.SecurityViolation, admin.changePassword, rstring("foo"))
admin.changePasswordWithOldPassword("ome", rstring("foo"))
finally:
client2.closeSession()

# Now try to change password without a secure session
if False: # Waiting on ticket:3232
client3 = client.createClient(False)
try:
admin = client3.sf.getAdminService()
self.assertRaises(omero.SecurityViolation, admin.changePasswordWithOldPassword, "foo", rstring("ome"))
finally:
client3.closeSession()


if __name__ == '__main__':
unittest.main()

0 comments on commit 41cfa46

Please sign in to comment.