This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
B&R
committed
Oct 28, 2023
1 parent
fc19777
commit fec4386
Showing
17 changed files
with
758 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ spec: | |
entry: iwa-ait | ||
|
||
accessControl: | ||
- userName: admin | ||
- name: admin | ||
type: user | ||
roles: | ||
- collectionManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
package http | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/gin-gonic/gin" | ||
"github.com/riotkit-org/backup-repository/pkg/core" | ||
"github.com/riotkit-org/backup-repository/pkg/security" | ||
"github.com/riotkit-org/backup-repository/pkg/users" | ||
"strings" | ||
) | ||
|
||
// GetContextUser returns a User{} that is authenticated in current request | ||
func GetContextUser(ctx *core.ApplicationContainer, c *gin.Context) (*users.User, error) { | ||
func GetContextUser(ctx *core.ApplicationContainer, c *gin.Context) (*users.SessionAwareUser, error) { | ||
username, accessKeyName := security.ExtractLoginFromJWT(c.GetHeader("Authorization")) | ||
scope, scopeErr := security.ExtractSessionLimitedOperationsScopeFromJWT(c.GetHeader("Authorization")) | ||
if scopeErr != nil { | ||
return nil, errors.New(fmt.Sprintf("cannot create context user: %s", scopeErr.Error())) | ||
} | ||
|
||
identity := security.NewUserIdentityFromString(username) | ||
identity.AccessKeyName = accessKeyName | ||
|
||
if accessKeyName != "" { | ||
return ctx.Users.LookupUser(username + "$" + accessKeyName) | ||
return ctx.Users.LookupSessionUser(identity, scope) | ||
} | ||
return ctx.Users.LookupUser(username) | ||
return ctx.Users.LookupSessionUser(identity, scope) | ||
} | ||
|
||
func GetCurrentSessionId(c *gin.Context) string { | ||
return security.HashJWT(c.GetHeader("Authorization")[7:]) | ||
return security.HashJWT(strings.Trim(c.GetHeader("Authorization"), " ")[7:]) | ||
} |
Oops, something went wrong.