Search in sources :

Example 6 with UserBuilder

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

the class ServiceAccountTest 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 enabledApp = ClientBuilder.create().id(KeycloakModelUtils.generateId()).clientId("service-account-cl-refresh-on").secret("secret1").serviceAccountsEnabled(true).attribute(OIDCConfigAttributes.USE_REFRESH_TOKEN_FOR_CLIENT_CREDENTIALS_GRANT, "true").build();
    realm.client(enabledApp);
    ClientRepresentation enabledAppWithSkipRefreshToken = ClientBuilder.create().id(KeycloakModelUtils.generateId()).clientId("service-account-cl").secret("secret1").serviceAccountsEnabled(true).build();
    realm.client(enabledAppWithSkipRefreshToken);
    ClientRepresentation disabledApp = ClientBuilder.create().id(KeycloakModelUtils.generateId()).clientId("service-account-disabled").secret("secret1").build();
    realm.client(disabledApp);
    UserBuilder defaultUser = UserBuilder.create().id(KeycloakModelUtils.generateId()).username("test-user@localhost");
    realm.user(defaultUser);
    userId = KeycloakModelUtils.generateId();
    userName = ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + enabledApp.getClientId();
    UserBuilder serviceAccountUser = UserBuilder.create().id(userId).username(userName).serviceAccountId(enabledApp.getClientId());
    realm.user(serviceAccountUser);
    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 7 with UserBuilder

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

the class AccessTokenTest 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());
    realm.getClients().stream().filter(clientRepresentation -> {
        return "test-app".equals(clientRepresentation.getClientId());
    }).forEach(clientRepresentation -> {
        clientRepresentation.setFullScopeAllowed(false);
    });
    testRealms.add(realm);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) AbstractAdminTest.loadJson(org.keycloak.testsuite.admin.AbstractAdminTest.loadJson) AssertEvents(org.keycloak.testsuite.AssertEvents) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) AdminClientUtil(org.keycloak.testsuite.util.AdminClientUtil) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) UriBuilder(javax.ws.rs.core.UriBuilder) ClientManager(org.keycloak.testsuite.util.ClientManager) UserInfoClientUtil(org.keycloak.testsuite.util.UserInfoClientUtil) RealmResource(org.keycloak.admin.client.resource.RealmResource) Matchers.allOf(org.hamcrest.Matchers.allOf) IDToken(org.keycloak.representations.IDToken) TextNode(com.fasterxml.jackson.databind.node.TextNode) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) RoleBuilder(org.keycloak.testsuite.util.RoleBuilder) ModelToRepresentation(org.keycloak.models.utils.ModelToRepresentation) OIDCConfigAttributes(org.keycloak.protocol.oidc.OIDCConfigAttributes) SslRequired(org.keycloak.common.enums.SslRequired) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest) OAuth2Constants(org.keycloak.OAuth2Constants) UserManager(org.keycloak.testsuite.util.UserManager) BasicAuthHelper(org.keycloak.util.BasicAuthHelper) ProtocolMapperModel(org.keycloak.models.ProtocolMapperModel) Algorithm(org.keycloak.crypto.Algorithm) ApiUtil.findUserByUsername(org.keycloak.testsuite.admin.ApiUtil.findUserByUsername) TokenUtil(org.keycloak.util.TokenUtil) UserModel(org.keycloak.models.UserModel) UserBuilder(org.keycloak.testsuite.util.UserBuilder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Base64Url(org.keycloak.common.util.Base64Url) OIDCLoginProtocolService(org.keycloak.protocol.oidc.OIDCLoginProtocolService) Before(org.junit.Before) ApiUtil(org.keycloak.testsuite.admin.ApiUtil) TreeNode(com.fasterxml.jackson.core.TreeNode) JWSInput(org.keycloak.jose.jws.JWSInput) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Matchers.hasItemInArray(org.hamcrest.Matchers.hasItemInArray) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Assert.assertNull(org.junit.Assert.assertNull) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) JWSHeader(org.keycloak.jose.jws.JWSHeader) Security(java.security.Security) Assert.assertExpiration(org.keycloak.testsuite.Assert.assertExpiration) OAuthClient(org.keycloak.testsuite.util.OAuthClient) AccessToken(org.keycloak.representations.AccessToken) URI(java.net.URI) ClientResource(org.keycloak.admin.client.resource.ClientResource) ApiUtil.findClientByClientId(org.keycloak.testsuite.admin.ApiUtil.findClientByClientId) RealmManager(org.keycloak.testsuite.util.RealmManager) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Entity(javax.ws.rs.client.Entity) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) EventRepresentation(org.keycloak.representations.idm.EventRepresentation) ProtocolMapperRepresentation(org.keycloak.representations.idm.ProtocolMapperRepresentation) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Details(org.keycloak.events.Details) ActionURIUtils(org.keycloak.testsuite.ActionURIUtils) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HardcodedClaim(org.keycloak.protocol.oidc.mappers.HardcodedClaim) BeforeClass(org.junit.BeforeClass) KeycloakModelUtils(org.keycloak.models.utils.KeycloakModelUtils) Form(javax.ws.rs.core.Form) Client(javax.ws.rs.client.Client) JWSInputException(org.keycloak.jose.jws.JWSInputException) AUTH_SERVER_SSL_REQUIRED(org.keycloak.testsuite.util.ServerURLs.AUTH_SERVER_SSL_REQUIRED) OIDCAdvancedConfigWrapper(org.keycloak.protocol.oidc.OIDCAdvancedConfigWrapper) ECDSASignatureProvider(org.keycloak.crypto.ECDSASignatureProvider) ApiUtil.findUserByUsernameId(org.keycloak.testsuite.admin.ApiUtil.findUserByUsernameId) UserResource(org.keycloak.admin.client.resource.UserResource) LinkedList(java.util.LinkedList) RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) AUTH_SERVER_ROOT(org.keycloak.testsuite.util.OAuthClient.AUTH_SERVER_ROOT) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Errors(org.keycloak.events.Errors) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) JsonParser(com.fasterxml.jackson.core.JsonParser) Assert.assertNotNull(org.junit.Assert.assertNotNull) By(org.openqa.selenium.By) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ProtocolMapperUtil.createRoleNameMapper(org.keycloak.testsuite.util.ProtocolMapperUtil.createRoleNameMapper) ClientScopeResource(org.keycloak.admin.client.resource.ClientScopeResource) TimeUnit(java.util.concurrent.TimeUnit) JsonSerialization(org.keycloak.util.JsonSerialization) Rule(org.junit.Rule) TokenSignatureUtil(org.keycloak.testsuite.util.TokenSignatureUtil) ClientBuilder(org.keycloak.testsuite.util.ClientBuilder) WebTarget(javax.ws.rs.client.WebTarget) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) UserBuilder(org.keycloak.testsuite.util.UserBuilder)

Example 8 with UserBuilder

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

the class OAuthProofKeyForCodeExchangeTest 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());
    testRealms.add(realm);
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) UserBuilder(org.keycloak.testsuite.util.UserBuilder)

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