Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
backoffice_server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
Factory
LLLE_Project
backoffice_server
Commits
97020c65
Commit
97020c65
authored
3 years ago
by
Rémi PAILHAREY
Browse files
Options
Downloads
Patches
Plain Diff
feat(oauth2): check if the connected user has the correct role
parent
6eb63808
No related branches found
Branches containing commit
No related tags found
3 merge requests
!14
feat: addprices + subject managment
,
!11
feat: Add partners issue info
,
!8
Feat/filter user group
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
internal/auth/oauth2.go
+12
-0
12 additions, 0 deletions
internal/auth/oauth2.go
with
12 additions
and
0 deletions
internal/auth/oauth2.go
+
12
−
0
View file @
97020c65
...
...
@@ -121,10 +121,22 @@ func (m Manager) HandleOAuth2Callback() http.Handler {
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
return
}
// Trim the user roles in case they come from LDAP
for
key
,
role
:=
range
user
.
Roles
{
user
.
Roles
[
key
]
=
strings
.
TrimPrefix
(
strings
.
Split
(
role
,
","
)[
0
],
"CN="
)
}
// Check if user has the correct role
err
=
checkUserHasRole
(
TokenData
{
User
:
user
},
[]
string
{
AdminRole
})
if
err
!=
nil
{
// Log the connexion attempt
log
.
Printf
(
"| %v (%v %v) | Login failed (Unauthorized user) | %v"
,
user
.
Login
,
user
.
Name
,
user
.
Surname
,
req
.
RemoteAddr
)
http
.
Redirect
(
w
,
r
,
"/"
,
http
.
StatusFound
)
return
}
// Store the user in cookie
// Generate
xsrfToken
,
err
:=
common
.
GenerateRandomString
(
16
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment