Java Code Examples for org.keycloak.representations.idm.RealmRepresentation#setClients()
The following examples show how to use
org.keycloak.representations.idm.RealmRepresentation#setClients() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeycloakDevModeRealmResourceManager.java From quarkus with Apache License 2.0 | 8 votes |
private static RealmRepresentation createRealm(String name) { RealmRepresentation realm = new RealmRepresentation(); realm.setRealm(name); realm.setEnabled(true); realm.setUsers(new ArrayList<>()); realm.setClients(new ArrayList<>()); realm.setSsoSessionMaxLifespan(2); // sec realm.setAccessTokenLifespan(3); // 3 seconds RolesRepresentation roles = new RolesRepresentation(); List<RoleRepresentation> realmRoles = new ArrayList<>(); roles.setRealm(realmRoles); realm.setRoles(roles); realm.getRoles().getRealm().add(new RoleRepresentation("user", null, false)); return realm; }
Example 2
Source File: KeycloakRealmResourceManager.java From quarkus with Apache License 2.0 | 6 votes |
private static RealmRepresentation createRealm(String name) { RealmRepresentation realm = new RealmRepresentation(); realm.setRealm(name); realm.setEnabled(true); realm.setUsers(new ArrayList<>()); realm.setClients(new ArrayList<>()); realm.setAccessTokenLifespan(3); RolesRepresentation roles = new RolesRepresentation(); List<RoleRepresentation> realmRoles = new ArrayList<>(); roles.setRealm(realmRoles); realm.setRoles(roles); realm.getRoles().getRealm().add(new RoleRepresentation("user", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("admin", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("confidential", null, false)); return realm; }
Example 3
Source File: KeycloakTestResource.java From quarkus with Apache License 2.0 | 6 votes |
private static RealmRepresentation createRealm(String name) { RealmRepresentation realm = new RealmRepresentation(); realm.setRealm(name); realm.setEnabled(true); realm.setUsers(new ArrayList<>()); realm.setClients(new ArrayList<>()); RolesRepresentation roles = new RolesRepresentation(); List<RoleRepresentation> realmRoles = new ArrayList<>(); roles.setRealm(realmRoles); realm.setRoles(roles); realm.getRoles().getRealm().add(new RoleRepresentation("user", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("admin", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("confidential", null, false)); return realm; }
Example 4
Source File: KeycloakRealmResourceManager.java From quarkus with Apache License 2.0 | 6 votes |
private static RealmRepresentation createRealm(String name) { RealmRepresentation realm = new RealmRepresentation(); realm.setRealm(name); realm.setEnabled(true); realm.setUsers(new ArrayList<>()); realm.setClients(new ArrayList<>()); RolesRepresentation roles = new RolesRepresentation(); List<RoleRepresentation> realmRoles = new ArrayList<>(); roles.setRealm(realmRoles); realm.setRoles(roles); realm.getRoles().getRealm().add(new RoleRepresentation("user", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("admin", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("confidential", null, false)); return realm; }
Example 5
Source File: KeycloakTestResource.java From quarkus with Apache License 2.0 | 6 votes |
private static RealmRepresentation createRealm(String name) { RealmRepresentation realm = new RealmRepresentation(); realm.setRealm(name); realm.setEnabled(true); realm.setUsers(new ArrayList<>()); realm.setClients(new ArrayList<>()); RolesRepresentation roles = new RolesRepresentation(); List<RoleRepresentation> realmRoles = new ArrayList<>(); roles.setRealm(realmRoles); realm.setRoles(roles); realm.getRoles().getRealm().add(new RoleRepresentation("user", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("admin", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("confidential", null, false)); return realm; }
Example 6
Source File: KeycloakModelUtils.java From keycloak with Apache License 2.0 | 6 votes |
public static ClientRepresentation createClient(RealmRepresentation realm, String name) { ClientRepresentation app = new ClientRepresentation(); app.setName(name); app.setClientId(name); List<ClientRepresentation> clients = realm.getClients(); if (clients != null) { clients.add(app); } else { realm.setClients(Arrays.asList(app)); } app.setClientAuthenticatorType(getDefaultClientAuthenticatorType()); generateSecret(app); app.setFullScopeAllowed(true); return app; }
Example 7
Source File: AbstractSpringBootTest.java From keycloak with Apache License 2.0 | 6 votes |
@Override public void addTestRealms(List<RealmRepresentation> testRealms) { RealmRepresentation realm = new RealmRepresentation(); realm.setId(REALM_ID); realm.setRealm(REALM_NAME); realm.setEnabled(true); realm.setPublicKey(REALM_PUBLIC_KEY); realm.setPrivateKey(REALM_PRIVATE_KEY); realm.setClients(Collections.singletonList(createClient())); List<String> eventListeners = new ArrayList<>(); eventListeners.add("jboss-logging"); eventListeners.add("event-queue"); realm.setEventsListeners(eventListeners); testRealms.add(realm); }
Example 8
Source File: RealmSetup.java From keycloak-custom-protocol-mapper-example with Apache License 2.0 | 5 votes |
public void execute() { RealmRepresentation realmRepresentation = new RealmRepresentation(); realmRepresentation.setDisplayName(REALM); realmRepresentation.setId(REALM); realmRepresentation.setClients(createClients()); realmRepresentation.setLoginWithEmailAllowed(true); realmRepresentation.setEnabled(true); realmRepresentation.setRealm(REALM); this.keycloak.realms().create(realmRepresentation); }
Example 9
Source File: KeycloakRealmResourceManager.java From quarkus with Apache License 2.0 | 5 votes |
private static RealmRepresentation createRealm(String name) { RealmRepresentation realm = new RealmRepresentation(); realm.setRealm(name); realm.setEnabled(true); realm.setUsers(new ArrayList<>()); realm.setClients(new ArrayList<>()); realm.setSsoSessionMaxLifespan(3); // sec realm.setAccessTokenLifespan(4); // 3 seconds RolesRepresentation roles = new RolesRepresentation(); List<RoleRepresentation> realmRoles = new ArrayList<>(); roles.setRealm(realmRoles); realm.setRoles(roles); realm.getRoles().getRealm().add(new RoleRepresentation("user", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("admin", null, false)); realm.getRoles().getRealm().add(new RoleRepresentation("confidential", null, false)); realm.getClients().add(createClient("quarkus-app")); realm.getClients().add(createClientJwt("quarkus-app-jwt")); realm.getUsers().add(createUser("alice", "user")); realm.getUsers().add(createUser("admin", "user", "admin")); realm.getUsers().add(createUser("jdoe", "user", "confidential")); return realm; }
Example 10
Source File: DockerTestRealmSetup.java From keycloak with Apache License 2.0 | 5 votes |
public static void configureDockerRegistryClient(final RealmRepresentation dockerRealm, final String clientId) { final ClientRepresentation dockerClient = new ClientRepresentation(); dockerClient.setClientId(clientId); dockerClient.setProtocol(DockerAuthV2Protocol.LOGIN_PROTOCOL); dockerClient.setEnabled(true); final List<ClientRepresentation> clients = Optional.ofNullable(dockerRealm.getClients()).orElse(new ArrayList<>()); clients.add(dockerClient); dockerRealm.setClients(clients); }
Example 11
Source File: LinkedAccountsTest.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void addTestRealms(List<RealmRepresentation> testRealms) { super.addTestRealms(testRealms); RealmRepresentation realm1 = testRealms.get(0); realm1.addIdentityProvider(createIdentityProviderRepresentation(SOCIAL_IDP_ALIAS, GoogleIdentityProviderFactory.PROVIDER_ID)); String oidcRoot = getAuthServerRoot() + "realms/" + REALM2_NAME + "/protocol/openid-connect/"; IdentityProviderRepresentation systemIdp = createIdentityProviderRepresentation(SYSTEM_IDP_ALIAS, OIDCIdentityProviderFactory.PROVIDER_ID); systemIdp.getConfig().put("clientId", CLIENT_ID); systemIdp.getConfig().put("clientSecret", CLIENT_SECRET); systemIdp.getConfig().put("clientAuthMethod", OIDCLoginProtocol.CLIENT_SECRET_POST); systemIdp.getConfig().put("authorizationUrl", oidcRoot + "auth"); systemIdp.getConfig().put("tokenUrl", oidcRoot + "token"); realm1.addIdentityProvider(systemIdp); ClientRepresentation client = ClientBuilder.create() .clientId(CLIENT_ID) .secret(CLIENT_SECRET) .redirectUris(getAuthServerRoot() + "realms/" + TEST + "/broker/" + SYSTEM_IDP_ALIAS + "/endpoint") .build(); // using REALM2 as an identity provider RealmRepresentation realm2 = new RealmRepresentation(); realm2.setId(REALM2_NAME); realm2.setRealm(REALM2_NAME); realm2.setEnabled(true); realm2.setClients(Collections.singletonList(client)); realm2.setUsers(Collections.singletonList(homerUser)); testRealms.add(realm2); }
Example 12
Source File: ReferrerTest.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void addTestRealms(List<RealmRepresentation> testRealms) { super.addTestRealms(testRealms); RealmRepresentation testRealm = testRealms.get(0); ClientRepresentation testClient = new ClientRepresentation(); testClient.setClientId(FAKE_CLIENT_ID); testClient.setName(LOCALE_CLIENT_NAME); testClient.setRedirectUris(Collections.singletonList(getFakeClientUrl())); testClient.setEnabled(true); testRealm.setClients(Collections.singletonList(testClient)); testRealm.setAccountTheme(LOCALIZED_THEME_PREVIEW); // using localized custom theme for the fake client localized name }
Example 13
Source File: DeviceActivityTest.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void addTestRealms(List<RealmRepresentation> testRealms) { super.addTestRealms(testRealms); RealmRepresentation realm = testRealms.get(0); realm.setClients(Arrays.asList( ClientBuilder .create() .clientId(TEST_CLIENT_ID) // client with no name .secret(TEST_CLIENT_SECRET) .directAccessGrants() .build(), ClientBuilder .create(). clientId(TEST_CLIENT2_ID) .name(LOCALE_CLIENT_NAME) // client with localized name .secret(TEST_CLIENT2_SECRET) .directAccessGrants().build(), ClientBuilder .create(). clientId(TEST_CLIENT3_ID) .name(TEST_CLIENT3_NAME) // client without localized name .secret(TEST_CLIENT3_SECRET) .directAccessGrants().build() )); realm.setAccountTheme(LOCALIZED_THEME_PREVIEW); // using localized custom theme for the client localized name }
Example 14
Source File: ApplicationsTest.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void addTestRealms(List<RealmRepresentation> testRealms) { super.addTestRealms(testRealms); RealmRepresentation realm = testRealms.get(0); realm.setClients(Arrays.asList( ClientBuilder .create() .clientId("always-display-client") .id(KeycloakModelUtils.generateId()) .name("Always Display Client") .baseUrl(APP_ROOT + "/always-display-client") .directAccessGrants() .secret("secret1") .alwaysDisplayInConsole(true) .build(), ClientBuilder .create() .clientId("third-party-client") .id(KeycloakModelUtils.generateId()) .name("Third Party Client") .baseUrl(APP_ROOT + "/third-party-client") .directAccessGrants() .secret("secret1") .consentRequired(true) .build() )); }