requiredActions = userRepresentation.getRequiredActions();
+ if (enabled && !requiredActions.contains(requiredAction)) {
+ requiredActions.add(requiredAction);
+ } else if (!enabled && requiredActions.contains(requiredAction)) {
+ requiredActions.remove(requiredAction);
+ }
+
+ userResource.update(userRepresentation);
+ }
+
}
diff --git a/testsuite/integration-arquillian/tests/other/console/pom.xml b/testsuite/integration-arquillian/tests/other/console/pom.xml
index b6818145ae..077655339f 100644
--- a/testsuite/integration-arquillian/tests/other/console/pom.xml
+++ b/testsuite/integration-arquillian/tests/other/console/pom.xml
@@ -30,5 +30,33 @@
integration-arquillian-tests-console
Admin Console UI Tests
-
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+
+
+ copy-theme-files
+ process-resources
+
+ copy-resources
+
+
+ ${keycloak.home}/themes
+
+
+ src/main/resources/themes
+
+
+
+
+
+
+
+
+
+
diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/resources/themes/qe/login/messages/messages_en.properties b/testsuite/integration-arquillian/tests/other/console/src/main/resources/themes/qe/login/messages/messages_en.properties
new file mode 100644
index 0000000000..b9060b4203
--- /dev/null
+++ b/testsuite/integration-arquillian/tests/other/console/src/main/resources/themes/qe/login/messages/messages_en.properties
@@ -0,0 +1,4 @@
+doAccept=Yes
+doDecline=No
+
+termsText=See QA for more information.
\ No newline at end of file
diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/resources/themes/qe/login/theme.properties b/testsuite/integration-arquillian/tests/other/console/src/main/resources/themes/qe/login/theme.properties
new file mode 100644
index 0000000000..f1dbb7215d
--- /dev/null
+++ b/testsuite/integration-arquillian/tests/other/console/src/main/resources/themes/qe/login/theme.properties
@@ -0,0 +1 @@
+parent=base
\ No newline at end of file
diff --git a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/authentication/actions/TermsAndConditionsTest.java b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/authentication/actions/TermsAndConditionsTest.java
new file mode 100644
index 0000000000..f518784f99
--- /dev/null
+++ b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/authentication/actions/TermsAndConditionsTest.java
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Copyright 2013 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.keycloak.testsuite.console.authentication.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.arquillian.graphene.page.Page;
+import org.junit.Assert;
+import org.junit.Test;
+import org.keycloak.admin.client.resource.RealmResource;
+import org.keycloak.representations.idm.CredentialRepresentation;
+import org.keycloak.representations.idm.RealmRepresentation;
+
+import org.keycloak.representations.idm.UserRepresentation;
+import org.keycloak.testsuite.auth.page.login.Registration;
+import org.keycloak.testsuite.auth.page.login.TermsAndConditions;
+import org.keycloak.testsuite.console.AbstractConsoleTest;
+import org.keycloak.testsuite.console.page.authentication.RequiredActions;
+
+/**
+ *
+ */
+public class TermsAndConditionsTest extends AbstractConsoleTest {
+
+ private static final String TERMS_TEXT = "Terms and conditions to be defined";
+
+ private static final String REALM = "TermsAndConditions";
+
+ private static final String BART = "Bart";
+
+ private static final String BART_PASS = "Ay caramba!";
+
+ private static final String HOMER = "Homer";
+
+ private static final String HOMER_PASS = "Mmm donuts.";
+
+ @Page
+ private TermsAndConditions termsAndConditionsPage;
+
+ @Page
+ private Registration registrationPage;
+
+ @Override
+ public void beforeConsoleTest() {
+ // no operation - we don't need 'admin' user for this test.
+ }
+
+ @Override
+ public void setDefaultPageUriParameters() {
+ super.setDefaultPageUriParameters();
+ testRealmPage.setAuthRealm(REALM);
+ testRealmAdminConsolePage.setAdminRealm(REALM);
+ }
+
+ @Override
+ public void addTestRealms(List testRealms) {
+ RealmRepresentation testRealmRep = new RealmRepresentation();
+ testRealmRep.setRealm(REALM);
+ testRealmRep.setEnabled(true);
+ testRealms.add(testRealmRep);
+ }
+
+ @Test
+ public void testExistingUser() {
+ // create user
+ String userId = createUser(REALM, HOMER, HOMER_PASS);
+
+ // test t&c - log in and make sure t&c is not displayed
+ testRealmAdminConsolePage.navigateTo();
+ testRealmLoginPage.form().login(HOMER, HOMER_PASS);
+ testRealmAdminConsolePage.logOut();
+
+ // enable terms
+ setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, true, false);
+ setRequiredActionEnabled(REALM, userId, RequiredActions.TERMS_AND_CONDITIONS, true);
+
+ // test t&c - log in and accept
+ testRealmLoginPage.form().login(HOMER, HOMER_PASS);
+ Assert.assertEquals(TERMS_TEXT, termsAndConditionsPage.getText());
+ termsAndConditionsPage.declineTerms();
+
+ testRealmLoginPage.form().login(HOMER, HOMER_PASS);
+ Assert.assertEquals(TERMS_TEXT, termsAndConditionsPage.getText());
+
+ termsAndConditionsPage.acceptTerms();
+ testRealmAdminConsolePage.logOut();
+
+ testRealmLoginPage.form().login(HOMER, HOMER_PASS);
+ testRealmAdminConsolePage.logOut();
+
+ // disable terms
+ setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, false, false);
+ }
+
+ @Test
+ public void testAdminCreatedUser() {
+ // enable terms
+ setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, true, false);
+
+ // create user
+ String userId = createUser(REALM, BART, BART_PASS);
+ setRequiredActionEnabled(REALM, userId, RequiredActions.TERMS_AND_CONDITIONS, true);
+
+ // test t&c
+ testRealmAdminConsolePage.navigateTo();
+ testRealmLoginPage.form().login(BART, BART_PASS);
+ Assert.assertTrue(termsAndConditionsPage.isCurrent());
+
+ // disable terms
+ setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, false, false);
+ }
+
+ @Test
+ public void testSelfRegisteredUser() {
+ // enable self-registration
+ RealmResource realmResource = adminClient.realm(REALM);
+ RealmRepresentation realmRepresentation = realmResource.toRepresentation();
+ realmRepresentation.setRegistrationAllowed(true);
+ realmResource.update(realmRepresentation);
+
+ // enable terms
+ setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, true, true);
+
+ // self-register
+ CredentialRepresentation mrBurnsPassword = new CredentialRepresentation();
+ mrBurnsPassword.setType(CredentialRepresentation.PASSWORD);
+ mrBurnsPassword.setValue("Excellent.");
+
+ List credentials = new ArrayList();
+ credentials.add(mrBurnsPassword);
+
+ UserRepresentation mrBurns = new UserRepresentation();
+ mrBurns.setUsername("mrburns");
+ mrBurns.setFirstName("Montgomery");
+ mrBurns.setLastName("Burns");
+ mrBurns.setEmail("mburns@keycloak.org");
+ mrBurns.setCredentials(credentials);
+
+ testRealmAdminConsolePage.navigateTo();
+ testRealmLoginPage.form().register();
+
+ registrationPage.register(mrBurns);
+
+ // test t&c
+ Assert.assertTrue(termsAndConditionsPage.isCurrent());
+
+ // disable terms
+ setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, false, false);
+ }
+
+}
\ No newline at end of file
diff --git a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/themes/TermsAndConditionsThemeTest.java b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/themes/TermsAndConditionsThemeTest.java
new file mode 100644
index 0000000000..69e0c8a4b7
--- /dev/null
+++ b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/themes/TermsAndConditionsThemeTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2016 Red Hat, Inc. and/or its affiliates
+ * and other contributors as indicated by the @author tags.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.keycloak.testsuite.console.themes;
+
+import java.util.List;
+import org.jboss.arquillian.graphene.page.Page;
+import org.junit.Assert;
+import org.junit.Test;
+import org.keycloak.admin.client.resource.RealmResource;
+import org.keycloak.representations.idm.RealmRepresentation;
+import org.keycloak.testsuite.auth.page.login.TermsAndConditions;
+import org.keycloak.testsuite.console.AbstractConsoleTest;
+import org.keycloak.testsuite.console.page.authentication.RequiredActions;
+
+/**
+ *
+ */
+public class TermsAndConditionsThemeTest extends AbstractConsoleTest {
+
+ private static final String REALM = "CustomLook";
+
+ private static final String HOMER = "Homer";
+
+ private static final String HOMER_PASS = "Mmm donuts.";
+
+ @Page
+ private TermsAndConditions termsAndConditionsPage;
+
+ @Override
+ public void setDefaultPageUriParameters() {
+ super.setDefaultPageUriParameters();
+ testRealmPage.setAuthRealm(REALM);
+ testRealmAdminConsolePage.setAdminRealm(REALM);
+ }
+
+ @Override
+ public void addTestRealms(List testRealms) {
+ RealmRepresentation testRealmRep = new RealmRepresentation();
+ testRealmRep.setRealm(REALM);
+ testRealmRep.setEnabled(true);
+ testRealms.add(testRealmRep);
+ }
+
+ @Override
+ public void beforeConsoleTest() {
+ // no operation - we don't need 'admin' user for this test.
+ }
+
+ @Test
+ public void testTermsAndConditions() {
+ String userId = createUser(REALM, HOMER, HOMER_PASS);
+ setRequiredActionEnabled(REALM, RequiredActions.TERMS_AND_CONDITIONS, true, false);
+ setRequiredActionEnabled(REALM, userId, RequiredActions.TERMS_AND_CONDITIONS, true);
+
+ RealmResource realmResource = adminClient.realm(REALM);
+ RealmRepresentation realmRepresentation = realmResource.toRepresentation();
+ realmRepresentation.setLoginTheme("qe");
+ realmResource.update(realmRepresentation);
+
+ testRealmAdminConsolePage.navigateTo();
+ testRealmLoginPage.form().login(HOMER, HOMER_PASS);
+
+ Assert.assertTrue(termsAndConditionsPage.isCurrent());
+ Assert.assertTrue(termsAndConditionsPage.getText().contains("See QA for more information."));
+ Assert.assertEquals("Yes", termsAndConditionsPage.getAcceptButtonText());
+ Assert.assertEquals("No", termsAndConditionsPage.getDeclineButtonText());
+ }
+
+}