Skip to content

Commit

Permalink
Merge pull request #127 from LalitDeore/admin2
Browse files Browse the repository at this point in the history
fix autoprovisining of users
  • Loading branch information
frikky authored Dec 20, 2024
2 parents 15ad3b3 + 092c297 commit 23112a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -11806,6 +11806,10 @@ func HandleEditOrg(resp http.ResponseWriter, request *http.Request) {
org.SSOConfig = tmpData.SSOConfig
}

if tmpData.SSOConfig.AutoProvision != org.SSOConfig.AutoProvision {
org.SSOConfig.AutoProvision = tmpData.SSOConfig.AutoProvision
}

if (tmpData.SSOConfig.OpenIdClientId != org.SSOConfig.OpenIdClientId) || (tmpData.SSOConfig.OpenIdAuthorization != org.SSOConfig.OpenIdAuthorization) {
org.SSOConfig = tmpData.SSOConfig
}
Expand Down Expand Up @@ -19327,6 +19331,14 @@ func HandleOpenId(resp http.ResponseWriter, request *http.Request) {
return
}

//Don't create user if auto-provisioning is disabled
if org.SSOConfig.AutoProvision {
log.Printf("[INFO] Auto-provisioning is disable for id: %s", org.Id)
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Auto-provisioning is disabled for this organization. Please ask your administrator to enable it."}`)))
return
}

log.Printf("[AUDIT] Adding user %s to org %s (%s) through single sign-on", userName, org.Name, org.Id)
newUser := new(User)
// Random password to ensure its not empty
Expand Down Expand Up @@ -19856,6 +19868,14 @@ func HandleSSO(resp http.ResponseWriter, request *http.Request) {
return
}

//Don't create user if auto-provisioning is disabled
if foundOrg.SSOConfig.AutoProvision {
log.Printf("[INFO] Auto-provisioning is disable for id: %s", foundOrg.Id)
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Auto-provisioning is disabled for this organization. Please ask your administrator to enable it."}`)))
return
}

log.Printf("[AUDIT] Adding user %s to org %s (%s) through single sign-on", userName, foundOrg.Name, foundOrg.Id)
newUser := new(User)
// Random password to ensure its not empty
Expand Down
1 change: 1 addition & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2739,6 +2739,7 @@ type SSOConfig struct {
OpenIdAuthorization string `json:"openid_authorization" datastore:"openid_authorization"`
OpenIdToken string `json:"openid_token" datastore:"openid_token"`
SSORequired bool `json:"SSORequired" datastore:"SSORequired"`
AutoProvision bool `json:"auto_provision" datastore:"auto_provision"`
}

type SamlRequest struct {
Expand Down

0 comments on commit 23112a0

Please sign in to comment.