Search in sources :

Example 16 with RealmBuilder

use of org.keycloak.testsuite.util.RealmBuilder in project keycloak by keycloak.

the class PermissionsTest method addTestRealms.

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    RealmBuilder builder = RealmBuilder.create().name(REALM_NAME).testMail();
    builder.client(ClientBuilder.create().clientId("test-client").publicClient().directAccessGrants());
    builder.user(UserBuilder.create().username(AdminRoles.REALM_ADMIN).role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.REALM_ADMIN).addPassword("password"));
    builder.user(UserBuilder.create().username("multi").role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.QUERY_GROUPS).role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.VIEW_REALM).role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.VIEW_CLIENTS).addPassword("password"));
    builder.user(UserBuilder.create().username("none").addPassword("password"));
    for (String role : AdminRoles.ALL_REALM_ROLES) {
        builder.user(UserBuilder.create().username(role).role(Constants.REALM_MANAGEMENT_CLIENT_ID, role).addPassword("password"));
    }
    testRealms.add(builder.build());
    RealmBuilder builder2 = RealmBuilder.create().name("realm2");
    builder2.client(ClientBuilder.create().clientId("test-client").publicClient().directAccessGrants());
    builder2.user(UserBuilder.create().username("admin").role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.REALM_ADMIN).addPassword("password"));
    testRealms.add(builder2.build());
}
Also used : RealmBuilder(org.keycloak.testsuite.util.RealmBuilder)

Example 17 with RealmBuilder

use of org.keycloak.testsuite.util.RealmBuilder in project keycloak by keycloak.

the class CrossRealmPermissionsTest method addTestRealms.

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    RealmBuilder builder = RealmBuilder.create().name(REALM_NAME).testMail();
    builder.client(ClientBuilder.create().clientId("test-client").publicClient().directAccessGrants());
    builder.user(UserBuilder.create().username(AdminRoles.REALM_ADMIN).role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.REALM_ADMIN).addPassword("password"));
    testRealms.add(builder.build());
    adminClient1 = Keycloak.getInstance(getAuthServerContextRoot() + "/auth", REALM_NAME, AdminRoles.REALM_ADMIN, "password", "test-client", "secret", TLSUtils.initializeTLS());
    realm1 = adminClient1.realm(REALM_NAME);
    builder = RealmBuilder.create().name(REALM2_NAME).testMail();
    builder.client(ClientBuilder.create().clientId("test-client").publicClient().directAccessGrants());
    builder.user(UserBuilder.create().username(AdminRoles.REALM_ADMIN).role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.REALM_ADMIN).addPassword("password"));
    testRealms.add(builder.build());
    adminClient2 = Keycloak.getInstance(getAuthServerContextRoot() + "/auth", REALM2_NAME, AdminRoles.REALM_ADMIN, "password", "test-client", "secret", TLSUtils.initializeTLS());
    realm2 = adminClient2.realm(REALM2_NAME);
}
Also used : RealmBuilder(org.keycloak.testsuite.util.RealmBuilder)

Example 18 with RealmBuilder

use of org.keycloak.testsuite.util.RealmBuilder in project keycloak by keycloak.

the class ClientAuthSignedJWTTest method addTestRealms.

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    RealmBuilder realmBuilder = RealmBuilder.create().name("test").privateKey("MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=").publicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB").testEventListener();
    app1 = ClientBuilder.create().id(KeycloakModelUtils.generateId()).clientId("client1").attribute(JWTClientAuthenticator.CERTIFICATE_ATTR, "MIICnTCCAYUCBgFPPLDaTzANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdjbGllbnQxMB4XDTE1MDgxNzE3MjI0N1oXDTI1MDgxNzE3MjQyN1owEjEQMA4GA1UEAwwHY2xpZW50MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIUjjgv+V3s96O+Za9002Lp/trtGuHBeaeVL9dFKMKzO2MPqdRmHB4PqNlDdd28Rwf5Xn6iWdFpyUKOnI/yXDLhdcuFpR0sMNK/C9Lt+hSpPFLuzDqgtPgDotlMxiHIWDOZ7g9/gPYNXbNvjv8nSiyqoguoCQiiafW90bPHsiVLdP7ZIUwCcfi1qQm7FhxRJ1NiW5dvUkuCnnWEf0XR+Wzc5eC9EgB0taLFiPsSEIlWMm5xlahYyXkPdNOqZjiRnrTWm5Y4uk8ZcsD/KbPTf/7t7cQXipVaswgjdYi1kK2/zRwOhg1QwWFX/qmvdd+fLxV0R6VqRDhn7Qep2cxwMxLsCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAKE6OA46sf20bz8LZPoiNsqRwBUDkaMGXfnob7s/hJZIIwDEx0IAQ3uKsG7q9wb+aA6s+v7S340zb2k3IxuhFaHaZpAd4CyR5cn1FHylbzoZ7rI/3ASqHDqpljdJaFqPH+m7nZWtyDvtZf+gkZ8OjsndwsSBK1d/jMZPp29qYbl1+XfO7RCp/jDqro/R3saYFaIFiEZPeKn1hUJn6BO48vxH1xspSu9FmlvDOEAOz4AuM58z4zRMP49GcFdCWr1wkonJUHaSptJaQwmBwLFUkCbE5I1ixGMb7mjEud6Y5jhfzJiZMo2U8RfcjNbrN0diZl3jB6LQIwESnhYSghaTjNQ==").attribute(OIDCConfigAttributes.USE_REFRESH_TOKEN_FOR_CLIENT_CREDENTIALS_GRANT, "true").authenticatorType(JWTClientAuthenticator.PROVIDER_ID).serviceAccountsEnabled(true).build();
    realmBuilder.client(app1);
    app2 = ClientBuilder.create().id(KeycloakModelUtils.generateId()).clientId("client2").directAccessGrants().serviceAccountsEnabled(true).redirectUris(OAuthClient.APP_ROOT + "/auth").attribute(JWTClientAuthenticator.CERTIFICATE_ATTR, "MIICnTCCAYUCBgFPPQDGxTANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdjbGllbnQxMB4XDTE1MDgxNzE4NTAwNVoXDTI1MDgxNzE4NTE0NVowEjEQMA4GA1UEAwwHY2xpZW50MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMMw3PaBffWxgS2PYSDDBp6As+cNvv9kt2C4f/RDAGmvSIHPFev9kuQiKs3Oaws3ZsV4JG3qHEuYgnh9W4vfe3DwNwtD1bjL5FYBhPBFTw0lAQECYxaBHnkjHwUKp957FqdSPPICm3LjmTcEdlH+9dpp9xHCMbbiNiWDzWI1xSxC8Fs2d0hwz1sd+Q4QeTBPIBWcPM+ICZtNG5MN+ORfayu4X+Me5d0tXG2fQO//rAevk1i5IFjKZuOjTwyKB5SJIY4b8QTeg0g/50IU7Ht00Pxw6CK02dHS+FvXHasZlD3ckomqCDjStTBWdhJo5dST0CbOqalkkpLlCCbGA1yEQRsCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAUIMeJ+EAo8eNpCG/nXImacjrKakbFnZYBGD/gqeTGaZynkX+jgBSructTHR83zSH+yELEhsAy+3BfK4EEihp+PEcRnK2fASVkHste8AQ7rlzC+HGGirlwrVhWCdizNUCGK80DE537IZ7nmZw6LFG9P5/Q2MvCsOCYjRUvMkukq6TdXBXR9tETwZ+0gpSfsOxjj0ZF7ftTRUSzx4rFfcbM9fRNdVizdOuKGc8HJPA5lLOxV6CyaYIvi3y5RlQI1OHeS34lE4w9CNPRFa/vdxXvN7ClyzA0HMFNWxBN7pC/Ht/FbhSvaAagJBHg+vCrcY5C26Oli7lAglf/zZrwUPs0w==").authenticatorType(JWTClientAuthenticator.PROVIDER_ID).build();
    realmBuilder.client(app2);
    // This one is for keystore-client2.p12 , which doesn't work on Sun JDK
    // app2.setAttribute(JWTClientAuthenticator.CERTIFICATE_ATTR, "MIICnTCCAYUCBgFPPLGHHjANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdjbGllbnQxMB4XDTE1MDgxNzE3MjMzMVoXDTI1MDgxNzE3MjUxMVowEjEQMA4GA1UEAwwHY2xpZW50MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIsatXj38fFD9fHslNrsWrubobudXYwwdZpGYqkHIhuDeSojGvhBSLmKIFmtbHMVcLEbS0dIEsSbNVrwjdFfuRuvd9Vu6Ng0JUC8fRhSeQniC3jcBuP8P4WlXK4+ir3Wlya+T6Hum9b68BiH0KyNZtFGJ6zLHuCcq9Bl0JifvibnUkDeTZPwgJNA9+GxS/x8fAkApcAbJrgBZvr57PwhbgHoZdB8aAY5f5ogbGzKDtSUMvFh+Jah39gWtn7p3VOuuMXA8SugogoH8C5m2itrPBL1UPhAcKUeWiqx4SmZe/lZo7x2WbSecNiFaiqBhIW+QbqCYW6I4u0YvuLuEe3+TC8CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAZzW5DZviCxUQdV5Ab07PZkUfvImHZ73oWWHZqzUQtZtbVdzfp3cnbb2wyXtlOvingO3hgpoTxV8vbKgLbIQfvkGGHBG1F5e0QVdtikfdcwWb7cy4/9F80OD7cgG0ZAzFbQ8ZY7iS3PToBp3+4tbIK2NK0ntt/MYgJnPbHeG4V4qfgUbFm1YgEK7WpbSVU8jGuJ5DWE+mlYgECZKZ5TSlaVGs2XOm6WXrJScucNekwcBWWiHyRsFHZEDzWmzt8TLTLnnb0vVjhx3qCYxah3RbyyMZm6WLZlLAaGEcwNDO8jaA3hAjrxoOA1xEaolQfGVsb/ElelHcR1Zfe0u4Ekd4tw==");
    defaultUser = UserBuilder.create().id(KeycloakModelUtils.generateId()).username("test-user@localhost").password("password").build();
    realmBuilder.user(defaultUser);
    client1SAUserId = KeycloakModelUtils.generateId();
    serviceAccountUser = UserBuilder.create().id(client1SAUserId).username(ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + app1.getClientId()).serviceAccountId(app1.getClientId()).build();
    realmBuilder.user(serviceAccountUser);
    testRealm = realmBuilder.build();
    testRealms.add(testRealm);
}
Also used : RealmBuilder(org.keycloak.testsuite.util.RealmBuilder)

Example 19 with RealmBuilder

use of org.keycloak.testsuite.util.RealmBuilder in project keycloak by keycloak.

the class OAuth2DeviceAuthorizationGrantTest method addTestRealms.

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    RealmBuilder realm = RealmBuilder.create().name(REALM_NAME).privateKey("MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=").publicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB").testEventListener();
    ClientRepresentation app = ClientBuilder.create().id(KeycloakModelUtils.generateId()).clientId("test-device").secret("secret").attribute(OAuth2DeviceConfig.OAUTH2_DEVICE_AUTHORIZATION_GRANT_ENABLED, "true").build();
    realm.client(app);
    ClientRepresentation appPublic = ClientBuilder.create().id(KeycloakModelUtils.generateId()).publicClient().clientId(DEVICE_APP_PUBLIC).attribute(OAuth2DeviceConfig.OAUTH2_DEVICE_AUTHORIZATION_GRANT_ENABLED, "true").build();
    realm.client(appPublic);
    ClientRepresentation appPublicCustomConsent = ClientBuilder.create().id(KeycloakModelUtils.generateId()).publicClient().clientId(DEVICE_APP_PUBLIC_CUSTOM_CONSENT).attribute(OAuth2DeviceConfig.OAUTH2_DEVICE_AUTHORIZATION_GRANT_ENABLED, "true").consentRequired(true).attribute(ClientScopeModel.DISPLAY_ON_CONSENT_SCREEN, "true").attribute(ClientScopeModel.CONSENT_SCREEN_TEXT, "This is the custom consent screen text.").build();
    realm.client(appPublicCustomConsent);
    userId = KeycloakModelUtils.generateId();
    UserRepresentation user = UserBuilder.create().id(userId).username("device-login").email("device-login@localhost").password("password").addAttribute("phoneNumber", "211211211").build();
    realm.user(user);
    testRealms.add(realm.build());
}
Also used : RealmBuilder(org.keycloak.testsuite.util.RealmBuilder) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation)

Example 20 with RealmBuilder

use of org.keycloak.testsuite.util.RealmBuilder in project keycloak by keycloak.

the class OAuthRedirectUriTest method addTestRealms.

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    RealmRepresentation realmRepresentation = loadJson(getClass().getResourceAsStream("/testrealm.json"), RealmRepresentation.class);
    RealmBuilder realm = RealmBuilder.edit(realmRepresentation).testEventListener();
    ClientBuilder installedApp = ClientBuilder.create().clientId("test-installed").name("test-installed").redirectUris(Constants.INSTALLED_APP_URN, Constants.INSTALLED_APP_URL).secret("password");
    realm.client(installedApp);
    ClientBuilder installedApp2 = ClientBuilder.create().clientId("test-installed2").name("test-installed2").redirectUris(Constants.INSTALLED_APP_URL + "/myapp").secret("password");
    realm.client(installedApp2);
    ClientBuilder installedApp3 = ClientBuilder.create().clientId("test-wildcard").name("test-wildcard").redirectUris("http://example.com/foo/*", "http://with-dash.example.local/foo/*", "http://localhost:8280/foo/*").secret("password");
    realm.client(installedApp3);
    ClientBuilder installedApp4 = ClientBuilder.create().clientId("test-dash").name("test-dash").redirectUris("http://with-dash.example.local", "http://with-dash.example.local/foo").secret("password");
    realm.client(installedApp4);
    ClientBuilder installedApp5 = ClientBuilder.create().clientId("test-root-url").name("test-root-url").rootUrl("http://with-dash.example.local").redirectUris("/foo").secret("password");
    realm.client(installedApp5);
    ClientBuilder installedApp6 = ClientBuilder.create().clientId("test-relative-url").name("test-relative-url").rootUrl("").redirectUris("/auth").secret("password");
    realm.client(installedApp6);
    ClientBuilder installedApp7 = ClientBuilder.create().clientId("test-query-component").name("test-query-component").redirectUris("http://localhost?foo=bar", "http://localhost?foo=bar*").secret("password");
    realm.client(installedApp7);
    ClientBuilder installedApp8 = ClientBuilder.create().clientId("test-fragment").name("test-fragment").redirectUris("http://localhost:8180/*", "https://localhost:8543/*").secret("password");
    realm.client(installedApp8);
    ClientBuilder installedAppCustomScheme = ClientBuilder.create().clientId("custom-scheme").name("custom-scheme").redirectUris("android-app://org.keycloak.examples.cordova/https/keycloak-cordova-example.github.io/login").secret("password");
    realm.client(installedAppCustomScheme);
    ClientBuilder installedAppLoopback = ClientBuilder.create().clientId("test-installed-loopback").name("test-installed-loopback").redirectUris(Constants.INSTALLED_APP_LOOPBACK).secret("password");
    realm.client(installedAppLoopback);
    ClientBuilder installedAppLoopback2 = ClientBuilder.create().clientId("test-installed-loopback2").name("test-installed-loopback2").redirectUris(Constants.INSTALLED_APP_LOOPBACK + "/myapp").secret("password");
    realm.client(installedAppLoopback2);
    testRealms.add(realm.build());
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) RealmBuilder(org.keycloak.testsuite.util.RealmBuilder) ClientBuilder(org.keycloak.testsuite.util.ClientBuilder)

Aggregations

RealmBuilder (org.keycloak.testsuite.util.RealmBuilder)20 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)9 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)6 UserBuilder (org.keycloak.testsuite.util.UserBuilder)4 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)3 ClientBuilder (org.keycloak.testsuite.util.ClientBuilder)2 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)1 RolesBuilder (org.keycloak.testsuite.util.RolesBuilder)1