1. Packages
  2. Keycloak
  3. API Docs
  4. ldap
  5. HardcodedGroupMapper
Keycloak v5.3.1 published on Monday, Mar 11, 2024 by Pulumi

keycloak.ldap.HardcodedGroupMapper

Explore with Pulumi AI

keycloak logo
Keycloak v5.3.1 published on Monday, Mar 11, 2024 by Pulumi

    Allows for creating and managing hardcoded group mappers for Keycloak users federated via LDAP.

    The LDAP hardcoded group mapper will grant a specified Keycloak group to each Keycloak user linked with LDAP.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as keycloak from "@pulumi/keycloak";
    
    const realm = new keycloak.Realm("realm", {
        realm: "my-realm",
        enabled: true,
    });
    const ldapUserFederation = new keycloak.ldap.UserFederation("ldapUserFederation", {
        realmId: realm.id,
        usernameLdapAttribute: "cn",
        rdnLdapAttribute: "cn",
        uuidLdapAttribute: "entryDN",
        userObjectClasses: [
            "simpleSecurityObject",
            "organizationalRole",
        ],
        connectionUrl: "ldap://openldap",
        usersDn: "dc=example,dc=org",
        bindDn: "cn=admin,dc=example,dc=org",
        bindCredential: "admin",
    });
    const realmGroup = new keycloak.Group("realmGroup", {realmId: realm.id});
    const assignGroupToUsers = new keycloak.ldap.HardcodedGroupMapper("assignGroupToUsers", {
        realmId: realm.id,
        ldapUserFederationId: ldapUserFederation.id,
        group: realmGroup.name,
    });
    
    import pulumi
    import pulumi_keycloak as keycloak
    
    realm = keycloak.Realm("realm",
        realm="my-realm",
        enabled=True)
    ldap_user_federation = keycloak.ldap.UserFederation("ldapUserFederation",
        realm_id=realm.id,
        username_ldap_attribute="cn",
        rdn_ldap_attribute="cn",
        uuid_ldap_attribute="entryDN",
        user_object_classes=[
            "simpleSecurityObject",
            "organizationalRole",
        ],
        connection_url="ldap://openldap",
        users_dn="dc=example,dc=org",
        bind_dn="cn=admin,dc=example,dc=org",
        bind_credential="admin")
    realm_group = keycloak.Group("realmGroup", realm_id=realm.id)
    assign_group_to_users = keycloak.ldap.HardcodedGroupMapper("assignGroupToUsers",
        realm_id=realm.id,
        ldap_user_federation_id=ldap_user_federation.id,
        group=realm_group.name)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak"
    	"github.com/pulumi/pulumi-keycloak/sdk/v5/go/keycloak/ldap"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		realm, err := keycloak.NewRealm(ctx, "realm", &keycloak.RealmArgs{
    			Realm:   pulumi.String("my-realm"),
    			Enabled: pulumi.Bool(true),
    		})
    		if err != nil {
    			return err
    		}
    		ldapUserFederation, err := ldap.NewUserFederation(ctx, "ldapUserFederation", &ldap.UserFederationArgs{
    			RealmId:               realm.ID(),
    			UsernameLdapAttribute: pulumi.String("cn"),
    			RdnLdapAttribute:      pulumi.String("cn"),
    			UuidLdapAttribute:     pulumi.String("entryDN"),
    			UserObjectClasses: pulumi.StringArray{
    				pulumi.String("simpleSecurityObject"),
    				pulumi.String("organizationalRole"),
    			},
    			ConnectionUrl:  pulumi.String("ldap://openldap"),
    			UsersDn:        pulumi.String("dc=example,dc=org"),
    			BindDn:         pulumi.String("cn=admin,dc=example,dc=org"),
    			BindCredential: pulumi.String("admin"),
    		})
    		if err != nil {
    			return err
    		}
    		realmGroup, err := keycloak.NewGroup(ctx, "realmGroup", &keycloak.GroupArgs{
    			RealmId: realm.ID(),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = ldap.NewHardcodedGroupMapper(ctx, "assignGroupToUsers", &ldap.HardcodedGroupMapperArgs{
    			RealmId:              realm.ID(),
    			LdapUserFederationId: ldapUserFederation.ID(),
    			Group:                realmGroup.Name,
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Keycloak = Pulumi.Keycloak;
    
    return await Deployment.RunAsync(() => 
    {
        var realm = new Keycloak.Realm("realm", new()
        {
            RealmName = "my-realm",
            Enabled = true,
        });
    
        var ldapUserFederation = new Keycloak.Ldap.UserFederation("ldapUserFederation", new()
        {
            RealmId = realm.Id,
            UsernameLdapAttribute = "cn",
            RdnLdapAttribute = "cn",
            UuidLdapAttribute = "entryDN",
            UserObjectClasses = new[]
            {
                "simpleSecurityObject",
                "organizationalRole",
            },
            ConnectionUrl = "ldap://openldap",
            UsersDn = "dc=example,dc=org",
            BindDn = "cn=admin,dc=example,dc=org",
            BindCredential = "admin",
        });
    
        var realmGroup = new Keycloak.Group("realmGroup", new()
        {
            RealmId = realm.Id,
        });
    
        var assignGroupToUsers = new Keycloak.Ldap.HardcodedGroupMapper("assignGroupToUsers", new()
        {
            RealmId = realm.Id,
            LdapUserFederationId = ldapUserFederation.Id,
            Group = realmGroup.Name,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.keycloak.Realm;
    import com.pulumi.keycloak.RealmArgs;
    import com.pulumi.keycloak.ldap.UserFederation;
    import com.pulumi.keycloak.ldap.UserFederationArgs;
    import com.pulumi.keycloak.Group;
    import com.pulumi.keycloak.GroupArgs;
    import com.pulumi.keycloak.ldap.HardcodedGroupMapper;
    import com.pulumi.keycloak.ldap.HardcodedGroupMapperArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var realm = new Realm("realm", RealmArgs.builder()        
                .realm("my-realm")
                .enabled(true)
                .build());
    
            var ldapUserFederation = new UserFederation("ldapUserFederation", UserFederationArgs.builder()        
                .realmId(realm.id())
                .usernameLdapAttribute("cn")
                .rdnLdapAttribute("cn")
                .uuidLdapAttribute("entryDN")
                .userObjectClasses(            
                    "simpleSecurityObject",
                    "organizationalRole")
                .connectionUrl("ldap://openldap")
                .usersDn("dc=example,dc=org")
                .bindDn("cn=admin,dc=example,dc=org")
                .bindCredential("admin")
                .build());
    
            var realmGroup = new Group("realmGroup", GroupArgs.builder()        
                .realmId(realm.id())
                .build());
    
            var assignGroupToUsers = new HardcodedGroupMapper("assignGroupToUsers", HardcodedGroupMapperArgs.builder()        
                .realmId(realm.id())
                .ldapUserFederationId(ldapUserFederation.id())
                .group(realmGroup.name())
                .build());
    
        }
    }
    
    resources:
      realm:
        type: keycloak:Realm
        properties:
          realm: my-realm
          enabled: true
      ldapUserFederation:
        type: keycloak:ldap:UserFederation
        properties:
          realmId: ${realm.id}
          usernameLdapAttribute: cn
          rdnLdapAttribute: cn
          uuidLdapAttribute: entryDN
          userObjectClasses:
            - simpleSecurityObject
            - organizationalRole
          connectionUrl: ldap://openldap
          usersDn: dc=example,dc=org
          bindDn: cn=admin,dc=example,dc=org
          bindCredential: admin
      realmGroup:
        type: keycloak:Group
        properties:
          realmId: ${realm.id}
      assignGroupToUsers:
        type: keycloak:ldap:HardcodedGroupMapper
        properties:
          realmId: ${realm.id}
          ldapUserFederationId: ${ldapUserFederation.id}
          group: ${realmGroup.name}
    

    Create HardcodedGroupMapper Resource

    new HardcodedGroupMapper(name: string, args: HardcodedGroupMapperArgs, opts?: CustomResourceOptions);
    @overload
    def HardcodedGroupMapper(resource_name: str,
                             opts: Optional[ResourceOptions] = None,
                             group: Optional[str] = None,
                             ldap_user_federation_id: Optional[str] = None,
                             name: Optional[str] = None,
                             realm_id: Optional[str] = None)
    @overload
    def HardcodedGroupMapper(resource_name: str,
                             args: HardcodedGroupMapperArgs,
                             opts: Optional[ResourceOptions] = None)
    func NewHardcodedGroupMapper(ctx *Context, name string, args HardcodedGroupMapperArgs, opts ...ResourceOption) (*HardcodedGroupMapper, error)
    public HardcodedGroupMapper(string name, HardcodedGroupMapperArgs args, CustomResourceOptions? opts = null)
    public HardcodedGroupMapper(String name, HardcodedGroupMapperArgs args)
    public HardcodedGroupMapper(String name, HardcodedGroupMapperArgs args, CustomResourceOptions options)
    
    type: keycloak:ldap:HardcodedGroupMapper
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    name string
    The unique name of the resource.
    args HardcodedGroupMapperArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args HardcodedGroupMapperArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args HardcodedGroupMapperArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args HardcodedGroupMapperArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args HardcodedGroupMapperArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    HardcodedGroupMapper Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    The HardcodedGroupMapper resource accepts the following input properties:

    Group string
    The name of the group which should be assigned to the users.
    LdapUserFederationId string
    The ID of the LDAP user federation provider to attach this mapper to.
    RealmId string
    The realm that this LDAP mapper will exist in.
    Name string
    Display name of this mapper when displayed in the console.
    Group string
    The name of the group which should be assigned to the users.
    LdapUserFederationId string
    The ID of the LDAP user federation provider to attach this mapper to.
    RealmId string
    The realm that this LDAP mapper will exist in.
    Name string
    Display name of this mapper when displayed in the console.
    group String
    The name of the group which should be assigned to the users.
    ldapUserFederationId String
    The ID of the LDAP user federation provider to attach this mapper to.
    realmId String
    The realm that this LDAP mapper will exist in.
    name String
    Display name of this mapper when displayed in the console.
    group string
    The name of the group which should be assigned to the users.
    ldapUserFederationId string
    The ID of the LDAP user federation provider to attach this mapper to.
    realmId string
    The realm that this LDAP mapper will exist in.
    name string
    Display name of this mapper when displayed in the console.
    group str
    The name of the group which should be assigned to the users.
    ldap_user_federation_id str
    The ID of the LDAP user federation provider to attach this mapper to.
    realm_id str
    The realm that this LDAP mapper will exist in.
    name str
    Display name of this mapper when displayed in the console.
    group String
    The name of the group which should be assigned to the users.
    ldapUserFederationId String
    The ID of the LDAP user federation provider to attach this mapper to.
    realmId String
    The realm that this LDAP mapper will exist in.
    name String
    Display name of this mapper when displayed in the console.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the HardcodedGroupMapper resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing HardcodedGroupMapper Resource

    Get an existing HardcodedGroupMapper resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: HardcodedGroupMapperState, opts?: CustomResourceOptions): HardcodedGroupMapper
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            group: Optional[str] = None,
            ldap_user_federation_id: Optional[str] = None,
            name: Optional[str] = None,
            realm_id: Optional[str] = None) -> HardcodedGroupMapper
    func GetHardcodedGroupMapper(ctx *Context, name string, id IDInput, state *HardcodedGroupMapperState, opts ...ResourceOption) (*HardcodedGroupMapper, error)
    public static HardcodedGroupMapper Get(string name, Input<string> id, HardcodedGroupMapperState? state, CustomResourceOptions? opts = null)
    public static HardcodedGroupMapper get(String name, Output<String> id, HardcodedGroupMapperState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Group string
    The name of the group which should be assigned to the users.
    LdapUserFederationId string
    The ID of the LDAP user federation provider to attach this mapper to.
    Name string
    Display name of this mapper when displayed in the console.
    RealmId string
    The realm that this LDAP mapper will exist in.
    Group string
    The name of the group which should be assigned to the users.
    LdapUserFederationId string
    The ID of the LDAP user federation provider to attach this mapper to.
    Name string
    Display name of this mapper when displayed in the console.
    RealmId string
    The realm that this LDAP mapper will exist in.
    group String
    The name of the group which should be assigned to the users.
    ldapUserFederationId String
    The ID of the LDAP user federation provider to attach this mapper to.
    name String
    Display name of this mapper when displayed in the console.
    realmId String
    The realm that this LDAP mapper will exist in.
    group string
    The name of the group which should be assigned to the users.
    ldapUserFederationId string
    The ID of the LDAP user federation provider to attach this mapper to.
    name string
    Display name of this mapper when displayed in the console.
    realmId string
    The realm that this LDAP mapper will exist in.
    group str
    The name of the group which should be assigned to the users.
    ldap_user_federation_id str
    The ID of the LDAP user federation provider to attach this mapper to.
    name str
    Display name of this mapper when displayed in the console.
    realm_id str
    The realm that this LDAP mapper will exist in.
    group String
    The name of the group which should be assigned to the users.
    ldapUserFederationId String
    The ID of the LDAP user federation provider to attach this mapper to.
    name String
    Display name of this mapper when displayed in the console.
    realmId String
    The realm that this LDAP mapper will exist in.

    Import

    LDAP mappers can be imported using the format {{realm_id}}/{{ldap_user_federation_id}}/{{ldap_mapper_id}}.

    The ID of the LDAP user federation provider and the mapper can be found within the Keycloak GUI, and they are typically GUIDs.

    Example:

    bash

    $ pulumi import keycloak:ldap/hardcodedGroupMapper:HardcodedGroupMapper assign_group_to_users my-realm/af2a6ca3-e4d7-49c3-b08b-1b3c70b4b860/3d923ece-1a91-4bf7-adaf-3b82f2a12b67
    

    Package Details

    Repository
    Keycloak pulumi/pulumi-keycloak
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the keycloak Terraform Provider.
    keycloak logo
    Keycloak v5.3.1 published on Monday, Mar 11, 2024 by Pulumi