Added support for default application roles. Added authz to account, user (or client if oauth) is required to have role manage-account to manage their account, this is a default role for the Account application.
This commit is contained in:
1 parent
97792b7e1d
commit
d083909136
20 files changed
+244
-90
No files matched your search
+39
-10
@@ -29,6 +29,8 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -51,17 +53,13 @@ public class ProfileTest {
|
||||
|
||||
ApplicationModel accountApp = appRealm.getApplicationNameMap().get(org.keycloak.models.Constants.ACCOUNT_APPLICATION);
|
||||
|
||||
accountApp.grantRole(user, accountApp.getRole(org.keycloak.models.Constants.ACCOUNT_PROFILE_ROLE));
|
||||
accountApp.grantRole(user, accountApp.getRole(org.keycloak.models.Constants.ACCOUNT_MANAGE_ROLE));
|
||||
ApplicationModel app = appRealm.getApplicationNameMap().get("test-app");
|
||||
accountApp.addScopeMapping(app.getApplicationUser(), org.keycloak.models.Constants.ACCOUNT_PROFILE_ROLE);
|
||||
|
||||
app.getApplicationUser().addWebOrigin("http://localtest.me:8081");
|
||||
|
||||
UserModel thirdParty = appRealm.getUser("third-party");
|
||||
accountApp.addScopeMapping(thirdParty, org.keycloak.models.Constants.ACCOUNT_PROFILE_ROLE);
|
||||
|
||||
for (ApplicationModel app : appRealm.getApplications()) {
|
||||
if (app.getName().equals("test-app")) {
|
||||
app.getApplicationUser().addWebOrigin("http://localtest.me:8081");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -83,6 +81,8 @@ public class ProfileTest {
|
||||
@WebResource
|
||||
protected OAuthGrantPage grantPage;
|
||||
|
||||
private List<String> defaultRoles;
|
||||
|
||||
@Test
|
||||
public void getProfile() throws Exception {
|
||||
oauth.doLogin("test-user@localhost", "password");
|
||||
@@ -119,7 +119,7 @@ public class ProfileTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProfileCorsInvalidOrigin() throws Exception {
|
||||
public void getProfileCorsInvalidOrigin() throws Exception {
|
||||
oauth.doLogin("test-user@localhost", "password");
|
||||
|
||||
String code = oauth.getCurrentQuery().get("code");
|
||||
@@ -152,6 +152,35 @@ public class ProfileTest {
|
||||
assertEquals(403, response.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProfileNoAccess() throws Exception {
|
||||
try {
|
||||
keycloakRule.configure(new KeycloakRule.KeycloakSetup() {
|
||||
@Override
|
||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||
ApplicationModel app = appRealm.getApplicationNameMap().get(org.keycloak.models.Constants.ACCOUNT_APPLICATION);
|
||||
defaultRoles = app.getDefaultRoles();
|
||||
app.updateDefaultRoles(new String[0]);
|
||||
}
|
||||
});
|
||||
|
||||
oauth.doLogin("test-user@localhost", "password");
|
||||
|
||||
String code = oauth.getCurrentQuery().get("code");
|
||||
String token = oauth.doAccessTokenRequest(code, "password").getAccessToken();
|
||||
|
||||
HttpResponse response = doGetProfile(token, null);
|
||||
assertEquals(403, response.getStatusLine().getStatusCode());
|
||||
} finally {
|
||||
keycloakRule.configure(new KeycloakRule.KeycloakSetup() {
|
||||
@Override
|
||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||
appRealm.getApplicationNameMap().get(org.keycloak.models.Constants.ACCOUNT_APPLICATION).updateDefaultRoles((String[]) defaultRoles.toArray());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProfileOAuthClient() throws Exception {
|
||||
oauth.addScope(org.keycloak.models.Constants.ACCOUNT_APPLICATION, org.keycloak.models.Constants.ACCOUNT_PROFILE_ROLE);
|
||||
@@ -209,7 +238,7 @@ public class ProfileTest {
|
||||
sb.append("req.send(null);\n");
|
||||
sb.append("return req.status + '///' + req.responseText;\n");
|
||||
|
||||
JavascriptExecutor js = (JavascriptExecutor) driver;
|
||||
JavascriptExecutor js = (JavascriptExecutor) driver;
|
||||
String response = (String) js.executeScript(sb.toString());
|
||||
return response.split("///");
|
||||
}
|
||||
|
||||
@@ -21,19 +21,14 @@
|
||||
*/
|
||||
package org.keycloak.testsuite.forms;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.junit.*;
|
||||
import org.keycloak.models.*;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.services.managers.RealmManager;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserCredentialModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.testsuite.OAuthClient;
|
||||
import org.keycloak.testsuite.pages.AccountPasswordPage;
|
||||
import org.keycloak.testsuite.pages.AccountTotpPage;
|
||||
import org.keycloak.testsuite.pages.AccountUpdateProfilePage;
|
||||
import org.keycloak.testsuite.pages.AppPage;
|
||||
import org.keycloak.testsuite.pages.*;
|
||||
import org.keycloak.testsuite.pages.AppPage.RequestType;
|
||||
import org.keycloak.testsuite.pages.LoginPage;
|
||||
import org.keycloak.testsuite.rule.KeycloakRule;
|
||||
import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup;
|
||||
import org.keycloak.testsuite.rule.WebResource;
|
||||
@@ -43,6 +38,10 @@ import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
import org.picketlink.idm.credential.util.TimeBasedOTP;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
@@ -75,8 +74,13 @@ public class AccountTest {
|
||||
@WebResource
|
||||
protected AccountTotpPage totpPage;
|
||||
|
||||
@WebResource
|
||||
protected ErrorPage errorPage;
|
||||
|
||||
private TimeBasedOTP totp = new TimeBasedOTP();
|
||||
|
||||
private List<String> defaultRoles;
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
keycloakRule.configure(new KeycloakSetup() {
|
||||
@@ -183,4 +187,31 @@ public class AccountTest {
|
||||
Assert.assertTrue(driver.getPageSource().contains("Remove Google"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeProfileNoAccess() throws Exception {
|
||||
try {
|
||||
keycloakRule.configure(new KeycloakRule.KeycloakSetup() {
|
||||
@Override
|
||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||
ApplicationModel app = appRealm.getApplicationNameMap().get(Constants.ACCOUNT_APPLICATION);
|
||||
defaultRoles = app.getDefaultRoles();
|
||||
app.updateDefaultRoles(new String[0]);
|
||||
}
|
||||
});
|
||||
|
||||
profilePage.open();
|
||||
loginPage.login("test-user@localhost", "password");
|
||||
|
||||
Assert.assertTrue(errorPage.isCurrent());
|
||||
Assert.assertEquals("No access", errorPage.getError());
|
||||
} finally {
|
||||
keycloakRule.configure(new KeycloakRule.KeycloakSetup() {
|
||||
@Override
|
||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||
appRealm.getApplicationNameMap().get(org.keycloak.models.Constants.ACCOUNT_APPLICATION).updateDefaultRoles((String[]) defaultRoles.toArray());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user