Search in sources :

Example 1 with UserBuilder

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

the class AdminClientTest method addTestRealms.

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    RealmBuilder realm = 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();
    ClientRepresentation enabledAppWithSkipRefreshToken = ClientBuilder.create().id(KeycloakModelUtils.generateId()).clientId("service-account-cl").secret("secret1").serviceAccountsEnabled(true).build();
    realm.client(enabledAppWithSkipRefreshToken);
    userId = KeycloakModelUtils.generateId();
    userName = ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + enabledAppWithSkipRefreshToken.getClientId();
    UserBuilder serviceAccountUser = UserBuilder.create().id(userId).username(userName).serviceAccountId(enabledAppWithSkipRefreshToken.getClientId()).role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.REALM_ADMIN);
    realm.user(serviceAccountUser);
    UserBuilder defaultUser = UserBuilder.create().id(KeycloakModelUtils.generateId()).username("test-user@localhost").password("password").role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.REALM_ADMIN);
    realm.user(defaultUser);
    testRealms.add(realm.build());
}
Also used : RealmBuilder(org.keycloak.testsuite.util.RealmBuilder) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) UserBuilder(org.keycloak.testsuite.util.UserBuilder)

Example 2 with UserBuilder

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

the class CompositeRoleTest method addTestRealms.

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    RealmBuilder realmBuilder = RealmBuilder.create().name("test").publicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB").privateKey("MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=").ssoSessionIdleTimeout(3000).accessTokenLifespan(10000).ssoSessionMaxLifespan(10000).accessCodeLifespanUserAction(1000).accessCodeLifespan(1000).sslRequired(SslRequired.EXTERNAL.toString());
    RoleRepresentation realmRole1 = RoleBuilder.create().name("REALM_ROLE_1").build();
    RoleRepresentation realmComposite1 = RoleBuilder.create().name("REALM_COMPOSITE_1").composite().realmComposite(realmRole1).build();
    RolesBuilder roles = RolesBuilder.create().realmRole(realmRole1).realmRole(RoleBuilder.create().name("REALM_ROLE_2").build()).realmRole(RoleBuilder.create().name("REALM_ROLE_3").build()).realmRole(realmComposite1);
    realmBuilder.roles(roles);
    UserBuilder realmCompositeUser = UserBuilder.create().username("REALM_COMPOSITE_1_USER").enabled(true).password("password").addRoles(realmComposite1.getName());
    realmBuilder.user(realmCompositeUser);
    UserBuilder realmRole1User = UserBuilder.create().username("REALM_ROLE_1_USER").enabled(true).password("password").addRoles(realmRole1.getName());
    realmBuilder.user(realmRole1User);
    ClientBuilder realmComposite1Application = ClientBuilder.create().clientId("REALM_COMPOSITE_1_APPLICATION").name("REALM_COMPOSITE_1_APPLICATION").fullScopeEnabled(Boolean.FALSE).redirectUris("http://localhost:8180/auth/realms/master/app/*", "https://localhost:8543/auth/realms/master/app/*").baseUrl("http://localhost:8180/auth/realms/master/app/auth").adminUrl("http://localhost:8180/auth/realms/master/app/logout").secret("password");
    realmBuilder.client(realmComposite1Application);
    ClientBuilder realmRole1Application = ClientBuilder.create().clientId("REALM_ROLE_1_APPLICATION").name("REALM_ROLE_1_APPLICATION").fullScopeEnabled(Boolean.FALSE).redirectUris("http://localhost:8180/auth/realms/master/app/*", "https://localhost:8543/auth/realms/master/app/*").baseUrl("http://localhost:8180/auth/realms/master/app/auth").adminUrl("http://localhost:8180/auth/realms/master/app/logout").secret("password");
    realmBuilder.client(realmRole1Application);
    ClientBuilder appRoleApplication = ClientBuilder.create().clientId("APP_ROLE_APPLICATION").name("APP_ROLE_APPLICATION").fullScopeEnabled(Boolean.FALSE).redirectUris("http://localhost:8180/auth/realms/master/app/*", "https://localhost:8543/auth/realms/master/app/*").baseUrl("http://localhost:8180/auth/realms/master/app/auth").adminUrl("http://localhost:8180/auth/realms/master/app/logout").defaultRoles("APP_ROLE_1", "APP_ROLE_2").secret("password");
    realmBuilder.client(appRoleApplication);
    UserBuilder realmAppCompositeUser = UserBuilder.create().username("REALM_APP_COMPOSITE_USER").password("password");
    realmBuilder.user(realmAppCompositeUser);
    UserBuilder realmAppRoleUser = UserBuilder.create().username("REALM_APP_ROLE_USER").password("password").addRoles("APP_ROLE_2");
    realmBuilder.user(realmAppRoleUser);
    ClientBuilder appCompositeApplication = ClientBuilder.create().clientId("APP_COMPOSITE_APPLICATION").name("APP_COMPOSITE_APPLICATION").fullScopeEnabled(Boolean.FALSE).defaultRoles("APP_COMPOSITE_ROLE").redirectUris("http://localhost:8180/auth/realms/master/app/*", "https://localhost:8543/auth/realms/master/app/*").baseUrl("http://localhost:8180/auth/realms/master/app/auth").adminUrl("http://localhost:8180/auth/realms/master/app/logout").secret("password");
    realmBuilder.client(appCompositeApplication);
    UserBuilder appCompositeUser = UserBuilder.create().username("APP_COMPOSITE_USER").password("password").addRoles("REALM_COMPOSITE_1");
    realmBuilder.user(appCompositeUser);
    testRealms.add(realmBuilder.build());
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) RolesBuilder(org.keycloak.testsuite.util.RolesBuilder) RealmBuilder(org.keycloak.testsuite.util.RealmBuilder) UserBuilder(org.keycloak.testsuite.util.UserBuilder) ClientBuilder(org.keycloak.testsuite.util.ClientBuilder)

Example 3 with UserBuilder

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

the class AbstractI18NTest method configureTestRealm.

@Override
public void configureTestRealm(RealmRepresentation testRealm) {
    UserBuilder user = UserBuilder.create().username("login-test").enabled(true).email("login@test.com").role("account", "manage-account").password("password");
    RealmBuilder.edit(testRealm).user(user);
}
Also used : UserBuilder(org.keycloak.testsuite.util.UserBuilder)

Example 4 with UserBuilder

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

the class AccessTokenResponseTest method addTestRealms.

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    RealmRepresentation realm = loadJson(getClass().getResourceAsStream("/testrealm.json"), RealmRepresentation.class);
    UserBuilder user = UserBuilder.create().id(KeycloakModelUtils.generateId()).username("no-permissions").addRoles("user").password("password");
    realm.getUsers().add(user.build());
    ProtocolMapperRepresentation customClaimHardcodedMapper = new ProtocolMapperRepresentation();
    customClaimHardcodedMapper.setName("custom-claim-hardcoded-mapper");
    customClaimHardcodedMapper.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
    customClaimHardcodedMapper.setProtocolMapper(HardcodedClaim.PROVIDER_ID);
    Map<String, String> config = new HashMap<>();
    config.put(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME, "custom_hardcoded_claim");
    config.put(HardcodedClaim.CLAIM_VALUE, "custom_claim");
    config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN_RESPONSE, "true");
    customClaimHardcodedMapper.setConfig(config);
    realm.getClients().stream().filter(clientRepresentation -> "test-app".equals(clientRepresentation.getClientId())).forEach(clientRepresentation -> {
        clientRepresentation.setProtocolMappers(Collections.singletonList(customClaimHardcodedMapper));
        clientRepresentation.setFullScopeAllowed(false);
    });
    testRealms.add(realm);
}
Also used : HardcodedClaim(org.keycloak.protocol.oidc.mappers.HardcodedClaim) OIDCAttributeMapperHelper(org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper) AbstractAdminTest.loadJson(org.keycloak.testsuite.admin.AbstractAdminTest.loadJson) KeycloakModelUtils(org.keycloak.models.utils.KeycloakModelUtils) AssertEvents(org.keycloak.testsuite.AssertEvents) HashMap(java.util.HashMap) Test(org.junit.Test) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) OAuthClient(org.keycloak.testsuite.util.OAuthClient) List(java.util.List) Rule(org.junit.Rule) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest) UserBuilder(org.keycloak.testsuite.util.UserBuilder) Map(java.util.Map) OIDCLoginProtocol(org.keycloak.protocol.oidc.OIDCLoginProtocol) Collections(java.util.Collections) ClientManager(org.keycloak.testsuite.util.ClientManager) Assert.assertEquals(org.junit.Assert.assertEquals) OAuth2Constants(org.keycloak.OAuth2Constants) Before(org.junit.Before) HashMap(java.util.HashMap) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) UserBuilder(org.keycloak.testsuite.util.UserBuilder)

Example 5 with UserBuilder

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

the class ResourceOwnerPasswordCredentialsGrantTest method addTestRealms.

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    RealmBuilder realm = 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();
    ClientRepresentation app = ClientBuilder.create().id(KeycloakModelUtils.generateId()).clientId("resource-owner").directAccessGrants().secret("secret").build();
    realm.client(app);
    ClientRepresentation app2 = ClientBuilder.create().id(KeycloakModelUtils.generateId()).clientId("resource-owner-public").directAccessGrants().publicClient().build();
    realm.client(app2);
    ClientRepresentation app3 = ClientBuilder.create().id(KeycloakModelUtils.generateId()).clientId("resource-owner-refresh").directAccessGrants().secret("secret").build();
    OIDCAdvancedConfigWrapper.fromClientRepresentation(app3).setUseRefreshToken(false);
    realm.client(app3);
    UserBuilder defaultUser = UserBuilder.create().id(KeycloakModelUtils.generateId()).username("test-user@localhost").password("password");
    realm.user(defaultUser);
    userId = KeycloakModelUtils.generateId();
    UserRepresentation user = UserBuilder.create().id(userId).username("direct-login").email("direct-login@localhost").password("password").build();
    realm.user(user);
    userId2 = KeycloakModelUtils.generateId();
    UserRepresentation user2 = UserBuilder.create().id(userId2).username("direct-login-otp").password("password").totpSecret("totpSecret").build();
    realm.user(user2);
    userIdMultipleOTPs = KeycloakModelUtils.generateId();
    UserBuilder userBuilderMultipleOTPs = UserBuilder.create().id(userIdMultipleOTPs).username("direct-login-multiple-otps").password("password").totpSecret("firstOTPIsPreferredCredential");
    for (int i = 2; i <= 10; i++) userBuilderMultipleOTPs.totpSecret(String.format("%s-th OTP authenticator", i));
    realm.user(userBuilderMultipleOTPs.build());
    testRealms.add(realm.build());
}
Also used : RealmBuilder(org.keycloak.testsuite.util.RealmBuilder) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) UserBuilder(org.keycloak.testsuite.util.UserBuilder) UserRepresentation(org.keycloak.representations.idm.UserRepresentation)

Aggregations

UserBuilder (org.keycloak.testsuite.util.UserBuilder)8 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)4 RealmBuilder (org.keycloak.testsuite.util.RealmBuilder)4 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)3 List (java.util.List)2 Map (java.util.Map)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 OAuth2Constants (org.keycloak.OAuth2Constants)2 KeycloakModelUtils (org.keycloak.models.utils.KeycloakModelUtils)2 HardcodedClaim (org.keycloak.protocol.oidc.mappers.HardcodedClaim)2 ProtocolMapperRepresentation (org.keycloak.representations.idm.ProtocolMapperRepresentation)2 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)2 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)2 AssertEvents (org.keycloak.testsuite.AssertEvents)2 AbstractAdminTest.loadJson (org.keycloak.testsuite.admin.AbstractAdminTest.loadJson)2 ClientManager (org.keycloak.testsuite.util.ClientManager)2 OAuthClient (org.keycloak.testsuite.util.OAuthClient)2