MCPcopy
hub / github.com/apache/casbin / registerDomainMatchingFunc

Method registerDomainMatchingFunc

enforcer.go:567–581  ·  view source on GitHub ↗

registerDomainMatchingFunc registers domain matching function if the matcher uses keyMatch for domains.

(ptype string)

Source from the content-addressed store, hash-verified

565
566// registerDomainMatchingFunc registers domain matching function if the matcher uses keyMatch for domains.
567func (e *Enforcer) registerDomainMatchingFunc(ptype string) {
568 // Dynamically detect the domain token name from the model definition.
569 // In RBAC with domains, the domain is typically the second parameter (index 1)
570 // in both request and policy definitions (e.g., r = sub, dom, obj, act).
571 // We extract the actual token names to support arbitrary domain parameter names.
572 rDomainToken, pDomainToken := e.getDomainTokens()
573 if rDomainToken == "" || pDomainToken == "" {
574 return
575 }
576
577 matchFun := fmt.Sprintf("keyMatch(%s, %s)", rDomainToken, pDomainToken)
578 if strings.Contains(e.model["m"]["m"].Value, matchFun) {
579 e.AddNamedDomainMatchingFunc(ptype, "g", util.KeyMatch)
580 }
581}
582
583func (e *Enforcer) initRmMap() {
584 for ptype, assertion := range e.model["g"] {

Callers 1

initRmMapMethod · 0.95

Calls 2

getDomainTokensMethod · 0.95

Tested by

no test coverage detected