-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,48 @@ | ||
package models | ||
|
||
import ( | ||
"crypto/x509" | ||
"encoding/base64" | ||
|
||
saml2 "github.com/russellhaering/gosaml2" | ||
dsig "github.com/russellhaering/goxmldsig" | ||
) | ||
|
||
type System struct { | ||
Version string `json:"version"` | ||
Endpoints *SystemEndpoints `json:"endpoints"` | ||
Setup bool `json:"setup" bson:"setup"` | ||
AllowManualSignin bool `json:"allow_manual_signin" bson:"allow_manual_signin"` | ||
SAML *SystemSAML `json:"sso" bson:"sso"` | ||
Version string `json:"version"` | ||
Endpoints *SystemEndpoints `json:"endpoints"` | ||
Setup bool `json:"setup" bson:"setup"` | ||
// Authentication manages the settings for available authentication methods, such as manual | ||
// username/password authentication and SAML authentication. Each authentication method | ||
// can be individually enabled or disabled. | ||
Authentication *SystemAuthentication `json:"authentication" bson:"authentication"` | ||
} | ||
|
||
type SystemEndpoints struct { | ||
API string `json:"api"` | ||
SSH string `json:"ssh"` | ||
} | ||
|
||
type SystemSAML struct { | ||
Enabled bool `json:"enabled" bson:"enabled"` | ||
AuthURL string `json:"auth_url" bson:"-"` | ||
IdpEntityID string `json:"-" bson:"idp_entity_id"` | ||
IdpSignonLocation string `json:"-" bson:"idp_signon_location"` | ||
IdpLogoutLocation string `json:"-" bson:"idp_logout_location"` | ||
IdpCertificate string `json:"-" bson:"idp_certificate"` | ||
type SystemAuthentication struct { | ||
// Manual indicates whether manual authentication using a username and password is enabled or | ||
// not. | ||
Manual bool `json:"manual" bson:"manual"` | ||
// SAML contains the configuration settings for SAML authentication. [SAML.Enabled] indicates | ||
// whether SAML authentication is enabled or not. | ||
SAML *SystemSAML `json:"saml" bson:"saml"` | ||
} | ||
|
||
func (s *SystemSAML) decodeCertificate() *dsig.MemoryX509CertificateStore { | ||
certData, err := base64.StdEncoding.DecodeString(s.IdpCertificate) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
idpCert, err := x509.ParseCertificate(certData) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
certStore := new(dsig.MemoryX509CertificateStore) | ||
certStore.Roots = append(certStore.Roots, idpCert) | ||
|
||
return certStore | ||
type SystemSAML struct { | ||
// Enabled indicates whether SAML authentication is enabled. | ||
Enabled bool `json:"enabled" bson:"enabled"` | ||
Idp *SystemIdpSAML `json:"-" bson:"idp"` | ||
Sp *SystemSpSAML `json:"-" bson:"sp"` | ||
} | ||
|
||
func (s *SystemSAML) GetAuthURL() { | ||
sp := &saml2.SAMLServiceProvider{ | ||
IdentityProviderSSOURL: s.IdpSignonLocation, | ||
IdentityProviderIssuer: s.IdpEntityID, | ||
AssertionConsumerServiceURL: "http://localhost:3334/v1/_saml_callback", | ||
SignAuthnRequests: true, | ||
IDPCertificateStore: s.decodeCertificate(), | ||
SPKeyStore: dsig.RandomKeyStoreForTest(), | ||
} | ||
type SystemIdpSAML struct { | ||
EntityID string `json:"-" bson:"entity_id"` | ||
SignonURL string `json:"-" bson:"signon_url"` | ||
// Certificate is the IdP's X.509 certificate used to validate the authenticity of SAML assertions. | ||
Certificate string `json:"-" bson:"certificate"` | ||
} | ||
|
||
s.AuthURL, _ = sp.BuildAuthURL("") | ||
type SystemSpSAML struct { | ||
// Certificate is the SP X.509 certificate used to enable mutual verification | ||
// between the SP and IdP. The IdP uses this certificate to validate that authentication requests | ||
// are signed by the SP, it also disable the "IdP-initiated" login flows. | ||
// | ||
// If this field is empty, the mutual verification behavior is disabled. | ||
Certificate string `json:"-" bson:"certificate"` | ||
} |