keycloak-memoizeit

change password

8/13/2014 11:35:49 AM

Details

diff --git a/core/src/main/java/org/keycloak/representations/idm/CredentialRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/CredentialRepresentation.java
index 99237ee..406ded3 100755
--- a/core/src/main/java/org/keycloak/representations/idm/CredentialRepresentation.java
+++ b/core/src/main/java/org/keycloak/representations/idm/CredentialRepresentation.java
@@ -20,6 +20,8 @@ public class CredentialRepresentation {
     protected String hashedSaltedValue;
     protected String salt;
     protected Integer hashIterations;
+    // only used when updating a credential.  Might set required action
+    protected boolean temporary;
 
     public String getType() {
         return type;
@@ -68,4 +70,12 @@ public class CredentialRepresentation {
     public void setHashIterations(Integer hashIterations) {
         this.hashIterations = hashIterations;
     }
+
+    public boolean isTemporary() {
+        return temporary;
+    }
+
+    public void setTemporary(boolean temporary) {
+        this.temporary = temporary;
+    }
 }
diff --git a/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/users.js b/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/users.js
index 706cd0e..2c64127 100755
--- a/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/users.js
+++ b/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/users.js
@@ -267,7 +267,7 @@ module.controller('UserCredentialsCtrl', function($scope, realm, user, User, Use
         $scope.isTotp = user.totp;
     }
 
-    $scope.resetPassword = function() {
+    $scope.resetPassword = function(temporary) {
         if ($scope.pwdChange) {
             if ($scope.password != $scope.confirmPassword) {
                 Notifications.error("Password and confirmation does not match.");
@@ -275,8 +275,15 @@ module.controller('UserCredentialsCtrl', function($scope, realm, user, User, Use
             }
         }
 
-        Dialog.confirm('Reset password', 'Are you sure you want to reset the users password?', function() {
-            UserCredentials.resetPassword({ realm: realm.realm, userId: user.username }, { type : "password", value : $scope.password }, function() {
+        var msgTitle = 'Change password';
+        var msg = 'Are you sure you want to change the users password?';
+        if (temporary) {
+            msgTitle = 'Reset password';
+            msg = 'Are you sure you want to reset the users password?';
+        }
+
+        Dialog.confirm(msgTitle, msg, function() {
+            UserCredentials.resetPassword({ realm: realm.realm, userId: user.username }, { type : "password", value : $scope.password, temporary: temporary }, function() {
                 Notifications.success("The password has been reset");
                 $scope.password = null;
                 $scope.confirmPassword = null;
diff --git a/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/user-credentials.html b/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/user-credentials.html
index 5bc8a64..2a7656b 100755
--- a/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/user-credentials.html
+++ b/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/user-credentials.html
@@ -18,24 +18,25 @@
                 <legend><span class="text">Credential Management</span></legend>
                 <div class="form-group">
                     <label class="col-sm-2 control-label" for="password">Reset password</label>
-                    <div class="col-sm-4 kc-multiline">
-                        <input class="form-control" type="password" id="password" name="password" data-ng-model="password" placeholder="Temporary password" required>
+                    <div class="col-sm-6 kc-multiline">
+                        <input class="form-control" type="password" id="password" name="password" data-ng-model="password" placeholder="New password" required>
                         <input class="form-control" type="password" id="confirmPassword" name="confirmPassword" data-ng-model="confirmPassword" placeholder="Password confirmation" required>
-                        <button class="btn btn-danger" type="submit" data-ng-click="resetPassword()" data-ng-show="password">Reset Password</button>
+                        <button class="btn btn-danger" type="submit" data-ng-click="resetPassword(true)" data-ng-show="password" tooltip="Temporary reset of password.  User will be asked to change it when they log in." tooltip-placement="left">Reset Password</button>
+                        <button class="btn btn-danger" type="submit" data-ng-click="resetPassword(false)" data-ng-show="password" tooltip="Change the password of the user." tooltip-placement="right">Change Password</button>
                     </div>
                 </div>
 
                 <div class="form-group" data-ng-show="user.email">
                     <label class="col-sm-2 control-label" for="password">Reset password email</label>
-                    <div class="col-sm-4">
-                        <button class="btn btn-danger" type="submit" data-ng-click="resetPasswordEmail()" >Send Email</button>
+                    <div class="col-sm-5">
+                        <button class="btn btn-danger" type="submit" data-ng-click="resetPasswordEmail()" tooltip="Send an email to user with a link to reset their password" tooltip-placement="right">Send Email</button>
                     </div>
                 </div>
 
                 <div class="form-group" data-ng-show="user.totp">
                     <label class="col-sm-2 control-label" for="password">Remove totp</label>
-                    <div class="col-sm-4" data-ng-show="user.totp">
-                        <button class="btn btn-danger"  type="submit" data-ng-click="removeTotp()">Remove TOTP</button>
+                    <div class="col-sm-5" data-ng-show="user.totp">
+                        <button class="btn btn-danger"  type="submit" data-ng-click="removeTotp()" tooltip="Remove one time password generator for user." tooltip-placement="right">Remove TOTP</button>
                     </div>
                 </div>
             </fieldset>
diff --git a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java b/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java
index 278bc29..628ef9a 100755
--- a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java
+++ b/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java
@@ -775,7 +775,7 @@ public class UsersResource {
 
         UserCredentialModel cred = RepresentationToModel.convertCredential(pass);
         session.users().updateCredential(realm, user, cred);
-        user.addRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD);
+        if (pass.isTemporary()) user.addRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD);
     }
 
     /**