Documentation
¶
Index ¶
- type LDAPConn
- type LDAPOptions
- type RoleManager
- func (rm *RoleManager) AddDomainMatchingFunc(name string, fn rbac.MatchingFunc)
- func (rm *RoleManager) AddLink(name1 string, name2 string, domain ...string) error
- func (rm *RoleManager) AddMatchingFunc(name string, fn rbac.MatchingFunc)
- func (rm *RoleManager) BuildRelationship(name1 string, name2 string, domain ...string) error
- func (rm *RoleManager) Clear() error
- func (rm *RoleManager) Close() error
- func (rm *RoleManager) DeleteDomain(domain string) error
- func (rm *RoleManager) DeleteLink(name1 string, name2 string, domain ...string) error
- func (rm *RoleManager) GetAllDomains() ([]string, error)
- func (rm *RoleManager) GetDomains(name string) ([]string, error)
- func (rm *RoleManager) GetImplicitRoles(name string, domain ...string) ([]string, error)
- func (rm *RoleManager) GetImplicitUsers(roleName string, domain ...string) ([]string, error)
- func (rm *RoleManager) GetRoles(name string, domain ...string) ([]string, error)
- func (rm *RoleManager) GetUsers(roleName string, domain ...string) ([]string, error)
- func (rm *RoleManager) HasLink(name1 string, name2 string, domain ...string) (bool, error)
- func (rm *RoleManager) Match(str string, pattern string) bool
- func (rm *RoleManager) PrintRoles() error
- func (rm *RoleManager) SetLogger(logger log.Logger)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LDAPConn ¶
type LDAPConn interface {
Search(searchRequest *ldap.SearchRequest) (*ldap.SearchResult, error)
Bind(username, password string) error
Close() error
}
LDAPConn defines the interface for LDAP operations.
type LDAPOptions ¶
type LDAPOptions struct {
// LDAP server URL (e.g., "ldap://localhost:389" or "ldaps://localhost:636")
URL string
// Base DN for searching (e.g., "dc=example,dc=com")
BaseDN string
// User filter template (e.g., "(uid=%s)")
UserFilter string
// Group filter template (e.g., "(member=%s)")
GroupFilter string
// Attribute containing role/group names (default: "cn")
RoleAttr string
// Bind DN for authentication
BindDN string
// Bind password
BindPassword string
// Use TLS
UseTLS bool
// Skip TLS verification
SkipTLSVerify bool
// Maximum hierarchy level for role inheritance (default: 10)
MaxHierarchyLevel int
}
LDAPOptions contains configuration options for LDAP connection.
type RoleManager ¶
type RoleManager struct {
// contains filtered or unexported fields
}
RoleManager implements the RoleManager interface for LDAP.
func NewRoleManager ¶
func NewRoleManager(opts *LDAPOptions) (*RoleManager, error)
NewRoleManager creates a new RoleManager instance with LDAP connection.
func (*RoleManager) AddDomainMatchingFunc ¶
func (rm *RoleManager) AddDomainMatchingFunc(name string, fn rbac.MatchingFunc)
AddDomainMatchingFunc adds the domain matching function.
func (*RoleManager) AddLink ¶
func (rm *RoleManager) AddLink(name1 string, name2 string, domain ...string) error
AddLink adds the inheritance link between role: name1 and role: name2. For LDAP role manager, this is a no-op as roles are managed in LDAP.
func (*RoleManager) AddMatchingFunc ¶
func (rm *RoleManager) AddMatchingFunc(name string, fn rbac.MatchingFunc)
AddMatchingFunc adds the matching function.
func (*RoleManager) BuildRelationship ¶
func (rm *RoleManager) BuildRelationship(name1 string, name2 string, domain ...string) error
BuildRelationship builds the relationship between role: name1 and role: name2. Deprecated: BuildRelationship is no longer required
func (*RoleManager) Clear ¶
func (rm *RoleManager) Clear() error
Clear clears all stored data and resets the role manager to the initial state.
func (*RoleManager) DeleteDomain ¶
func (rm *RoleManager) DeleteDomain(domain string) error
DeleteDomain deletes all data of a domain in the role manager.
func (*RoleManager) DeleteLink ¶
func (rm *RoleManager) DeleteLink(name1 string, name2 string, domain ...string) error
DeleteLink deletes the inheritance link between role: name1 and role: name2. For LDAP role manager, this is a no-op as roles are managed in LDAP.
func (*RoleManager) GetAllDomains ¶
func (rm *RoleManager) GetAllDomains() ([]string, error)
GetAllDomains gets all domains.
func (*RoleManager) GetDomains ¶
func (rm *RoleManager) GetDomains(name string) ([]string, error)
GetDomains gets domains that a user has.
func (*RoleManager) GetImplicitRoles ¶
func (rm *RoleManager) GetImplicitRoles(name string, domain ...string) ([]string, error)
GetImplicitRoles gets the implicit roles that a user inherits, respecting maxHierarchyLevel.
func (*RoleManager) GetImplicitUsers ¶
func (rm *RoleManager) GetImplicitUsers(roleName string, domain ...string) ([]string, error)
GetImplicitUsers gets the implicit users that inherits a role, respecting maxHierarchyLevel.
func (*RoleManager) GetRoles ¶
func (rm *RoleManager) GetRoles(name string, domain ...string) ([]string, error)
GetRoles gets the roles that a user inherits.
Example ¶
Example test demonstrating usage
// Note: This example requires a running LDAP server
opts := &LDAPOptions{
URL: "ldap://localhost:389",
BaseDN: "dc=example,dc=com",
UserFilter: "(uid=%s)",
GroupFilter: "(member=%s)",
RoleAttr: "cn",
BindDN: "cn=admin,dc=example,dc=com",
BindPassword: "password",
MaxHierarchyLevel: 10,
}
rm, err := NewRoleManager(opts)
if err != nil {
fmt.Printf("Failed to create role manager: %v\n", err)
return
}
defer rm.Close()
roles, err := rm.GetRoles("alice")
if err != nil {
fmt.Printf("Failed to get roles: %v\n", err)
return
}
fmt.Printf("Roles for alice: %v\n", roles)
func (*RoleManager) GetUsers ¶
func (rm *RoleManager) GetUsers(roleName string, domain ...string) ([]string, error)
GetUsers gets the users that inherits a role.
func (*RoleManager) Match ¶
func (rm *RoleManager) Match(str string, pattern string) bool
Match matches the domain with the pattern.
func (*RoleManager) PrintRoles ¶
func (rm *RoleManager) PrintRoles() error
PrintRoles prints all the roles to log.
func (*RoleManager) SetLogger ¶
func (rm *RoleManager) SetLogger(logger log.Logger)
SetLogger sets role manager's logger.