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

The following examples show how to use org.keycloak.representations.idm.ClientRepresentation#setAuthorizationSettings() . 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: KeycloakTestResource.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static ClientRepresentation createClient(String clientId) {
    ClientRepresentation client = new ClientRepresentation();

    client.setClientId(clientId);
    client.setPublicClient(false);
    client.setSecret("secret");
    client.setDirectAccessGrantsEnabled(true);
    client.setEnabled(true);

    client.setAuthorizationServicesEnabled(true);

    ResourceServerRepresentation authorizationSettings = new ResourceServerRepresentation();

    authorizationSettings.setResources(new ArrayList<>());
    authorizationSettings.setPolicies(new ArrayList<>());

    configurePermissionResourcePermission(authorizationSettings);
    configureClaimBasedPermission(authorizationSettings);
    configureHttpResponseClaimBasedPermission(authorizationSettings);
    configureBodyClaimBasedPermission(authorizationSettings);
    configurePaths(authorizationSettings);

    client.setAuthorizationSettings(authorizationSettings);

    return client;
}
 
Example 2
Source File: KeycloakTestResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static ClientRepresentation createClient(String clientId) {
    ClientRepresentation client = new ClientRepresentation();

    client.setClientId(clientId);
    client.setPublicClient(false);
    client.setSecret("secret");
    client.setDirectAccessGrantsEnabled(true);
    client.setEnabled(true);

    client.setAuthorizationServicesEnabled(true);

    ResourceServerRepresentation authorizationSettings = new ResourceServerRepresentation();

    authorizationSettings.setResources(new ArrayList<>());
    authorizationSettings.setPolicies(new ArrayList<>());

    configurePermissionResourcePermission(authorizationSettings);
    configureClaimBasedPermission(authorizationSettings);
    configureHttpResponseClaimBasedPermission(authorizationSettings);
    configureBodyClaimBasedPermission(authorizationSettings);
    configurePaths(authorizationSettings);
    configureScopePermission(authorizationSettings);

    client.setAuthorizationSettings(authorizationSettings);

    return client;
}
 
Example 3
Source File: PartialImportTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void addClients(boolean withServiceAccounts) throws IOException {
    List<ClientRepresentation> clients = new ArrayList<>();
    List<UserRepresentation> serviceAccounts = new ArrayList<>();

    for (int i = 0; i < NUM_ENTITIES; i++) {
        ClientRepresentation client = new ClientRepresentation();
        client.setClientId(CLIENT_PREFIX + i);
        client.setName(CLIENT_PREFIX + i);
        clients.add(client);
        if (withServiceAccounts) {
            client.setServiceAccountsEnabled(true);
            client.setBearerOnly(false);
            client.setPublicClient(false);
            client.setAuthorizationSettings(resourceServerSampleSettings);
            client.setAuthorizationServicesEnabled(true);
            // create the user service account
            UserRepresentation serviceAccount = new UserRepresentation();
            serviceAccount.setUsername(ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + client.getClientId());
            serviceAccount.setEnabled(true);
            serviceAccount.setEmail(serviceAccount.getUsername() + "@placeholder.org");
            serviceAccount.setServiceAccountClientId(client.getClientId());
            serviceAccounts.add(serviceAccount);
        }
    }

    if (withServiceAccounts) {
        if (piRep.getUsers() == null) {
            piRep.setUsers(new ArrayList<>());
        }
        piRep.getUsers().addAll(serviceAccounts);
    }
    piRep.setClients(clients);
}
 
Example 4
Source File: ExportUtils.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Full export of application including claims and secret
 * @param client
 * @return full ApplicationRepresentation
 */
public static ClientRepresentation exportClient(KeycloakSession session, ClientModel client) {
    ClientRepresentation clientRep = ModelToRepresentation.toRepresentation(client, session);
    clientRep.setSecret(client.getSecret());
    clientRep.setAuthorizationSettings(exportAuthorizationSettings(session,client));
    return clientRep;
}