Java Code Examples for org.keycloak.component.ComponentModel#put()

The following examples show how to use org.keycloak.component.ComponentModel#put() . 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: DefaultClientRegistrationPolicies.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private static void addAnonymousPolicies(RealmModel realm, String policyTypeKey) {
    ComponentModel trustedHostModel = createModelInstance("Trusted Hosts", realm, TrustedHostClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey);

    // Not any trusted hosts by default
    trustedHostModel.getConfig().put(TrustedHostClientRegistrationPolicyFactory.TRUSTED_HOSTS, Collections.emptyList());
    trustedHostModel.getConfig().putSingle(TrustedHostClientRegistrationPolicyFactory.HOST_SENDING_REGISTRATION_REQUEST_MUST_MATCH, "true");
    trustedHostModel.getConfig().putSingle(TrustedHostClientRegistrationPolicyFactory.CLIENT_URIS_MUST_MATCH, "true");
    realm.addComponentModel(trustedHostModel);

    ComponentModel consentRequiredModel = createModelInstance("Consent Required", realm, ConsentRequiredClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey);
    realm.addComponentModel(consentRequiredModel);

    ComponentModel scopeModel = createModelInstance("Full Scope Disabled", realm, ScopeClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey);
    realm.addComponentModel(scopeModel);

    ComponentModel maxClientsModel = createModelInstance("Max Clients Limit", realm, MaxClientsClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey);
    maxClientsModel.put(MaxClientsClientRegistrationPolicyFactory.MAX_CLIENTS, MaxClientsClientRegistrationPolicyFactory.DEFAULT_MAX_CLIENTS);
    realm.addComponentModel(maxClientsModel);

    addGenericPolicies(realm, policyTypeKey);
}
 
Example 2
Source File: DefaultClientRegistrationPolicies.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private static void addGenericPolicies(RealmModel realm, String policyTypeKey) {
    ComponentModel protMapperModel = createModelInstance("Allowed Protocol Mapper Types", realm, ProtocolMappersClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey);
    protMapperModel.getConfig().put(ProtocolMappersClientRegistrationPolicyFactory.ALLOWED_PROTOCOL_MAPPER_TYPES, Arrays.asList(DEFAULT_ALLOWED_PROTOCOL_MAPPERS));
    realm.addComponentModel(protMapperModel);

    ComponentModel clientTemplatesModel = createModelInstance("Allowed Client Scopes", realm, ClientScopesClientRegistrationPolicyFactory.PROVIDER_ID, policyTypeKey);
    clientTemplatesModel.getConfig().put(ClientScopesClientRegistrationPolicyFactory.ALLOWED_CLIENT_SCOPES, Collections.emptyList());
    clientTemplatesModel.put(ClientScopesClientRegistrationPolicyFactory.ALLOW_DEFAULT_SCOPES, true);
    realm.addComponentModel(clientTemplatesModel);
}
 
Example 3
Source File: AbstractGeneratedSecretKeyProviderFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void generateSecret(ComponentModel model, int size) {
    try {
        byte[] secret = KeycloakModelUtils.generateSecret(size);
        model.put(Attributes.SECRET_KEY, Base64Url.encode(secret));

        String kid = KeycloakModelUtils.generateId();
        model.put(Attributes.KID_KEY, kid);
    } catch (Throwable t) {
        throw new ComponentValidationException("Failed to generate secret", t);
    }
}
 
Example 4
Source File: GeneratedRsaKeyProviderFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void generateKeys(RealmModel realm, ComponentModel model, int size) {
    KeyPair keyPair;
    try {
        keyPair = KeyUtils.generateRsaKeyPair(size);
        model.put(Attributes.PRIVATE_KEY_KEY, PemUtils.encodeKey(keyPair.getPrivate()));
    } catch (Throwable t) {
        throw new ComponentValidationException("Failed to generate keys", t);
    }

    generateCertificate(realm, model, keyPair);
}
 
Example 5
Source File: GeneratedRsaKeyProviderFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void generateCertificate(RealmModel realm, ComponentModel model, KeyPair keyPair) {
    try {
        Certificate certificate = CertificateUtils.generateV1SelfSignedCertificate(keyPair, realm.getName());
        model.put(Attributes.CERTIFICATE_KEY, PemUtils.encodeCertificate(certificate));
    } catch (Throwable t) {
        throw new ComponentValidationException("Failed to generate certificate", t);
    }
}
 
Example 6
Source File: GeneratedEcdsaKeyProviderFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void generateKeys(ComponentModel model, String ecInNistRep) {
    KeyPair keyPair;
    try {
        keyPair = generateEcdsaKeyPair(convertECDomainParmNistRepToSecRep(ecInNistRep));
        model.put(ECDSA_PRIVATE_KEY_KEY, Base64.encodeBytes(keyPair.getPrivate().getEncoded()));
        model.put(ECDSA_PUBLIC_KEY_KEY, Base64.encodeBytes(keyPair.getPublic().getEncoded()));
        model.put(ECDSA_ELLIPTIC_CURVE_KEY, ecInNistRep);
    } catch (Throwable t) {
        throw new ComponentValidationException("Failed to generate ECDSA keys", t);
    }
}