mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-30 14:13:43 +01:00
refactor ldap API
This commit is contained in:
parent
a901297859
commit
0d3c25e2a5
@ -20,8 +20,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/vmware/harbor/src/common/api"
|
|
||||||
"github.com/vmware/harbor/src/common/dao"
|
|
||||||
"github.com/vmware/harbor/src/common/models"
|
"github.com/vmware/harbor/src/common/models"
|
||||||
ldapUtils "github.com/vmware/harbor/src/common/utils/ldap"
|
ldapUtils "github.com/vmware/harbor/src/common/utils/ldap"
|
||||||
"github.com/vmware/harbor/src/common/utils/log"
|
"github.com/vmware/harbor/src/common/utils/log"
|
||||||
@ -29,25 +27,22 @@ import (
|
|||||||
|
|
||||||
// LdapAPI handles requesst to /api/ldap/ping /api/ldap/user/search /api/ldap/user/import
|
// LdapAPI handles requesst to /api/ldap/ping /api/ldap/user/search /api/ldap/user/import
|
||||||
type LdapAPI struct {
|
type LdapAPI struct {
|
||||||
api.BaseAPI
|
BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
const metaChars = "&|!=~*<>()"
|
const metaChars = "&|!=~*<>()"
|
||||||
|
|
||||||
// Prepare ...
|
// Prepare ...
|
||||||
func (l *LdapAPI) Prepare() {
|
func (l *LdapAPI) Prepare() {
|
||||||
|
l.BaseController.Prepare()
|
||||||
userID := l.ValidateUser()
|
if !l.SecurityCtx.IsAuthenticated() {
|
||||||
isSysAdmin, err := dao.IsAdminRole(userID)
|
l.HandleUnauthorized()
|
||||||
if err != nil {
|
return
|
||||||
log.Errorf("error occurred in IsAdminRole: %v", err)
|
|
||||||
l.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
|
|
||||||
}
|
}
|
||||||
|
if !l.SecurityCtx.IsSysAdmin() {
|
||||||
if !isSysAdmin {
|
l.HandleForbidden(l.SecurityCtx.GetUsername())
|
||||||
l.CustomAbort(http.StatusForbidden, http.StatusText(http.StatusForbidden))
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ping ...
|
// Ping ...
|
||||||
|
Loading…
Reference in New Issue
Block a user