Search in sources :

Example 26 with ClientModel

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

the class DefaultClientRegistrationProvider method getDefault.

@GET
@Path("{clientId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getDefault(@PathParam("clientId") String clientId) {
    ClientModel client = session.getContext().getRealm().getClientByClientId(clientId);
    ClientRepresentation clientRepresentation = get(client);
    return Response.ok(clientRepresentation).build();
}
Also used : ClientModel(org.keycloak.models.ClientModel) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 27 with ClientModel

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

the class AdapterInstallationClientRegistrationProvider method get.

@GET
@Path("{clientId}")
@Produces(MediaType.APPLICATION_JSON)
public Response get(@PathParam("clientId") String clientId) {
    event.event(EventType.CLIENT_INFO);
    ClientModel client = session.getContext().getRealm().getClientByClientId(clientId);
    auth.requireView(client, true);
    ClientManager clientManager = new ClientManager(new RealmManager(session));
    Object rep = clientManager.toInstallationRepresentation(session.getContext().getRealm(), client, session.getContext().getUri().getBaseUri());
    event.client(client.getClientId()).success();
    return Response.ok(rep).build();
}
Also used : ClientModel(org.keycloak.models.ClientModel) ClientManager(org.keycloak.services.managers.ClientManager) RealmManager(org.keycloak.services.managers.RealmManager) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 28 with ClientModel

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

the class AbstractClientRegistrationProvider method create.

public ClientRepresentation create(ClientRegistrationContext context) {
    ClientRepresentation client = context.getClient();
    event.event(EventType.CLIENT_REGISTER);
    RegistrationAuth registrationAuth = auth.requireCreate(context);
    try {
        RealmModel realm = session.getContext().getRealm();
        ClientModel clientModel = ClientManager.createClient(session, realm, client);
        if (client.getDefaultRoles() != null) {
            for (String name : client.getDefaultRoles()) {
                clientModel.addDefaultRole(name);
            }
        }
        if (clientModel.isServiceAccountsEnabled()) {
            new ClientManager(new RealmManager(session)).enableServiceAccount(clientModel);
        }
        if (Boolean.TRUE.equals(client.getAuthorizationServicesEnabled())) {
            RepresentationToModel.createResourceServer(clientModel, session, true);
        }
        session.clientPolicy().triggerOnEvent(new DynamicClientRegisteredContext(context, clientModel, auth.getJwt(), realm));
        ClientRegistrationPolicyManager.triggerAfterRegister(context, registrationAuth, clientModel);
        client = ModelToRepresentation.toRepresentation(clientModel, session);
        client.setSecret(clientModel.getSecret());
        String registrationAccessToken = ClientRegistrationTokenUtils.updateRegistrationAccessToken(session, clientModel, registrationAuth);
        client.setRegistrationAccessToken(registrationAccessToken);
        if (auth.isInitialAccessToken()) {
            ClientInitialAccessModel initialAccessModel = auth.getInitialAccessModel();
            session.realms().decreaseRemainingCount(realm, initialAccessModel);
        }
        client.setDirectAccessGrantsEnabled(false);
        Stream<String> defaultRolesNames = clientModel.getDefaultRolesStream();
        if (defaultRolesNames != null) {
            client.setDefaultRoles(defaultRolesNames.toArray(String[]::new));
        }
        event.client(client.getClientId()).success();
        return client;
    } catch (ModelDuplicateException e) {
        throw new ErrorResponseException(ErrorCodes.INVALID_CLIENT_METADATA, "Client Identifier in use", Response.Status.BAD_REQUEST);
    } catch (ClientPolicyException cpe) {
        throw new ErrorResponseException(cpe.getError(), cpe.getErrorDetail(), Response.Status.BAD_REQUEST);
    }
}
Also used : ClientInitialAccessModel(org.keycloak.models.ClientInitialAccessModel) RegistrationAuth(org.keycloak.services.clientregistration.policy.RegistrationAuth) DynamicClientRegisteredContext(org.keycloak.services.clientpolicy.context.DynamicClientRegisteredContext) RealmManager(org.keycloak.services.managers.RealmManager) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) OIDCClientRepresentation(org.keycloak.representations.oidc.OIDCClientRepresentation) ClientPolicyException(org.keycloak.services.clientpolicy.ClientPolicyException) RealmModel(org.keycloak.models.RealmModel) ClientModel(org.keycloak.models.ClientModel) ClientManager(org.keycloak.services.managers.ClientManager) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) ErrorResponseException(org.keycloak.services.ErrorResponseException)

Example 29 with ClientModel

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

the class RoleLDAPStorageMapper method getTargetRoleContainer.

protected RoleContainerModel getTargetRoleContainer(RealmModel realm) {
    boolean realmRolesMapping = config.isRealmRolesMapping();
    if (realmRolesMapping) {
        return realm;
    } else {
        String clientId = config.getClientId();
        if (clientId == null) {
            throw new ModelException("Using client roles mapping is requested, but parameter client.id not found!");
        }
        ClientModel client = realm.getClientByClientId(clientId);
        if (client == null) {
            throw new ModelException("Can't found requested client with clientId: " + clientId);
        }
        return client;
    }
}
Also used : ClientModel(org.keycloak.models.ClientModel) ModelException(org.keycloak.models.ModelException)

Example 30 with ClientModel

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

the class JpaRealmProvider method addClient.

@Override
public ClientModel addClient(RealmModel realm, String id, String clientId) {
    if (id == null) {
        id = KeycloakModelUtils.generateId();
    }
    if (clientId == null) {
        clientId = id;
    }
    logger.tracef("addClient(%s, %s, %s)%s", realm, id, clientId, getShortStackTrace());
    ClientEntity entity = new ClientEntity();
    entity.setId(id);
    entity.setClientId(clientId);
    entity.setEnabled(true);
    entity.setStandardFlowEnabled(true);
    entity.setRealmId(realm.getId());
    em.persist(entity);
    final ClientModel resource = new ClientAdapter(realm, em, session, entity);
    session.getKeycloakSessionFactory().publish((ClientModel.ClientCreationEvent) () -> resource);
    return resource;
}
Also used : ClientEntity(org.keycloak.models.jpa.entities.ClientEntity) ClientModel(org.keycloak.models.ClientModel)

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