Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions admin/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,19 @@ func handlerAuthCheck(h http.Handler) http.Handler {
case settings.AuthSAML:
samlSession, err := samlMiddleware.Session.GetSession(r)
if err != nil {
log.Err(err).Msg("GetSession")
http.Redirect(w, r, samlConfig.LoginURL, http.StatusFound)
return
}
if samlSession == nil {
log.Error().Msg("No SAML session")
http.Redirect(w, r, samlConfig.LogoutURL, http.StatusFound)
return
}
jwtSessionClaims, ok := samlSession.(samlsp.JWTSessionClaims)
if !ok {
log.Error().Msg("JWTSessionClaims")
return
}
samlUser := jwtSessionClaims.Subject
if samlUser == "" {
log.Error().Msg("SAML user is empty")
return
}
// Check if user is already authenticated
Expand Down
5 changes: 4 additions & 1 deletion admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,10 @@ func osctrlAdminService() {
adminMux.Handle("POST "+logoutPath, handlerAuthCheck(http.HandlerFunc(handlersAdmin.LogoutPOSTHandler)))
// SAML ACS
if adminConfig.Auth == settings.AuthSAML {
adminMux.Handle("GET /saml/", samlMiddleware)
adminMux.Handle("GET /saml/acs", samlMiddleware)
adminMux.Handle("POST /saml/acs", samlMiddleware)
adminMux.Handle("GET /saml/metadata", samlMiddleware)
adminMux.Handle("POST /saml/metadata", samlMiddleware)
adminMux.HandleFunc("GET "+loginPath, func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, samlConfig.LoginURL, http.StatusFound)
})
Expand Down
27 changes: 27 additions & 0 deletions admin/saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,37 @@ func loadSAML(file string) (JSONConfigurationSAML, error) {
if err := samlRaw.Unmarshal(&cfg); err != nil {
return cfg, err
}
// Verify SAML configuration
if err := verifySAML(cfg); err != nil {
return cfg, err
}
// No errors!
return cfg, nil
}

// Function to verify SAML configuration
func verifySAML(cfg JSONConfigurationSAML) error {
if cfg.CertPath == "" {
return fmt.Errorf("Missing CertPath")
}
if cfg.KeyPath == "" {
return fmt.Errorf("Missing KeyPath")
}
if cfg.MetaDataURL == "" {
return fmt.Errorf("Missing MetaDataURL")
}
if cfg.RootURL == "" {
return fmt.Errorf("Missing RootURL")
}
if cfg.LoginURL == "" {
return fmt.Errorf("Missing LoginURL")
}
if cfg.LogoutURL == "" {
return fmt.Errorf("Missing LogoutURL")
}
return nil
}

// Function to initialize variables when using SAML for authentication
func keypairSAML(config JSONConfigurationSAML) (samlThings, error) {
var data samlThings
Expand Down
Loading