Skip to content

Commit

Permalink
BED-4766: Correctly Format SAML Provider Details in ListAuthProviders…
Browse files Browse the repository at this point in the history
… Endpoint (#915)

* chore: list properly formatted saml provider

* chore: addresses array return of FormatSAMLProviderURLs
  • Loading branch information
iustinum authored Oct 25, 2024
1 parent 97edd77 commit f8813f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmd/api/src/api/v2/auth/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package auth

import (
"github.com/specterops/bloodhound/src/auth/bhsaml"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -116,7 +117,7 @@ func (s ManagementResource) ListAuthProviders(response http.ResponseWriter, requ
}
case model.SessionAuthProviderSAML:
if ssoProvider.SAMLProvider != nil {
provider.Details = ssoProvider.SAMLProvider
provider.Details = bhsaml.FormatSAMLProviderURLs(request.Context(), *ssoProvider.SAMLProvider)[0]
}
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/api/src/auth/bhsaml/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/specterops/bloodhound/src/serde"
)

func formatSAMLProviderURLs(requestContext context.Context, samlProviders ...model.SAMLProvider) model.SAMLProviders {
func FormatSAMLProviderURLs(requestContext context.Context, samlProviders ...model.SAMLProvider) model.SAMLProviders {
for idx := 0; idx < len(samlProviders); idx++ {
providerURLs := FormatServiceProviderURLs(*ctx.Get(requestContext).Host, samlProviders[idx].Name)

Expand All @@ -42,22 +42,22 @@ func GetSAMLProviderByName(db database.Database, name string, requestContext con
if samlProvider, err := db.LookupSAMLProviderByName(requestContext, name); err != nil {
return model.SAMLProvider{}, err
} else {
return formatSAMLProviderURLs(requestContext, samlProvider)[0], nil
return FormatSAMLProviderURLs(requestContext, samlProvider)[0], nil
}
}

func GetSAMLProviderByID(db database.Database, id int32, requestContext context.Context) (model.SAMLProvider, error) {
if samlProvider, err := db.GetSAMLProvider(requestContext, id); err != nil {
return model.SAMLProvider{}, err
} else {
return formatSAMLProviderURLs(requestContext, samlProvider)[0], nil
return FormatSAMLProviderURLs(requestContext, samlProvider)[0], nil
}
}

func GetAllSAMLProviders(db database.Database, requestContext context.Context) (model.SAMLProviders, error) {
if samlProviders, err := db.GetAllSAMLProviders(requestContext); err != nil {
return nil, err
} else {
return formatSAMLProviderURLs(requestContext, samlProviders...), nil
return FormatSAMLProviderURLs(requestContext, samlProviders...), nil
}
}

0 comments on commit f8813f8

Please sign in to comment.