Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
fix endpoints, upgrade modules, linter
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-stauffer committed Jun 11, 2024
1 parent 2fbd1ea commit 463ef25
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 59 deletions.
15 changes: 6 additions & 9 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
API_SERVER_PORT = 3000
SSO_SERVER_PORT = 8081 // Publicly accessible without auth. See wiki.

SAML_SPECIFIC_ENDPOINT_PATH = "/saml/"
SAML_SPECIFIC_ENDPOINT_PATH = "/saml-sso/"
)

func initialize() {
Expand Down Expand Up @@ -129,21 +129,18 @@ func run() {
}()

// saml specific handle (no RESTful) to router
elionaAuth := eliona.NewSingleSignOn(config.OwnUrl,
sso := eliona.NewSingleSignOn(config.OwnUrl,
config.UserToArchive, config.LoginFailedUrl)

activeHandleFunc := http.HandlerFunc(elionaAuth.ActiveHandle)
activeHandleFunc := http.HandlerFunc(sso.ActiveHandle)
http.Handle(eliona.ENDPOINT_SSO_GENERIC_ACTIVE, activeHandleFunc)
authHandleFunc := http.HandlerFunc(elionaAuth.Authentication) // TODO: Not completely implemented.
samlErrHandleFunc := http.HandlerFunc(sso.DefaultLoginError)
http.Handle(eliona.ENDPOINT_SSO_GENERIC_ERROR, samlErrHandleFunc)
authHandleFunc := http.HandlerFunc(sso.Authentication)
http.Handle(eliona.ENDPOINT_SSO_GENERIC_VERIFICATION,
sp.GetMiddleWare().RequireAccount(authHandleFunc))
http.Handle(SAML_SPECIFIC_ENDPOINT_PATH, sp.GetMiddleWare())

// for backwards compatibility, can be removed when the frontend is reworked to the new generic /sso/* endpoints
http.Handle("/adfs/active/", activeHandleFunc)
http.Handle("/adfs/auth/",
sp.GetMiddleWare().RequireAccount(authHandleFunc))

log.Info(LOG_REGIO, "started @ %v", samlSpPort)
err = http.ListenAndServe(":"+samlSpPort, nil)
if err != nil {
Expand Down
24 changes: 20 additions & 4 deletions eliona/single_sign_on.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const (
)

const (
ENDPOINT_SSO_GENERIC_VERIFICATION = "/sso/auth"
ENDPOINT_SSO_GENERIC_ACTIVE = "/sso/active"
ENDPOINT_SSO_GENERIC_VERIFICATION = "/saml-sso/auth"
ENDPOINT_SSO_GENERIC_ACTIVE = "/saml-sso/active"
ENDPOINT_SSO_GENERIC_ERROR = "/saml-sso/error.html"
)

type SingleSignOn struct {
Expand Down Expand Up @@ -98,6 +99,18 @@ func (s *SingleSignOn) ActiveHandle(w http.ResponseWriter, r *http.Request) {
}
}

func (s *SingleSignOn) DefaultLoginError(w http.ResponseWriter, r *http.Request) {
content, err := os.ReadFile("html/error.html")
if err != nil {
log.Error(LOG_REGIO, "read def err page: %v", err)
}
w.WriteHeader(http.StatusOK)
_, err = w.Write(content)
if err != nil {
log.Error(LOG_REGIO, "send def err page: %v", err)
}
}

func (s *SingleSignOn) Authentication(w http.ResponseWriter, r *http.Request) {
log.Info(LOG_REGIO, "authentication handle called [%s]", r.Method)

Expand Down Expand Up @@ -258,7 +271,7 @@ func (s *SingleSignOn) authFailed(intError bool, login string, ip string, errorM
if err != nil {
log.Error(LOG_REGIO, "cannot parse fallback redirect url: %v", err)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(errorMsg + ":" + err.Error()))
_, _ = w.Write([]byte(errorMsg + ":" + err.Error()))
return
}
queries := url.Values{}
Expand All @@ -278,7 +291,10 @@ func (s *SingleSignOn) authFailed(intError bool, login string, ip string, errorM
http.Redirect(w, r, s.redirectNoLogin, http.StatusFound)
} else {
// write html content
w.Write([]byte(utils.SubstituteError(s.redirectNoLogin, []byte(errorMsg))))
_, err := w.Write([]byte(utils.SubstituteError(s.redirectNoLogin, []byte(errorMsg))))
if err != nil {
log.Error(LOG_REGIO, "write error page content: %v", err)
}
}
}

Expand Down
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ go 1.20

require (
github.com/crewjam/saml v0.4.14
github.com/eliona-smart-building-assistant/go-eliona v1.9.32
github.com/eliona-smart-building-assistant/go-eliona-api-client/v2 v2.6.3
github.com/eliona-smart-building-assistant/go-utils v1.0.62
github.com/eliona-smart-building-assistant/go-eliona v1.9.39
github.com/eliona-smart-building-assistant/go-eliona-api-client/v2 v2.6.12
github.com/eliona-smart-building-assistant/go-utils v1.1.1
github.com/friendsofgo/errors v0.9.2
github.com/go-test/deep v1.1.0
github.com/gorilla/mux v1.8.1
github.com/volatiletech/null/v8 v8.1.2
github.com/volatiletech/sqlboiler/v4 v4.16.2
github.com/volatiletech/strmangle v0.0.6
github.com/zenazn/goji v1.0.1
golang.org/x/crypto v0.20.0
golang.org/x/net v0.21.0
golang.org/x/crypto v0.24.0
golang.org/x/net v0.26.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -24,28 +24,28 @@ require (
replace github.com/ericlagergren/decimal => github.com/ericlagergren/decimal v0.0.0-20181231230500-73749d4874d5

require (
github.com/beevik/etree v1.3.0 // indirect
github.com/beevik/etree v1.4.0 // indirect
github.com/crewjam/httperr v0.2.0 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.1 // indirect
github.com/jackc/pgconn v1.14.3 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgtype v1.14.2 // indirect
github.com/jackc/pgx/v4 v4.18.1 // indirect
github.com/jackc/pgtype v1.14.3 // indirect
github.com/jackc/pgx/v4 v4.18.3 // indirect
github.com/jackc/puddle v1.3.0 // indirect
github.com/jonboulle/clockwork v0.4.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/russellhaering/goxmldsig v1.4.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/volatiletech/inflect v0.0.1 // indirect
github.com/volatiletech/randomize v0.0.1 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
)
Loading

0 comments on commit 463ef25

Please sign in to comment.