use custom UserIDFunc for anonymous provider

This commit is contained in:
Alena Maslova
2022-05-10 12:59:49 -05:00
committed by Umputun
parent 168a6d36c0
commit ac492180e8
+6 -2
View File
@@ -887,7 +887,8 @@ func (s *ServerCommand) addAuthProviders(authenticator *auth.Service) error {
if s.Auth.Anonymous {
log.Print("[INFO] anonymous access enabled")
var isValidAnonName = regexp.MustCompile(`^[\p{L}\d_ ]+$`).MatchString
authenticator.AddDirectProvider("anonymous", provider.CredCheckerFunc(func(user, _ string) (ok bool, err error) {
authenticator.AddDirectProviderWithUserIDFunc("anonymous", provider.CredCheckerFunc(func(user, _ string) (ok bool, err error) {
// don't allow anon with space prefix or suffix
if strings.HasPrefix(user, " ") || strings.HasSuffix(user, " ") {
log.Printf("[WARN] name %q has space as a suffix or prefix", user)
@@ -909,7 +910,10 @@ func (s *ServerCommand) addAuthProviders(authenticator *auth.Service) error {
return false, nil
}
return true, nil
}))
}),
func(user string, r *http.Request) string {
return user + r.RemoteAddr
})
}
if providersCount == 0 {