Add domain ownership info

This commit is contained in:
Melon 2023-10-27 09:40:10 +01:00
parent 6f16ea6690
commit 8a364b59ac
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
3 changed files with 30 additions and 2 deletions

View File

@ -12,6 +12,7 @@ type Conf struct {
Issuer string `json:"issuer"` Issuer string `json:"issuer"`
SsoServices []issuer.SsoConfig `json:"sso_services"` SsoServices []issuer.SsoConfig `json:"sso_services"`
AllowedClients []AllowedClient `json:"allowed_clients"` AllowedClients []AllowedClient `json:"allowed_clients"`
Ownership DomainOwnership `json:"ownership"`
} }
type AllowedClient struct { type AllowedClient struct {

View File

@ -129,13 +129,16 @@ func (h *HttpServer) flowCallback(rw http.ResponseWriter, req *http.Request, _ h
return return
} }
var needsMailFlag bool var needsMailFlag, needsDomains bool
ps := claims.NewPermStorage() ps := claims.NewPermStorage()
for _, i := range v.target.Permissions { for _, i := range v.target.Permissions {
if strings.HasPrefix(i, "dynamic:") { if strings.HasPrefix(i, "dynamic:") {
if i == "dynamic:mail-client" { switch i {
case "dynamic:mail-client":
needsMailFlag = true needsMailFlag = true
case "dynamic:domain-owns":
needsDomains = true
} }
} else { } else {
ps.Set(i) ps.Set(i)
@ -162,6 +165,13 @@ func (h *HttpServer) flowCallback(rw http.ResponseWriter, req *http.Request, _ h
} }
} }
if needsDomains {
a := h.conf.Ownership.AllOwns(sub + "@" + v.sso.Config.Namespace)
for _, i := range a {
ps.Set("domain:owns=" + i)
}
}
noEmailSupport: noEmailSupport:
nsSub := sub + "@" + v.sso.Config.Namespace nsSub := sub + "@" + v.sso.Config.Namespace
ati := uuidNewStringAti() ati := uuidNewStringAti()

17
server/owners.go Normal file
View File

@ -0,0 +1,17 @@
package server
// DomainOwnership is the structure for storing if a user owns a domain
type DomainOwnership map[string][]string
func (d DomainOwnership) AllOwns(user string) []string {
return d[user]
}
func (d DomainOwnership) Owns(user, domain string) bool {
for _, i := range d[user] {
if i == domain {
return true
}
}
return false
}