Shares #109

Merged
amigan merged 59 commits from shareUI into trunk 2025-02-14 00:25:03 -05:00
4 changed files with 31 additions and 0 deletions
Showing only changes of commit dd2ee06f03 - Show all commits

View file

@ -2,6 +2,7 @@ package entities
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"github.com/el-mike/restrict/v2" "github.com/el-mike/restrict/v2"
@ -39,6 +40,7 @@ func SubjectFrom(ctx context.Context) Subject {
} }
type Subject interface { type Subject interface {
fmt.Stringer
restrict.Subject restrict.Subject
GetName() string GetName() string
} }
@ -63,6 +65,10 @@ func (s *PublicSubject) GetName() string {
return "PUBLIC:" + s.RemoteAddr return "PUBLIC:" + s.RemoteAddr
} }
func (s *PublicSubject) String() string {
return s.GetName()
}
func (s *PublicSubject) GetRoles() []string { func (s *PublicSubject) GetRoles() []string {
return []string{RolePublic} return []string{RolePublic}
} }
@ -79,6 +85,10 @@ func (s *SystemServiceSubject) GetName() string {
return "SYSTEM:" + s.Name return "SYSTEM:" + s.Name
} }
func (s *SystemServiceSubject) String() string {
return s.GetName()
}
func (s *SystemServiceSubject) GetRoles() []string { func (s *SystemServiceSubject) GetRoles() []string {
return []string{RoleSystem} return []string{RoleSystem}
} }

View file

@ -8,6 +8,7 @@ import (
"github.com/el-mike/restrict/v2" "github.com/el-mike/restrict/v2"
"github.com/el-mike/restrict/v2/adapters" "github.com/el-mike/restrict/v2/adapters"
"github.com/rs/zerolog/log"
) )
var ( var (
@ -121,6 +122,18 @@ func (r *rbac) Check(ctx context.Context, res restrict.Resource, opts ...CheckOp
} }
authRes := r.access.Authorize(req) authRes := r.access.Authorize(req)
if IsErrAccessDenied(authRes) != nil {
subS := ""
resS := ""
if sub != nil {
subS = sub.String()
}
if res != nil {
resS = res.GetResourceName()
}
log.Error().Str("resource", resS).Strs("actions", req.Actions).Str("subject", subS).Msg("access denied")
}
return sub, authRes return sub, authRes
} }

View file

@ -57,6 +57,10 @@ func (s *Share) GetName() string {
return "SHARE:" + s.ID return "SHARE:" + s.ID
} }
func (s *Share) String() string {
return s.GetName()
}
func (s *Share) GetRoles() []string { func (s *Share) GetRoles() []string {
return []string{entities.RoleShareGuest} return []string{entities.RoleShareGuest}
} }

View file

@ -71,6 +71,10 @@ func (u *User) GetName() string {
return u.Username return u.Username
} }
func (u *User) String() string {
return "USER:"+u.GetName()
}
func (u *User) GetRoles() []string { func (u *User) GetRoles() []string {
r := make([]string, 1, 2) r := make([]string, 1, 2)