mirror of
https://github.com/go-gitea/gitea
synced 2024-11-12 13:14:24 +00:00
Remove Named
interface (#26913)
`Named` is implemented by every `Method` and future implementations should implement the method too.
This commit is contained in:
parent
a99b96cbcd
commit
0eebeeec90
@ -36,6 +36,8 @@ var (
|
|||||||
algorithmPattern = regexp.MustCompile(`algorithm=(\w+)`)
|
algorithmPattern = regexp.MustCompile(`algorithm=(\w+)`)
|
||||||
versionPattern = regexp.MustCompile(`version=(\d+\.\d+)`)
|
versionPattern = regexp.MustCompile(`version=(\d+\.\d+)`)
|
||||||
authorizationPattern = regexp.MustCompile(`\AX-Ops-Authorization-(\d+)`)
|
authorizationPattern = regexp.MustCompile(`\AX-Ops-Authorization-(\d+)`)
|
||||||
|
|
||||||
|
_ auth.Method = &Auth{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Documentation:
|
// Documentation:
|
||||||
|
@ -12,6 +12,8 @@ import (
|
|||||||
"code.gitea.io/gitea/services/packages"
|
"code.gitea.io/gitea/services/packages"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ auth.Method = &Auth{}
|
||||||
|
|
||||||
type Auth struct{}
|
type Auth struct{}
|
||||||
|
|
||||||
func (a *Auth) Name() string {
|
func (a *Auth) Name() string {
|
||||||
|
@ -12,6 +12,8 @@ import (
|
|||||||
"code.gitea.io/gitea/services/packages"
|
"code.gitea.io/gitea/services/packages"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ auth.Method = &Auth{}
|
||||||
|
|
||||||
type Auth struct{}
|
type Auth struct{}
|
||||||
|
|
||||||
func (a *Auth) Name() string {
|
func (a *Auth) Name() string {
|
||||||
|
@ -13,6 +13,8 @@ import (
|
|||||||
"code.gitea.io/gitea/services/auth"
|
"code.gitea.io/gitea/services/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ auth.Method = &Auth{}
|
||||||
|
|
||||||
type Auth struct{}
|
type Auth struct{}
|
||||||
|
|
||||||
func (a *Auth) Name() string {
|
func (a *Auth) Name() string {
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
// Ensure the struct implements the interface.
|
// Ensure the struct implements the interface.
|
||||||
var (
|
var (
|
||||||
_ Method = &Basic{}
|
_ Method = &Basic{}
|
||||||
_ Named = &Basic{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// BasicMethodName is the constant name of the basic authentication method
|
// BasicMethodName is the constant name of the basic authentication method
|
||||||
|
@ -5,7 +5,6 @@ package auth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
@ -37,21 +36,16 @@ func (b *Group) Add(method Method) {
|
|||||||
func (b *Group) Name() string {
|
func (b *Group) Name() string {
|
||||||
names := make([]string, 0, len(b.methods))
|
names := make([]string, 0, len(b.methods))
|
||||||
for _, m := range b.methods {
|
for _, m := range b.methods {
|
||||||
if n, ok := m.(Named); ok {
|
names = append(names, m.Name())
|
||||||
names = append(names, n.Name())
|
|
||||||
} else {
|
|
||||||
names = append(names, reflect.TypeOf(m).Elem().Name())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return strings.Join(names, ",")
|
return strings.Join(names, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify extracts and validates
|
|
||||||
func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) {
|
func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) {
|
||||||
// Try to sign in with each of the enabled plugins
|
// Try to sign in with each of the enabled plugins
|
||||||
var retErr error
|
var retErr error
|
||||||
for _, ssoMethod := range b.methods {
|
for _, m := range b.methods {
|
||||||
user, err := ssoMethod.Verify(req, w, store, sess)
|
user, err := m.Verify(req, w, store, sess)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if retErr == nil {
|
if retErr == nil {
|
||||||
retErr = err
|
retErr = err
|
||||||
@ -67,9 +61,7 @@ func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore
|
|||||||
// Return the user and ignore any error returned by previous methods.
|
// Return the user and ignore any error returned by previous methods.
|
||||||
if user != nil {
|
if user != nil {
|
||||||
if store.GetData()["AuthedMethod"] == nil {
|
if store.GetData()["AuthedMethod"] == nil {
|
||||||
if named, ok := ssoMethod.(Named); ok {
|
store.GetData()["AuthedMethod"] = m.Name()
|
||||||
store.GetData()["AuthedMethod"] = named.Name()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
// Ensure the struct implements the interface.
|
// Ensure the struct implements the interface.
|
||||||
var (
|
var (
|
||||||
_ Method = &HTTPSign{}
|
_ Method = &HTTPSign{}
|
||||||
_ Named = &HTTPSign{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTPSign implements the Auth interface and authenticates requests (API requests
|
// HTTPSign implements the Auth interface and authenticates requests (API requests
|
||||||
|
@ -27,10 +27,7 @@ type Method interface {
|
|||||||
// Second argument returns err if verification fails, otherwise
|
// Second argument returns err if verification fails, otherwise
|
||||||
// First return argument returns nil if no matched verification condition
|
// First return argument returns nil if no matched verification condition
|
||||||
Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error)
|
Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error)
|
||||||
}
|
|
||||||
|
|
||||||
// Named represents a named thing
|
|
||||||
type Named interface {
|
|
||||||
Name() string
|
Name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
// Ensure the struct implements the interface.
|
// Ensure the struct implements the interface.
|
||||||
var (
|
var (
|
||||||
_ Method = &OAuth2{}
|
_ Method = &OAuth2{}
|
||||||
_ Named = &OAuth2{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckOAuthAccessToken returns uid of user from oauth token
|
// CheckOAuthAccessToken returns uid of user from oauth token
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
// Ensure the struct implements the interface.
|
// Ensure the struct implements the interface.
|
||||||
var (
|
var (
|
||||||
_ Method = &ReverseProxy{}
|
_ Method = &ReverseProxy{}
|
||||||
_ Named = &ReverseProxy{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReverseProxyMethodName is the constant name of the ReverseProxy authentication method
|
// ReverseProxyMethodName is the constant name of the ReverseProxy authentication method
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
// Ensure the struct implements the interface.
|
// Ensure the struct implements the interface.
|
||||||
var (
|
var (
|
||||||
_ Method = &Session{}
|
_ Method = &Session{}
|
||||||
_ Named = &Session{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Session checks if there is a user uid stored in the session and returns the user
|
// Session checks if there is a user uid stored in the session and returns the user
|
||||||
|
@ -37,7 +37,6 @@ var (
|
|||||||
|
|
||||||
// Ensure the struct implements the interface.
|
// Ensure the struct implements the interface.
|
||||||
_ Method = &SSPI{}
|
_ Method = &SSPI{}
|
||||||
_ Named = &SSPI{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SSPI implements the SingleSignOn interface and authenticates requests
|
// SSPI implements the SingleSignOn interface and authenticates requests
|
||||||
|
Loading…
Reference in New Issue
Block a user