Search in sources :

Example 41 with RealmResource

use of org.keycloak.admin.client.resource.RealmResource in project keycloak by keycloak.

the class UsersTest method countUsersByFiltersWithNoViewPermission.

@Test
public void countUsersByFiltersWithNoViewPermission() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException {
    ProfileAssume.assumeFeatureEnabled(Profile.Feature.AUTHORIZATION);
    RealmResource testRealmResource = setupTestEnvironmentWithPermissions(false);
    // search username
    assertThat(testRealmResource.users().count(null, null, null, "user"), is(0));
    assertThat(testRealmResource.users().count(null, null, null, "user1"), is(0));
    assertThat(testRealmResource.users().count(null, null, null, "notExisting"), is(0));
    assertThat(testRealmResource.users().count(null, null, null, ""), is(0));
    // search first name
    assertThat(testRealmResource.users().count(null, "FirstName", null, null), is(0));
    assertThat(testRealmResource.users().count(null, "user2FirstName", null, null), is(0));
    assertThat(testRealmResource.users().count(null, "notExisting", null, null), is(0));
    assertThat(testRealmResource.users().count(null, "", null, null), is(0));
    // search last name
    assertThat(testRealmResource.users().count("LastName", null, null, null), is(0));
    assertThat(testRealmResource.users().count("user2LastName", null, null, null), is(0));
    assertThat(testRealmResource.users().count("notExisting", null, null, null), is(0));
    assertThat(testRealmResource.users().count("", null, null, null), is(0));
    // search in email
    assertThat(testRealmResource.users().count(null, null, "@example.com", null), is(0));
    assertThat(testRealmResource.users().count(null, null, "user1@example.com", null), is(0));
    assertThat(testRealmResource.users().count(null, null, "user1@test.com", null), is(0));
    assertThat(testRealmResource.users().count(null, null, "", null), is(0));
    // search for combinations
    assertThat(testRealmResource.users().count("LastName", "FirstName", null, null), is(0));
    assertThat(testRealmResource.users().count("user1LastName", "FirstName", null, null), is(0));
    assertThat(testRealmResource.users().count("user1LastName", "", null, null), is(0));
    assertThat(testRealmResource.users().count("LastName", "", null, null), is(0));
    assertThat(testRealmResource.users().count("LastName", "", null, null), is(0));
    assertThat(testRealmResource.users().count(null, null, "@example.com", "user"), is(0));
    // search not specified (defaults to simply /count)
    assertThat(testRealmResource.users().count(null, null, null, null), is(0));
    assertThat(testRealmResource.users().count("", "", "", ""), is(0));
}
Also used : RealmResource(org.keycloak.admin.client.resource.RealmResource) Test(org.junit.Test)

Example 42 with RealmResource

use of org.keycloak.admin.client.resource.RealmResource in project keycloak by keycloak.

the class UsersTest method countUsersBySearchWithGroupViewPermission.

@Test
public void countUsersBySearchWithGroupViewPermission() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException {
    ProfileAssume.assumeFeatureEnabled(Profile.Feature.AUTHORIZATION);
    RealmResource testRealmResource = setupTestEnvironmentWithPermissions(true);
    // search all
    assertThat(testRealmResource.users().count("user"), is(3));
    // search first name
    assertThat(testRealmResource.users().count("*FirstName*"), is(3));
    assertThat(testRealmResource.users().count("user2FirstName"), is(1));
    // search last name
    assertThat(testRealmResource.users().count("*LastName*"), is(3));
    assertThat(testRealmResource.users().count("user2LastName"), is(1));
    // search in email
    assertThat(testRealmResource.users().count("*@example.com*"), is(3));
    assertThat(testRealmResource.users().count("user1@example.com"), is(1));
    // search for something not existing
    assertThat(testRealmResource.users().count("notExisting"), is(0));
    // search for empty string
    assertThat(testRealmResource.users().count(""), is(3));
    // search not specified (defaults to simply /count)
    assertThat(testRealmResource.users().count(null), is(3));
}
Also used : RealmResource(org.keycloak.admin.client.resource.RealmResource) Test(org.junit.Test)

Example 43 with RealmResource

use of org.keycloak.admin.client.resource.RealmResource in project keycloak by keycloak.

the class AbstractPolicyManagementTest method configureAuthorization.

@Before
public void configureAuthorization() throws Exception {
    createResourcesAndScopes();
    RealmResource realm = getRealm();
    createPolicies(realm, getClient(realm));
}
Also used : RealmResource(org.keycloak.admin.client.resource.RealmResource) Before(org.junit.Before)

Example 44 with RealmResource

use of org.keycloak.admin.client.resource.RealmResource in project keycloak by keycloak.

the class AbstractKerberosTest method updateKerberosAuthExecutionRequirement.

public static AuthenticationExecutionModel.Requirement updateKerberosAuthExecutionRequirement(AuthenticationExecutionModel.Requirement requirement, RealmResource realmResource) {
    Optional<AuthenticationExecutionInfoRepresentation> kerberosAuthExecutionOpt = realmResource.flows().getExecutions(DefaultAuthenticationFlows.BROWSER_FLOW).stream().filter(e -> e.getProviderId().equals(SpnegoAuthenticatorFactory.PROVIDER_ID)).findFirst();
    Assert.assertTrue(kerberosAuthExecutionOpt.isPresent());
    AuthenticationExecutionInfoRepresentation kerberosAuthExecution = kerberosAuthExecutionOpt.get();
    String oldRequirementStr = kerberosAuthExecution.getRequirement();
    AuthenticationExecutionModel.Requirement oldRequirement = AuthenticationExecutionModel.Requirement.valueOf(oldRequirementStr);
    kerberosAuthExecution.setRequirement(requirement.name());
    realmResource.flows().updateExecutions(DefaultAuthenticationFlows.BROWSER_FLOW, kerberosAuthExecution);
    return oldRequirement;
}
Also used : DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) AbstractAdminTest.loadJson(org.keycloak.testsuite.admin.AbstractAdminTest.loadJson) AssertEvents(org.keycloak.testsuite.AssertEvents) NamingException(javax.naming.NamingException) Page(org.jboss.arquillian.graphene.page.Page) DefaultAuthenticationFlows(org.keycloak.models.utils.DefaultAuthenticationFlows) KerberosRule(org.keycloak.testsuite.util.KerberosRule) LDAPConstants(org.keycloak.models.LDAPConstants) OAuthClient(org.keycloak.testsuite.util.OAuthClient) AccessToken(org.keycloak.representations.AccessToken) Map(java.util.Map) After(org.junit.After) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel) URI(java.net.URI) GSSCredential(org.ietf.jgss.GSSCredential) RealmResource(org.keycloak.admin.client.resource.RealmResource) CommonKerberosConfig(org.keycloak.federation.kerberos.CommonKerberosConfig) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) List(java.util.List) ModelToRepresentation(org.keycloak.models.utils.ModelToRepresentation) Principal(java.security.Principal) AuthRealm(org.keycloak.testsuite.auth.page.AuthRealm) Response(javax.ws.rs.core.Response) Details(org.keycloak.events.Details) LoginPage(org.keycloak.testsuite.pages.LoginPage) Attributes(javax.naming.directory.Attributes) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) URLEncodedUtils(org.apache.http.client.utils.URLEncodedUtils) Optional(java.util.Optional) NameValuePair(org.apache.http.NameValuePair) OAuth2Constants(org.keycloak.OAuth2Constants) Assert(org.keycloak.testsuite.Assert) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) AuthSchemes(org.apache.http.client.config.AuthSchemes) InitialDirContext(javax.naming.directory.InitialDirContext) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) AbstractAuthTest(org.keycloak.testsuite.AbstractAuthTest) UserModel(org.keycloak.models.UserModel) AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) Credentials(org.apache.http.auth.Credentials) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) Context(javax.naming.Context) Sasl(javax.security.sasl.Sasl) AccountPasswordPage(org.keycloak.testsuite.pages.AccountPasswordPage) AuthServer(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer) Hashtable(java.util.Hashtable) Before(org.junit.Before) ApiUtil(org.keycloak.testsuite.admin.ApiUtil) SpnegoAuthenticatorFactory(org.keycloak.authentication.authenticators.browser.SpnegoAuthenticatorFactory) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) UserStorageProvider(org.keycloak.storage.UserStorageProvider) DirContext(javax.naming.directory.DirContext) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) AuthScope(org.apache.http.auth.AuthScope) HttpClientBuilder(org.keycloak.adapters.HttpClientBuilder) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)

Example 45 with RealmResource

use of org.keycloak.admin.client.resource.RealmResource in project keycloak by keycloak.

the class UncaughtErrorPageTest method internationalisationEnabled.

@Test
public void internationalisationEnabled() throws MalformedURLException {
    RealmResource testRealm = realmsResouce().realm("master");
    RealmRepresentation rep = testRealm.toRepresentation();
    rep.setInternationalizationEnabled(true);
    rep.setDefaultLocale("en");
    rep.setSupportedLocales(Collections.singleton("en"));
    testRealm.update(rep);
    try {
        checkPageNotFound("/auth/realms/master/nosuch");
        checkPageNotFound("/auth/nosuch");
    } finally {
        rep.setInternationalizationEnabled(false);
        testRealm.update(rep);
    }
}
Also used : RealmResource(org.keycloak.admin.client.resource.RealmResource) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Aggregations

RealmResource (org.keycloak.admin.client.resource.RealmResource)263 Test (org.junit.Test)190 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)67 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)61 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)58 Response (javax.ws.rs.core.Response)55 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)48 ClientResource (org.keycloak.admin.client.resource.ClientResource)39 OAuthClient (org.keycloak.testsuite.util.OAuthClient)37 GroupRepresentation (org.keycloak.representations.idm.GroupRepresentation)36 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)34 Before (org.junit.Before)31 UserResource (org.keycloak.admin.client.resource.UserResource)30 IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)25 List (java.util.List)19 LinkedList (java.util.LinkedList)16 ClientScopeRepresentation (org.keycloak.representations.idm.ClientScopeRepresentation)16 VerifyProfileTest (org.keycloak.testsuite.forms.VerifyProfileTest)14 ProtocolMapperRepresentation (org.keycloak.representations.idm.ProtocolMapperRepresentation)13 AccessToken (org.keycloak.representations.AccessToken)12