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

The following examples show how to use org.keycloak.representations.idm.ClientRepresentation#getProtocol() . 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: ClientManager.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Should not be called from an import.  This really expects that the client is created from the admin console.
 *
 * @param session
 * @param realm
 * @param rep
 * @param addDefaultRoles
 * @return
 */
public static ClientModel createClient(KeycloakSession session, RealmModel realm, ClientRepresentation rep, boolean addDefaultRoles) {
    ClientModel client = RepresentationToModel.createClient(session, realm, rep, addDefaultRoles);

    if (rep.getProtocol() != null) {
        LoginProtocolFactory providerFactory = (LoginProtocolFactory) session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, rep.getProtocol());
        providerFactory.setupClientDefaults(rep, client);
    }


    // remove default mappers if there is a template
    if (rep.getProtocolMappers() == null && rep.getClientTemplate() != null) {
        Set<ProtocolMapperModel> mappers = client.getProtocolMappers();
        for (ProtocolMapperModel mapper : mappers) client.removeProtocolMapper(mapper);
    }
    return client;

}
 
Example 2
Source File: AbstractKeycloakTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void modifySamlAttributes(ClientRepresentation cr) {
    if (cr.getProtocol() != null && cr.getProtocol().equals("saml")) {
        log.debug("Modifying attributes of SAML client: " + cr.getClientId());
        for (Map.Entry<String, String> entry : cr.getAttributes().entrySet()) {
            cr.getAttributes().put(entry.getKey(), replaceHttpValuesWithHttps(entry.getValue()));
        }
    }
}
 
Example 3
Source File: AbstractAdapterTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected void modifySAMLClientsAttributes(RealmRepresentation realm, String regex, String replacement) {
    if (realm.getClients() != null) {
        for (ClientRepresentation client : realm.getClients()) {
            if (client.getProtocol() != null && client.getProtocol().equals("saml")) {
                log.debug("Modifying attributes of SAML client: " + client.getClientId());
                for (Map.Entry<String, String> entry : client.getAttributes().entrySet()) {
                    client.getAttributes().put(entry.getKey(), entry.getValue().replaceAll(regex, replacement));
                }
            }
        }
    }
}
 
Example 4
Source File: AbstractAdapterTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected void modifySamlMasterURLs(RealmRepresentation realm, String regex, String replacement) {
    if (realm.getClients() != null) {
        for (ClientRepresentation client : realm.getClients()) {
            if (client.getProtocol() != null && client.getProtocol().equals("saml")) {
                log.debug("Modifying master URL of SAML client: " + client.getClientId());
                String masterUrl = client.getAdminUrl();
                if (masterUrl == null) {
                    masterUrl = client.getBaseUrl();
                }
                masterUrl = masterUrl.replaceFirst(regex, replacement);
                client.setAdminUrl(masterUrl + ((!masterUrl.endsWith("/saml")) ? "/saml" : ""));
            }
        }
    }
}