func (sa *Authenticator) AddUser(r *requests.Request) error {
	sa.mux.Lock()
	defer sa.mux.Unlock()
	return sa.db.AddUser(r)
}
AddUser adds a user to database.
package local
import (
	"github.com/greenpau/go-identity"
	"github.com/greenpau/go-identity/pkg/requests"
	"github.com/satori/go.uuid"
	"go.uber.org/zap"
	"sync"
)
var globalAuthenticators map[string]*Authenticator
func init() {
	globalAuthenticators = make(map[string]*Authenticator)
}
type Authenticator struct {
	db     *identity.Database
	mux    sync.Mutex
	path   string
	logger *zap.Logger
}
func NewAuthenticator() *Authenticator {
	return &Authenticator{}
}
func (sa *Authenticator) Configure(fp string) error {
	sa.mux.Lock()
	defer sa.mux.Unlock()
	sa.logger.Info(
		"local backend configuration",
		zap.String("db_path", fp),
	)
	sa.path = fp
	db, err := identity.NewDatabase(fp)
	if err != nil {
		return err
	}
	sa.db = db
	if len(sa.db.Users) == 0 {
		req := &requests.Request{
			User: requests.User{
				Username: "webadmin",
				Password: uuid.NewV4().String(),
				Email:    "webadmin@localdomain.local",
				Roles:    []string{"authp/admin"},
			},
		}
		if err := sa.db.AddUser(req); err != nil {
			return err
		}
		sa.logger.Info("created default admin user for the database",
			zap.String("username", req.User.Username),
			zap.String("email", req.User.Email),
			zap.String("secret", req.User.Password),
			zap.Any("roles", req.User.Roles),
		)
	}
	return nil
}
func (sa *Authenticator) AuthenticateUser(r *requests.Request) error {
	sa.mux.Lock()
	defer sa.mux.Unlock()
	return sa.db.AuthenticateUser(r)
}