keycloak.ldap.CustomMapper
Explore with Pulumi AI
Allows for creating and managing custom attribute mappers for Keycloak users federated via LDAP.
The LDAP custom mapper is implemented and deployed into Keycloak as a custom provider. This resource allows to specify the custom id and custom implementation class of the self-implemented attribute mapper as well as additional properties via config map.
The custom mapper should already be deployed into keycloak in order to be correctly configured.
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("ldap_user_federation", {
name: "openldap",
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 customMapper = new keycloak.ldap.CustomMapper("custom_mapper", {
name: "custom-mapper",
realmId: openldap.realmId,
ldapUserFederationId: openldap.id,
providerId: "custom-provider-registered-in-keycloak",
providerType: "com.example.custom.ldap.mappers.CustomMapper",
config: {
"attribute.name": "name",
"attribute.value": "value",
},
});
import pulumi
import pulumi_keycloak as keycloak
realm = keycloak.Realm("realm",
realm="my-realm",
enabled=True)
ldap_user_federation = keycloak.ldap.UserFederation("ldap_user_federation",
name="openldap",
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")
custom_mapper = keycloak.ldap.CustomMapper("custom_mapper",
name="custom-mapper",
realm_id=openldap["realmId"],
ldap_user_federation_id=openldap["id"],
provider_id="custom-provider-registered-in-keycloak",
provider_type="com.example.custom.ldap.mappers.CustomMapper",
config={
"attribute.name": "name",
"attribute.value": "value",
})
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
}
_, err = ldap.NewUserFederation(ctx, "ldap_user_federation", &ldap.UserFederationArgs{
Name: pulumi.String("openldap"),
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
}
_, err = ldap.NewCustomMapper(ctx, "custom_mapper", &ldap.CustomMapperArgs{
Name: pulumi.String("custom-mapper"),
RealmId: pulumi.Any(openldap.RealmId),
LdapUserFederationId: pulumi.Any(openldap.Id),
ProviderId: pulumi.String("custom-provider-registered-in-keycloak"),
ProviderType: pulumi.String("com.example.custom.ldap.mappers.CustomMapper"),
Config: pulumi.StringMap{
"attribute.name": pulumi.String("name"),
"attribute.value": pulumi.String("value"),
},
})
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("ldap_user_federation", new()
{
Name = "openldap",
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 customMapper = new Keycloak.Ldap.CustomMapper("custom_mapper", new()
{
Name = "custom-mapper",
RealmId = openldap.RealmId,
LdapUserFederationId = openldap.Id,
ProviderId = "custom-provider-registered-in-keycloak",
ProviderType = "com.example.custom.ldap.mappers.CustomMapper",
Config =
{
{ "attribute.name", "name" },
{ "attribute.value", "value" },
},
});
});
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.ldap.CustomMapper;
import com.pulumi.keycloak.ldap.CustomMapperArgs;
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()
.name("openldap")
.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 customMapper = new CustomMapper("customMapper", CustomMapperArgs.builder()
.name("custom-mapper")
.realmId(openldap.realmId())
.ldapUserFederationId(openldap.id())
.providerId("custom-provider-registered-in-keycloak")
.providerType("com.example.custom.ldap.mappers.CustomMapper")
.config(Map.ofEntries(
Map.entry("attribute.name", "name"),
Map.entry("attribute.value", "value")
))
.build());
}
}
resources:
realm:
type: keycloak:Realm
properties:
realm: my-realm
enabled: true
ldapUserFederation:
type: keycloak:ldap:UserFederation
name: ldap_user_federation
properties:
name: openldap
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
customMapper:
type: keycloak:ldap:CustomMapper
name: custom_mapper
properties:
name: custom-mapper
realmId: ${openldap.realmId}
ldapUserFederationId: ${openldap.id}
providerId: custom-provider-registered-in-keycloak
providerType: com.example.custom.ldap.mappers.CustomMapper
config:
attribute.name: name
attribute.value: value
Create CustomMapper Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new CustomMapper(name: string, args: CustomMapperArgs, opts?: CustomResourceOptions);
@overload
def CustomMapper(resource_name: str,
args: CustomMapperArgs,
opts: Optional[ResourceOptions] = None)
@overload
def CustomMapper(resource_name: str,
opts: Optional[ResourceOptions] = None,
ldap_user_federation_id: Optional[str] = None,
provider_id: Optional[str] = None,
provider_type: Optional[str] = None,
realm_id: Optional[str] = None,
config: Optional[Mapping[str, str]] = None,
name: Optional[str] = None)
func NewCustomMapper(ctx *Context, name string, args CustomMapperArgs, opts ...ResourceOption) (*CustomMapper, error)
public CustomMapper(string name, CustomMapperArgs args, CustomResourceOptions? opts = null)
public CustomMapper(String name, CustomMapperArgs args)
public CustomMapper(String name, CustomMapperArgs args, CustomResourceOptions options)
type: keycloak:ldap:CustomMapper
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args CustomMapperArgs
- 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 CustomMapperArgs
- 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 CustomMapperArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args CustomMapperArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args CustomMapperArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var customMapperResource = new Keycloak.Ldap.CustomMapper("customMapperResource", new()
{
LdapUserFederationId = "string",
ProviderId = "string",
ProviderType = "string",
RealmId = "string",
Config =
{
{ "string", "string" },
},
Name = "string",
});
example, err := ldap.NewCustomMapper(ctx, "customMapperResource", &ldap.CustomMapperArgs{
LdapUserFederationId: pulumi.String("string"),
ProviderId: pulumi.String("string"),
ProviderType: pulumi.String("string"),
RealmId: pulumi.String("string"),
Config: pulumi.StringMap{
"string": pulumi.String("string"),
},
Name: pulumi.String("string"),
})
var customMapperResource = new CustomMapper("customMapperResource", CustomMapperArgs.builder()
.ldapUserFederationId("string")
.providerId("string")
.providerType("string")
.realmId("string")
.config(Map.of("string", "string"))
.name("string")
.build());
custom_mapper_resource = keycloak.ldap.CustomMapper("customMapperResource",
ldap_user_federation_id="string",
provider_id="string",
provider_type="string",
realm_id="string",
config={
"string": "string",
},
name="string")
const customMapperResource = new keycloak.ldap.CustomMapper("customMapperResource", {
ldapUserFederationId: "string",
providerId: "string",
providerType: "string",
realmId: "string",
config: {
string: "string",
},
name: "string",
});
type: keycloak:ldap:CustomMapper
properties:
config:
string: string
ldapUserFederationId: string
name: string
providerId: string
providerType: string
realmId: string
CustomMapper 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 CustomMapper resource accepts the following input properties:
- Ldap
User stringFederation Id - The ID of the LDAP user federation provider to attach this mapper to.
- Provider
Id string - The id of the LDAP mapper implemented in MapperFactory.
- Provider
Type string - The fully-qualified Java class name of the custom LDAP mapper.
- Realm
Id string - The realm that this LDAP mapper will exist in.
- Config Dictionary<string, string>
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- Name string
- Display name of this mapper when displayed in the console.
- Ldap
User stringFederation Id - The ID of the LDAP user federation provider to attach this mapper to.
- Provider
Id string - The id of the LDAP mapper implemented in MapperFactory.
- Provider
Type string - The fully-qualified Java class name of the custom LDAP mapper.
- Realm
Id string - The realm that this LDAP mapper will exist in.
- Config map[string]string
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- Name string
- Display name of this mapper when displayed in the console.
- ldap
User StringFederation Id - The ID of the LDAP user federation provider to attach this mapper to.
- provider
Id String - The id of the LDAP mapper implemented in MapperFactory.
- provider
Type String - The fully-qualified Java class name of the custom LDAP mapper.
- realm
Id String - The realm that this LDAP mapper will exist in.
- config Map<String,String>
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- name String
- Display name of this mapper when displayed in the console.
- ldap
User stringFederation Id - The ID of the LDAP user federation provider to attach this mapper to.
- provider
Id string - The id of the LDAP mapper implemented in MapperFactory.
- provider
Type string - The fully-qualified Java class name of the custom LDAP mapper.
- realm
Id string - The realm that this LDAP mapper will exist in.
- config {[key: string]: string}
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- name string
- Display name of this mapper when displayed in the console.
- ldap_
user_ strfederation_ id - The ID of the LDAP user federation provider to attach this mapper to.
- provider_
id str - The id of the LDAP mapper implemented in MapperFactory.
- provider_
type str - The fully-qualified Java class name of the custom LDAP mapper.
- realm_
id str - The realm that this LDAP mapper will exist in.
- config Mapping[str, str]
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- name str
- Display name of this mapper when displayed in the console.
- ldap
User StringFederation Id - The ID of the LDAP user federation provider to attach this mapper to.
- provider
Id String - The id of the LDAP mapper implemented in MapperFactory.
- provider
Type String - The fully-qualified Java class name of the custom LDAP mapper.
- realm
Id String - The realm that this LDAP mapper will exist in.
- config Map<String>
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- name String
- Display name of this mapper when displayed in the console.
Outputs
All input properties are implicitly available as output properties. Additionally, the CustomMapper 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 CustomMapper Resource
Get an existing CustomMapper 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?: CustomMapperState, opts?: CustomResourceOptions): CustomMapper
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
config: Optional[Mapping[str, str]] = None,
ldap_user_federation_id: Optional[str] = None,
name: Optional[str] = None,
provider_id: Optional[str] = None,
provider_type: Optional[str] = None,
realm_id: Optional[str] = None) -> CustomMapper
func GetCustomMapper(ctx *Context, name string, id IDInput, state *CustomMapperState, opts ...ResourceOption) (*CustomMapper, error)
public static CustomMapper Get(string name, Input<string> id, CustomMapperState? state, CustomResourceOptions? opts = null)
public static CustomMapper get(String name, Output<String> id, CustomMapperState 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.
- Config Dictionary<string, string>
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- Ldap
User stringFederation Id - 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.
- Provider
Id string - The id of the LDAP mapper implemented in MapperFactory.
- Provider
Type string - The fully-qualified Java class name of the custom LDAP mapper.
- Realm
Id string - The realm that this LDAP mapper will exist in.
- Config map[string]string
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- Ldap
User stringFederation Id - 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.
- Provider
Id string - The id of the LDAP mapper implemented in MapperFactory.
- Provider
Type string - The fully-qualified Java class name of the custom LDAP mapper.
- Realm
Id string - The realm that this LDAP mapper will exist in.
- config Map<String,String>
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- ldap
User StringFederation Id - 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.
- provider
Id String - The id of the LDAP mapper implemented in MapperFactory.
- provider
Type String - The fully-qualified Java class name of the custom LDAP mapper.
- realm
Id String - The realm that this LDAP mapper will exist in.
- config {[key: string]: string}
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- ldap
User stringFederation Id - 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.
- provider
Id string - The id of the LDAP mapper implemented in MapperFactory.
- provider
Type string - The fully-qualified Java class name of the custom LDAP mapper.
- realm
Id string - The realm that this LDAP mapper will exist in.
- config Mapping[str, str]
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- ldap_
user_ strfederation_ id - 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.
- provider_
id str - The id of the LDAP mapper implemented in MapperFactory.
- provider_
type str - The fully-qualified Java class name of the custom LDAP mapper.
- realm_
id str - The realm that this LDAP mapper will exist in.
- config Map<String>
- A map with key / value pairs for configuring the LDAP mapper. The supported keys depend on the protocol mapper.
- ldap
User StringFederation Id - 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.
- provider
Id String - The id of the LDAP mapper implemented in MapperFactory.
- provider
Type String - The fully-qualified Java class name of the custom LDAP mapper.
- realm
Id 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/customMapper:CustomMapper custom_mapper my-realm/af2a6ca3-e4d7-49c3-b08b-1b3c70b4b860/3d923ece-1a91-4bf7-adaf-3b82f2a12b67
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- Keycloak pulumi/pulumi-keycloak
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
keycloak
Terraform Provider.