diff --git a/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java b/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java index a076ed2109..0fb94f01a6 100755 --- a/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java +++ b/server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java @@ -474,7 +474,8 @@ public class ModelToRepresentation { session.clientPolicy().updateRealmRepresentationFromModel(realm, rep); - rep.setAttributes(stripRealmAttributesIncludedAsFields(realm.getAttributes())); + // Append realm attributes to representation + rep.getAttributes().putAll(stripRealmAttributesIncludedAsFields(realm.getAttributes())); if (!internal) { rep = StripSecretsUtils.strip(rep); diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/TokenSettings.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/TokenSettings.java index 7f0b714b42..6c0026b65d 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/TokenSettings.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/TokenSettings.java @@ -73,6 +73,12 @@ public class TokenSettings extends RealmSettings { @FindBy(id = "actionTokenAttributeTime") private WebElement actionTokenAttributeTime; + @FindBy(name = "requestUriLifespanUnit") + private Select requestUriLifespanUnit; + + @FindBy(id = "requestUriLifespan") + private WebElement requestUriLifespanTimeout; + @FindBy(xpath = "//button[@data-ng-click='resetToDefaultToken(actionTokenId)']") private WebElement resetButton; @@ -84,13 +90,17 @@ public class TokenSettings extends RealmSettings { setTimeout(sessionLifespanTimeoutUnit, sessionLifespanTimeout, time, unit); } + public void setRequestUriLifespanTimeout(int time, TimeUnit unit) { + setTimeout(requestUriLifespanUnit, requestUriLifespanTimeout, time, unit); + } + public void setOperation(String tokenType, int time, TimeUnit unit) { selectOperation(tokenType); setTimeout(actionTokenAttributeUnit, actionTokenAttributeTime, time, unit); } private void setTimeout(Select timeoutElement, WebElement unitElement, - int timeout, TimeUnit unit) { + int timeout, TimeUnit unit) { timeoutElement.selectByValue(capitalize(unit.name().toLowerCase())); UIUtils.setTextInputValue(unitElement, valueOf(timeout)); } @@ -112,5 +122,13 @@ public class TokenSettings extends RealmSettings { actionTokenAttributeSelect.selectByValue(tokenType.toLowerCase()); pause(500); // wait for the form to be updated; there isn't currently a better way } + + public int getRequestUriLifespanTimeout() { + return Integer.parseInt(requestUriLifespanTimeout.getAttribute("value")); + } + + public TimeUnit getRequestUriLifespanUnits() { + return TimeUnit.valueOf(requestUriLifespanUnit.getFirstSelectedOption().getText().toUpperCase()); + } } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/TokensTest.java b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/TokensTest.java index 29e2691a1b..11198778fa 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/TokensTest.java +++ b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/TokensTest.java @@ -23,6 +23,7 @@ import org.junit.Before; import org.junit.Test; import org.keycloak.authentication.actiontoken.resetcred.ResetCredentialsActionToken; import org.keycloak.authentication.actiontoken.verifyemail.VerifyEmailActionToken; +import org.keycloak.models.ParConfig; import org.keycloak.models.jpa.entities.RealmAttributes; import org.keycloak.testsuite.auth.page.account.Account; import org.keycloak.testsuite.console.page.realm.TokenSettings; @@ -34,10 +35,11 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.TimeUnit; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.keycloak.testsuite.util.UIUtils.refreshPageAndWaitForLoad; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith; @@ -188,6 +190,28 @@ public class TokensTest extends AbstractRealmTest { } + @Test + public void testParRequestUriLifespan() { + int defaultMinutes = (int) TimeUnit.SECONDS.toMinutes(ParConfig.DEFAULT_PAR_REQUEST_URI_LIFESPAN); + assertThat(tokenSettingsPage.form().getRequestUriLifespanTimeout(), is(defaultMinutes)); + + tokenSettingsPage.form().setRequestUriLifespanTimeout(30, TimeUnit.MINUTES); + tokenSettingsPage.form().save(); + + assertAlertSuccess(); + + assertThat(tokenSettingsPage.form().getRequestUriLifespanTimeout(), is(30)); + assertThat(tokenSettingsPage.form().getRequestUriLifespanUnits(), is(TimeUnit.MINUTES)); + + tokenSettingsPage.form().setRequestUriLifespanTimeout(20,TimeUnit.HOURS); + tokenSettingsPage.form().save(); + + assertAlertSuccess(); + + assertThat(tokenSettingsPage.form().getRequestUriLifespanTimeout(), is(20)); + assertThat(tokenSettingsPage.form().getRequestUriLifespanUnits(), is(TimeUnit.HOURS)); + } + private Map getUserActionTokens() { Map userActionTokens = new HashMap<>(); adminClient.realm(testRealmPage.getAuthRealm()).toRepresentation().getAttributes().entrySet().stream() diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js index 9f37f1acf3..f27dabad04 100644 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js @@ -1325,8 +1325,8 @@ module.controller('RealmTokenDetailCtrl', function($scope, Realm, realm, $http, $scope.realm.actionTokenGeneratedByAdminLifespan = TimeUnit2.asUnit(realm.actionTokenGeneratedByAdminLifespan); $scope.realm.actionTokenGeneratedByUserLifespan = TimeUnit2.asUnit(realm.actionTokenGeneratedByUserLifespan); $scope.realm.oauth2DeviceCodeLifespan = TimeUnit2.asUnit(realm.oauth2DeviceCodeLifespan); - $scope.requestUriLifespan = TimeUnit2.asUnit(realm.attributes.parRequestUriLifespan); - $scope.realm.attributes = realm.attributes + $scope.realm.attributes.parRequestUriLifespan = TimeUnit2.asUnit(realm.attributes.parRequestUriLifespan); + $scope.realm.attributes = realm.attributes; var oldCopy = angular.copy($scope.realm); $scope.changed = false; @@ -1337,10 +1337,6 @@ module.controller('RealmTokenDetailCtrl', function($scope, Realm, realm, $http, } }, true); - $scope.$watch('requestUriLifespan', function () { - $scope.changed = true; - }, true); - $scope.$watch('actionLifespanId', function () { // changedActionLifespanId signals other watchers that we were merely // changing the dropdown and we should not enable 'save' button @@ -1390,7 +1386,7 @@ module.controller('RealmTokenDetailCtrl', function($scope, Realm, realm, $http, $scope.realm.actionTokenGeneratedByAdminLifespan = $scope.realm.actionTokenGeneratedByAdminLifespan.toSeconds(); $scope.realm.actionTokenGeneratedByUserLifespan = $scope.realm.actionTokenGeneratedByUserLifespan.toSeconds(); $scope.realm.oauth2DeviceCodeLifespan = $scope.realm.oauth2DeviceCodeLifespan.toSeconds(); - $scope.realm.attributes.parRequestUriLifespan = $scope.requestUriLifespan.toSeconds().toString(); + $scope.realm.attributes.parRequestUriLifespan = $scope.realm.attributes.parRequestUriLifespan.toSeconds(); Realm.update($scope.realm, function () { $route.reload(); diff --git a/themes/src/main/resources/theme/base/admin/resources/partials/realm-tokens.html b/themes/src/main/resources/theme/base/admin/resources/partials/realm-tokens.html index 9c0b0fe4da..65232d2de5 100755 --- a/themes/src/main/resources/theme/base/admin/resources/partials/realm-tokens.html +++ b/themes/src/main/resources/theme/base/admin/resources/partials/realm-tokens.html @@ -324,9 +324,9 @@
- -