mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-18 17:18:16 +02:00
proxy: add route portal json (#5428)
* proxy: add route portal json * fix 405 issue * add link to issue * Update proxy/portal/filter_test.go Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com> --------- Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com>
This commit is contained in:
parent
6e1fabec0b
commit
e816cef2a1
10 changed files with 628 additions and 5 deletions
56
proxy/handlers_portal.go
Normal file
56
proxy/handlers_portal.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package proxy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/pomerium/pomerium/config"
|
||||
"github.com/pomerium/pomerium/internal/handlers"
|
||||
"github.com/pomerium/pomerium/internal/httputil"
|
||||
"github.com/pomerium/pomerium/proxy/portal"
|
||||
)
|
||||
|
||||
func (p *Proxy) routesPortalJSON(w http.ResponseWriter, r *http.Request) error {
|
||||
u := p.getUserInfoData(r)
|
||||
rs := p.getPortalRoutes(u)
|
||||
m := map[string]any{}
|
||||
m["routes"] = rs
|
||||
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return httputil.NewError(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(b)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Proxy) getPortalRoutes(u handlers.UserInfoData) []portal.Route {
|
||||
options := p.currentOptions.Load()
|
||||
pu := p.getPortalUser(u)
|
||||
var routes []*config.Policy
|
||||
for route := range options.GetAllPolicies() {
|
||||
if portal.CheckRouteAccess(pu, route) {
|
||||
routes = append(routes, route)
|
||||
}
|
||||
}
|
||||
return portal.RoutesFromConfigRoutes(routes)
|
||||
}
|
||||
|
||||
func (p *Proxy) getPortalUser(u handlers.UserInfoData) portal.User {
|
||||
pu := portal.User{}
|
||||
pu.SessionID = u.Session.GetId()
|
||||
pu.UserID = u.User.GetId()
|
||||
pu.Email = u.User.GetEmail()
|
||||
for _, dg := range u.DirectoryGroups {
|
||||
if v := dg.ID; v != "" {
|
||||
pu.Groups = append(pu.Groups, dg.ID)
|
||||
}
|
||||
if v := dg.Name; v != "" {
|
||||
pu.Groups = append(pu.Groups, dg.Name)
|
||||
}
|
||||
}
|
||||
return pu
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue