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

The following examples show how to use org.keycloak.representations.idm.ClientRepresentation#getAdminUrl() . 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: AbstractAdapterTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * Modifies baseUrl, adminUrl and redirectUris for client based on real
 * deployment url of the app.
 *
 * @param realm
 * @param clientId
 * @param deploymentUrl
 */
protected void fixClientUrisUsingDeploymentUrl(RealmRepresentation realm, String clientId, String deploymentUrl) {
    for (ClientRepresentation client : realm.getClients()) {
        if (clientId.equals(client.getClientId())) {
            if (client.getBaseUrl() != null) {
                client.setBaseUrl(deploymentUrl);
            }
            if (client.getAdminUrl() != null) {
                client.setAdminUrl(deploymentUrl);
            }
            List<String> redirectUris = client.getRedirectUris();
            if (redirectUris != null) {
                List<String> newRedirectUris = new ArrayList<>();
                for (String uri : redirectUris) {
                    newRedirectUris.add(deploymentUrl + "/*");
                }
                client.setRedirectUris(newRedirectUris);
            }
        }
    }
}
 
Example 2
Source File: CASLoginProtocolFactory.java    From keycloak-protocol-cas with Apache License 2.0 5 votes vote down vote up
@Override
public void setupClientDefaults(ClientRepresentation rep, ClientModel newClient) {
    if (rep.getRootUrl() != null && (rep.getRedirectUris() == null || rep.getRedirectUris().isEmpty())) {
        String root = rep.getRootUrl();
        if (root.endsWith("/")) root = root + "*";
        else root = root + "/*";
        newClient.addRedirectUri(root);
    }

    if (rep.getAdminUrl() == null && rep.getRootUrl() != null) {
        newClient.setManagementUrl(rep.getRootUrl());
    }
}
 
Example 3
Source File: AbstractAdapterTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected void modifyClientUrls(RealmRepresentation realm, String regex, String replacement) {
    if (realm.getClients() != null) {
        for (ClientRepresentation client : realm.getClients()) {
            String baseUrl = client.getBaseUrl();
            if (baseUrl != null) {
                client.setBaseUrl(baseUrl.replaceAll(regex, replacement));
            }
            String adminUrl = client.getAdminUrl();
            if (adminUrl != null) {
                client.setAdminUrl(adminUrl.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" : ""));
            }
        }
    }
}
 
Example 5
Source File: OIDCLoginProtocolFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void setupClientDefaults(ClientRepresentation rep, ClientModel newClient) {
    if (rep.getRootUrl() != null && (rep.getRedirectUris() == null || rep.getRedirectUris().isEmpty())) {
        String root = rep.getRootUrl();
        if (root.endsWith("/")) root = root + "*";
        else root = root + "/*";
        newClient.addRedirectUri(root);

        Set<String> origins = new HashSet<String>();
        String origin = UriUtils.getOrigin(root);
        logger.debugv("adding default client origin: {0}" , origin);
        origins.add(origin);
        newClient.setWebOrigins(origins);
    }
    if (rep.isBearerOnly() == null
            && rep.isPublicClient() == null) {
        newClient.setPublicClient(true);
    }
    if (rep.isBearerOnly() == null) newClient.setBearerOnly(false);
    if (rep.getAdminUrl() == null && rep.getRootUrl() != null) {
        newClient.setManagementUrl(rep.getRootUrl());
    }


    // Backwards compatibility only
    if (rep.isDirectGrantsOnly() != null) {
        ServicesLogger.LOGGER.usingDeprecatedDirectGrantsOnly();
        newClient.setStandardFlowEnabled(!rep.isDirectGrantsOnly());
        newClient.setDirectAccessGrantsEnabled(rep.isDirectGrantsOnly());
    } else {
        if (rep.isStandardFlowEnabled() == null) newClient.setStandardFlowEnabled(true);
        if (rep.isDirectAccessGrantsEnabled() == null) newClient.setDirectAccessGrantsEnabled(true);

    }

    if (rep.isImplicitFlowEnabled() == null) newClient.setImplicitFlowEnabled(false);
    if (rep.isPublicClient() == null) newClient.setPublicClient(true);
    if (rep.isFrontchannelLogout() == null) newClient.setFrontchannelLogout(false);
}
 
Example 6
Source File: TrustedHostClientRegistrationPolicy.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected void verifyClientUrls(ClientRegistrationContext context) throws ClientRegistrationPolicyException {
    boolean redirectUriMustMatch = isClientUrisMustMatch();
    if (!redirectUriMustMatch) {
        return;
    }

    List<String> trustedHosts = getTrustedHosts();
    List<String> trustedDomains = getTrustedDomains();

    ClientRepresentation client = context.getClient();
    String rootUrl = client.getRootUrl();
    String baseUrl = client.getBaseUrl();
    String adminUrl = client.getAdminUrl();
    List<String> redirectUris = client.getRedirectUris();

    baseUrl = relativeToAbsoluteURI(rootUrl, baseUrl);
    adminUrl = relativeToAbsoluteURI(rootUrl, adminUrl);
    Set<String> resolvedRedirects = PairwiseSubMapperUtils.resolveValidRedirectUris(rootUrl, redirectUris);

    if (rootUrl != null) {
        checkURLTrusted(rootUrl, trustedHosts, trustedDomains);
    }

    if (baseUrl != null) {
        checkURLTrusted(baseUrl, trustedHosts, trustedDomains);
    }
    if (adminUrl != null) {
        checkURLTrusted(adminUrl, trustedHosts, trustedDomains);
    }
    for (String redirect : resolvedRedirects) {
        checkURLTrusted(redirect, trustedHosts, trustedDomains);
    }

}