Java Code Examples for org.keycloak.representations.idm.ClientRepresentation#getClientId()

The following examples show how to use org.keycloak.representations.idm.ClientRepresentation#getClientId() . 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: ClientImportService.java    From keycloak-config-cli with Apache License 2.0 6 votes vote down vote up
private void createOrUpdateClient(RealmImport realmImport, ClientRepresentation client) {
    String clientId = client.getClientId();
    String realm = realmImport.getRealm();

    Optional<ClientRepresentation> maybeClient = clientRepository.tryToFindClient(realm, clientId);

    if (maybeClient.isPresent()) {
        updateClientIfNeeded(realm, client, maybeClient.get());
    } else {
        logger.debug("Create client '{}' in realm '{}'", clientId, realm);
        try {
            clientRepository.create(realm, client);
        } catch (KeycloakRepositoryException error) {
            throw new ImportProcessingException("Cannot create client '" + client.getClientId() + "' for realm '" + realm + "': " + error.getMessage(), error);
        }
    }
}
 
Example 2
Source File: ClientImportService.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private void updateClient(String realm, ClientRepresentation patchedClient) {
    try {
        clientRepository.update(realm, patchedClient);
    } catch (WebApplicationException error) {
        String errorMessage = ResponseUtil.getErrorMessage(error);
        throw new ImportProcessingException("Cannot update client '" + patchedClient.getClientId() + "' for realm '" + realm + "': " + errorMessage, error);
    }

    List<ProtocolMapperRepresentation> protocolMappers = patchedClient.getProtocolMappers();
    if (protocolMappers != null) {
        String clientId = patchedClient.getId();
        updateProtocolMappers(realm, clientId, protocolMappers);
    }
}
 
Example 3
Source File: ExportImportUtil.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private static Matcher<Iterable<? super String>> getDefaultClientScopeNameMatcher(ClientRepresentation rep) {
    switch (rep.getClientId()) {
        case "client-with-template":
            return Matchers.hasItem("Default_test_template");
        default:
            return Matchers.not(Matchers.hasItem("Default_test_template"));
    }
}
 
Example 4
Source File: ClientResource.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void updateClientFromRep(ClientRepresentation rep, ClientModel client, KeycloakSession session) throws ModelDuplicateException {
    UserModel serviceAccount = this.session.users().getServiceAccount(client);
    if (TRUE.equals(rep.isServiceAccountsEnabled())) {
        if (serviceAccount == null) {
            new ClientManager(new RealmManager(session)).enableServiceAccount(client);
        }
    }
    else {
        if (serviceAccount != null) {
            new UserManager(session).removeUser(realm, serviceAccount);
        }
    }

    if (rep.getClientId() != null && !rep.getClientId().equals(client.getClientId())) {
        new ClientManager(new RealmManager(session)).clientIdChanged(client, rep.getClientId());
    }

    if (rep.isFullScopeAllowed() != null && rep.isFullScopeAllowed() != client.isFullScopeAllowed()) {
        auth.clients().requireManage(client);
    }

    if ((rep.isBearerOnly() != null && rep.isBearerOnly()) || (rep.isPublicClient() != null && rep.isPublicClient())) {
        rep.setAuthorizationServicesEnabled(false);
    }

    RepresentationToModel.updateClient(rep, client);
    RepresentationToModel.updateClientProtocolMappers(rep, client);
    updateAuthorizationSettings(rep);
}
 
Example 5
Source File: ServiceAccountTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@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")
            .secret("secret1")
            .serviceAccountsEnabled(true)
            .build();

    realm.client(enabledApp);

    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());
}
 
Example 6
Source File: ClientsPartialImport.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public String getName(ClientRepresentation clientRep) {
    return clientRep.getClientId();
}