Search in sources :

Example 66 with ClientModel

use of org.keycloak.models.ClientModel in project keycloak by keycloak.

the class KeycloakModelUtils method createManagementClient.

public static ClientModel createManagementClient(RealmModel realm, String name) {
    ClientModel client = createClient(realm, name);
    client.setBearerOnly(true);
    return client;
}
Also used : ClientModel(org.keycloak.models.ClientModel)

Example 67 with ClientModel

use of org.keycloak.models.ClientModel in project keycloak by keycloak.

the class MigrateTo8_0_0 method migrateRealmCommon.

protected void migrateRealmCommon(RealmModel realm) {
    ClientModel adminConsoleClient = realm.getClientByClientId(Constants.ADMIN_CONSOLE_CLIENT_ID);
    if (adminConsoleClient != null) {
        adminConsoleClient.setRootUrl(Constants.AUTH_ADMIN_URL_PROP);
        String adminConsoleBaseUrl = "/admin/" + realm.getName() + "/console/";
        adminConsoleClient.setBaseUrl(adminConsoleBaseUrl);
        adminConsoleClient.setRedirectUris(Collections.singleton(adminConsoleBaseUrl + "*"));
        adminConsoleClient.setWebOrigins(Collections.singleton("+"));
    }
    ClientModel accountClient = realm.getClientByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID);
    if (accountClient != null) {
        accountClient.setRootUrl(Constants.AUTH_BASE_URL_PROP);
        String accountClientBaseUrl = "/realms/" + realm.getName() + "/account/";
        accountClient.setBaseUrl(accountClientBaseUrl);
        accountClient.setRedirectUris(Collections.singleton(accountClientBaseUrl + "*"));
    }
}
Also used : ClientModel(org.keycloak.models.ClientModel)

Example 68 with ClientModel

use of org.keycloak.models.ClientModel in project keycloak by keycloak.

the class MigrationUtils method addAdminRole.

public static void addAdminRole(RealmModel realm, String roleName) {
    ClientModel client = realm.getMasterAdminClient();
    if (client != null && client.getRole(roleName) == null) {
        RoleModel role = client.addRole(roleName);
        role.setDescription("${role_" + roleName + "}");
        client.getRealm().getRole(AdminRoles.ADMIN).addCompositeRole(role);
    }
    if (!realm.getName().equals(Config.getAdminRealm())) {
        client = realm.getClientByClientId(Constants.REALM_MANAGEMENT_CLIENT_ID);
        if (client != null && client.getRole(roleName) == null) {
            RoleModel role = client.addRole(roleName);
            role.setDescription("${role_" + roleName + "}");
            client.getRole(AdminRoles.REALM_ADMIN).addCompositeRole(role);
        }
    }
}
Also used : ClientModel(org.keycloak.models.ClientModel) RoleModel(org.keycloak.models.RoleModel)

Example 69 with ClientModel

use of org.keycloak.models.ClientModel in project keycloak by keycloak.

the class AuthenticationFlowResolver method resolveDirectGrantFlow.

public static AuthenticationFlowModel resolveDirectGrantFlow(AuthenticationSessionModel authSession) {
    AuthenticationFlowModel flow = null;
    ClientModel client = authSession.getClient();
    String clientFlow = client.getAuthenticationFlowBindingOverride(AuthenticationFlowBindings.DIRECT_GRANT_BINDING);
    if (clientFlow != null) {
        flow = authSession.getRealm().getAuthenticationFlowById(clientFlow);
        if (flow == null) {
            throw new ModelException("Client " + client.getClientId() + " has direct grant flow override, but this flow does not exist");
        }
        return flow;
    }
    return authSession.getRealm().getDirectGrantFlow();
}
Also used : ClientModel(org.keycloak.models.ClientModel) ModelException(org.keycloak.models.ModelException) AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel)

Example 70 with ClientModel

use of org.keycloak.models.ClientModel in project keycloak by keycloak.

the class LogoutEndpoint method authorizeClient.

private ClientModel authorizeClient() {
    ClientModel client = AuthorizeClientUtil.authorizeClient(session, event, cors).getClient();
    cors.allowedOrigins(session, client);
    if (client.isBearerOnly()) {
        throw new CorsErrorResponseException(cors, Errors.INVALID_CLIENT, "Bearer-only not allowed", Response.Status.BAD_REQUEST);
    }
    return client;
}
Also used : ClientModel(org.keycloak.models.ClientModel) CorsErrorResponseException(org.keycloak.services.CorsErrorResponseException)

Aggregations

ClientModel (org.keycloak.models.ClientModel)344 RealmModel (org.keycloak.models.RealmModel)148 UserModel (org.keycloak.models.UserModel)88 RoleModel (org.keycloak.models.RoleModel)74 KeycloakSession (org.keycloak.models.KeycloakSession)67 Test (org.junit.Test)64 UserSessionModel (org.keycloak.models.UserSessionModel)41 ResourceServer (org.keycloak.authorization.model.ResourceServer)39 Policy (org.keycloak.authorization.model.Policy)38 HashMap (java.util.HashMap)37 AuthorizationProvider (org.keycloak.authorization.AuthorizationProvider)36 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)34 ModelTest (org.keycloak.testsuite.arquillian.annotation.ModelTest)34 List (java.util.List)32 Map (java.util.Map)32 Path (javax.ws.rs.Path)29 LinkedList (java.util.LinkedList)28 ClientScopeModel (org.keycloak.models.ClientScopeModel)28 ArrayList (java.util.ArrayList)27 AuthenticatedClientSessionModel (org.keycloak.models.AuthenticatedClientSessionModel)27