Skip to content

Commit 605d3a6

Browse files
committed
[feature] - restrict user if roles are missing in sso response
1 parent 93ded5e commit 605d3a6

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

shared.go

+56-1
Original file line numberDiff line numberDiff line change
@@ -11764,7 +11764,7 @@ func HandleEditOrg(resp http.ResponseWriter, request *http.Request) {
1176411764
org.SSOConfig = tmpData.SSOConfig
1176511765
}
1176611766

11767-
if (tmpData.SSOConfig.OpenIdClientId != org.SSOConfig.OpenIdClientId) || (tmpData.SSOConfig.OpenIdAuthorization != org.SSOConfig.OpenIdAuthorization) {
11767+
if (tmpData.SSOConfig.OpenIdClientId != org.SSOConfig.OpenIdClientId) || (tmpData.SSOConfig.OpenIdAuthorization != org.SSOConfig.OpenIdAuthorization) || (tmpData.SSOConfig.RoleRequired != org.SSOConfig.RoleRequired) {
1176811768
org.SSOConfig = tmpData.SSOConfig
1176911769
}
1177011770

@@ -19923,6 +19923,25 @@ func HandleOpenId(resp http.ResponseWriter, request *http.Request) {
1992319923
log.Printf("[AUDIT] Found user %s (%s) which matches SSO info for %s. Redirecting to login! - (1)", user.Username, user.Id, userName)
1992419924
}
1992519925

19926+
// check whether role is required for org
19927+
19928+
if org.SSOConfig.RoleRequired {
19929+
foundRole := false
19930+
for _, role := range openidUser.Roles {
19931+
// check whether role matches with shuffle-admin, shuffle-user or shuffle-org-reader
19932+
if role == "shuffle-admin" || role == "shuffle-user" || role == "shuffle-org-reader" {
19933+
foundRole = true
19934+
}
19935+
}
19936+
19937+
if !foundRole {
19938+
log.Printf("[WARNING] User %s (%s) role is missing in respone for org %s (%s). Please contact the administrator - (1)", user.Username, user.Id, org.Name, org.Id)
19939+
resp.WriteHeader(401)
19940+
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Role detail is missing. Please contact the administrator of org."}`)))
19941+
return
19942+
}
19943+
}
19944+
1992619945
//log.Printf("SESSION: %s", user.Session)
1992719946
user.ActiveOrg = OrgMini{
1992819947
Name: org.Name,
@@ -20066,6 +20085,25 @@ func HandleOpenId(resp http.ResponseWriter, request *http.Request) {
2006620085
log.Printf("[AUDIT] Found user %s (%s) which matches SSO info for %s. Redirecting to login!- (2)", user.Username, user.Id, userName)
2006720086
}
2006820087
//log.Printf("SESSION: %s", user.Session)
20088+
20089+
// check whether role is required for org
20090+
if org.SSOConfig.RoleRequired {
20091+
foundRole := false
20092+
for _, role := range openidUser.Roles {
20093+
// check whether role matches with shuffle-admin, shuffle-user or shuffle-org-reader
20094+
if role == "shuffle-admin" || role == "shuffle-user" || role == "shuffle-org-reader" {
20095+
foundRole = true
20096+
}
20097+
}
20098+
20099+
if !foundRole {
20100+
log.Printf("[WARNING] User %s (%s) role is missing in respone for org %s (%s). Please contact the administrator - (1)", user.Username, user.Id, org.Name, org.Id)
20101+
resp.WriteHeader(401)
20102+
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Role detail is missing. Please contact the administrator of org."}`)))
20103+
return
20104+
}
20105+
}
20106+
2006920107
user.ActiveOrg = OrgMini{
2007020108
Name: org.Name,
2007120109
Id: org.Id,
@@ -20198,6 +20236,23 @@ func HandleOpenId(resp http.ResponseWriter, request *http.Request) {
2019820236
return
2019920237
}
2020020238

20239+
if org.SSOConfig.RoleRequired {
20240+
foundRole := false
20241+
for _, role := range openidUser.Roles {
20242+
// check whether role matches with shuffle-admin, shuffle-user or shuffle-org-reader
20243+
if role == "shuffle-admin" || role == "shuffle-user" || role == "shuffle-org-reader" {
20244+
foundRole = true
20245+
}
20246+
}
20247+
20248+
if !foundRole {
20249+
log.Printf("[WARNING] Role is missing in respone for username %s. Please contact the administrator - (3)", userName)
20250+
resp.WriteHeader(401)
20251+
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Role detail is missing. Please contact the administrator of org."}`)))
20252+
return
20253+
}
20254+
}
20255+
2020120256
// Assign default role as "user" for generated user, else assign the role from openid if available
2020220257
// Change active org role and user.role to assign role
2020320258
role := "user"

structs.go

+1
Original file line numberDiff line numberDiff line change
@@ -2777,6 +2777,7 @@ type SSOConfig struct {
27772777
OpenIdToken string `json:"openid_token" datastore:"openid_token"`
27782778
SSORequired bool `json:"SSORequired" datastore:"SSORequired"`
27792779
AutoProvision bool `json:"auto_provision" datastore:"auto_provision"`
2780+
RoleRequired bool `json:"role_required" datastore:"role_required"`
27802781
}
27812782

27822783
type SamlRequest struct {

0 commit comments

Comments
 (0)