MM-20698: Add server support for getting SAML metadata and updating S… (#13311)
* MM-20698: Add server support for getting SAMl metadata and updating SAMl settings
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c41e9d970a
Коммит
37ce413b7d
@@ -3463,6 +3463,18 @@ func (c *Client4) GetSamlCertificateStatus() (*SamlCertificateStatus, *Response)
|
||||
return SamlCertificateStatusFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) GetSamlMetadataFromIdp(samlMetadataURL string) (*SamlMetadataResponse, *Response) {
|
||||
requestBody := make(map[string]string)
|
||||
requestBody["saml_metadata_url"] = samlMetadataURL
|
||||
r, err := c.DoApiPost(c.GetSamlRoute()+"/metadatafromidp", MapToJson(requestBody))
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
|
||||
defer closeBody(r)
|
||||
return SamlMetadataResponseFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// Compliance Section
|
||||
|
||||
// CreateComplianceReport creates an incoming webhook for a channel.
|
||||
|
||||
@@ -1913,6 +1913,7 @@ type SamlSettings struct {
|
||||
|
||||
IdpUrl *string
|
||||
IdpDescriptorUrl *string
|
||||
IdpMetadataUrl *string
|
||||
AssertionConsumerServiceURL *string
|
||||
|
||||
SignatureAlgorithm *string
|
||||
@@ -1984,6 +1985,10 @@ func (s *SamlSettings) SetDefaults() {
|
||||
s.IdpDescriptorUrl = NewString("")
|
||||
}
|
||||
|
||||
if s.IdpMetadataUrl == nil {
|
||||
s.IdpMetadataUrl = NewString("")
|
||||
}
|
||||
|
||||
if s.IdpCertificateFile == nil {
|
||||
s.IdpCertificateFile = NewString("")
|
||||
}
|
||||
|
||||
@@ -157,6 +157,7 @@ func TestConfigIsValidFakeAlgorithm(t *testing.T) {
|
||||
|
||||
*c1.SamlSettings.IdpUrl = "http://test.url.com"
|
||||
*c1.SamlSettings.IdpDescriptorUrl = "http://test.url.com"
|
||||
*c1.SamlSettings.IdpMetadataUrl = "http://test.url.com"
|
||||
*c1.SamlSettings.IdpCertificateFile = "certificatefile"
|
||||
*c1.SamlSettings.EmailAttribute = "Email"
|
||||
*c1.SamlSettings.UsernameAttribute = "Username"
|
||||
|
||||
160
model/saml.go
160
model/saml.go
@@ -5,7 +5,9 @@ package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -25,6 +27,153 @@ type SamlCertificateStatus struct {
|
||||
PublicCertificateFile bool `json:"public_certificate_file"`
|
||||
}
|
||||
|
||||
type SamlMetadataResponse struct {
|
||||
IdpDescriptorUrl string `json:"idp_descriptor_url"`
|
||||
IdpUrl string `json:"idp_url"`
|
||||
IdpPublicCertificate string `json:"idp_public_certificate"`
|
||||
}
|
||||
|
||||
type NameIDFormat struct {
|
||||
XMLName xml.Name
|
||||
Format string `xml:",attr,omitempty"`
|
||||
Value string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
type NameID struct {
|
||||
NameQualifier string `xml:",attr"`
|
||||
SPNameQualifier string `xml:",attr"`
|
||||
Format string `xml:",attr,omitempty"`
|
||||
SPProvidedID string `xml:",attr"`
|
||||
Value string `xml:",chardata"`
|
||||
}
|
||||
|
||||
type AttributeValue struct {
|
||||
Type string `xml:"http://www.w3.org/2001/XMLSchema-instance type,attr"`
|
||||
Value string `xml:",chardata"`
|
||||
NameID *NameID
|
||||
}
|
||||
|
||||
type Attribute struct {
|
||||
XMLName xml.Name
|
||||
FriendlyName string `xml:",attr"`
|
||||
Name string `xml:",attr"`
|
||||
NameFormat string `xml:",attr"`
|
||||
Values []AttributeValue `xml:"AttributeValue"`
|
||||
}
|
||||
|
||||
type Endpoint struct {
|
||||
XMLName xml.Name
|
||||
Binding string `xml:"Binding,attr"`
|
||||
Location string `xml:"Location,attr"`
|
||||
ResponseLocation string `xml:"ResponseLocation,attr,omitempty"`
|
||||
}
|
||||
|
||||
type IndexedEndpoint struct {
|
||||
XMLName xml.Name
|
||||
Binding string `xml:"Binding,attr"`
|
||||
Location string `xml:"Location,attr"`
|
||||
ResponseLocation *string `xml:"ResponseLocation,attr,omitempty"`
|
||||
Index int `xml:"index,attr"`
|
||||
IsDefault *bool `xml:"isDefault,attr"`
|
||||
}
|
||||
|
||||
type IDPSSODescriptor struct {
|
||||
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:metadata IDPSSODescriptor"`
|
||||
SSODescriptor
|
||||
WantAuthnRequestsSigned *bool `xml:",attr"`
|
||||
|
||||
SingleSignOnServices []Endpoint `xml:"SingleSignOnService"`
|
||||
NameIDMappingServices []Endpoint `xml:"NameIDMappingService"`
|
||||
AssertionIDRequestServices []Endpoint `xml:"AssertionIDRequestService"`
|
||||
AttributeProfiles []string `xml:"AttributeProfile"`
|
||||
Attributes []Attribute `xml:"Attribute"`
|
||||
}
|
||||
|
||||
type SSODescriptor struct {
|
||||
XMLName xml.Name
|
||||
RoleDescriptor
|
||||
ArtifactResolutionServices []IndexedEndpoint `xml:"ArtifactResolutionService"`
|
||||
SingleLogoutServices []Endpoint `xml:"SingleLogoutService"`
|
||||
ManageNameIDServices []Endpoint `xml:"ManageNameIDService"`
|
||||
NameIDFormats []NameIDFormat `xml:"NameIDFormat"`
|
||||
}
|
||||
|
||||
type X509Certificate struct {
|
||||
XMLName xml.Name
|
||||
Cert string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
type X509Data struct {
|
||||
XMLName xml.Name
|
||||
X509Certificate X509Certificate `xml:"X509Certificate"`
|
||||
}
|
||||
|
||||
type KeyInfo struct {
|
||||
XMLName xml.Name
|
||||
DS string `xml:"xmlns:ds,attr"`
|
||||
X509Data X509Data `xml:"X509Data"`
|
||||
}
|
||||
type EncryptionMethod struct {
|
||||
Algorithm string `xml:"Algorithm,attr"`
|
||||
}
|
||||
|
||||
type KeyDescriptor struct {
|
||||
XMLName xml.Name
|
||||
Use string `xml:"use,attr,omitempty"`
|
||||
KeyInfo KeyInfo `xml:"http://www.w3.org/2000/09/xmldsig# KeyInfo,omitempty"`
|
||||
}
|
||||
|
||||
type RoleDescriptor struct {
|
||||
XMLName xml.Name
|
||||
ID string `xml:",attr,omitempty"`
|
||||
ValidUntil time.Time `xml:"validUntil,attr,omitempty"`
|
||||
CacheDuration time.Duration `xml:"cacheDuration,attr,omitempty"`
|
||||
ProtocolSupportEnumeration string `xml:"protocolSupportEnumeration,attr"`
|
||||
ErrorURL string `xml:"errorURL,attr,omitempty"`
|
||||
KeyDescriptors []KeyDescriptor `xml:"KeyDescriptor,omitempty"`
|
||||
Organization *Organization `xml:"Organization,omitempty"`
|
||||
ContactPersons []ContactPerson `xml:"ContactPerson,omitempty"`
|
||||
}
|
||||
|
||||
type ContactPerson struct {
|
||||
XMLName xml.Name
|
||||
ContactType string `xml:"contactType,attr"`
|
||||
Company string
|
||||
GivenName string
|
||||
SurName string
|
||||
EmailAddresses []string `xml:"EmailAddress"`
|
||||
TelephoneNumbers []string `xml:"TelephoneNumber"`
|
||||
}
|
||||
|
||||
type LocalizedName struct {
|
||||
Lang string `xml:"xml lang,attr"`
|
||||
Value string `xml:",chardata"`
|
||||
}
|
||||
|
||||
type LocalizedURI struct {
|
||||
Lang string `xml:"xml lang,attr"`
|
||||
Value string `xml:",chardata"`
|
||||
}
|
||||
|
||||
type Organization struct {
|
||||
XMLName xml.Name
|
||||
OrganizationNames []LocalizedName `xml:"OrganizationName"`
|
||||
OrganizationDisplayNames []LocalizedName `xml:"OrganizationDisplayName"`
|
||||
OrganizationURLs []LocalizedURI `xml:"OrganizationURL"`
|
||||
}
|
||||
|
||||
type EntityDescriptor struct {
|
||||
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:metadata EntityDescriptor"`
|
||||
EntityID string `xml:"entityID,attr"`
|
||||
ID string `xml:",attr,omitempty"`
|
||||
ValidUntil time.Time `xml:"validUntil,attr,omitempty"`
|
||||
CacheDuration time.Duration `xml:"cacheDuration,attr,omitempty"`
|
||||
RoleDescriptors []RoleDescriptor `xml:"RoleDescriptor"`
|
||||
IDPSSODescriptors []IDPSSODescriptor `xml:"IDPSSODescriptor"`
|
||||
Organization Organization `xml:"Organization"`
|
||||
ContactPerson ContactPerson `xml:"ContactPerson"`
|
||||
}
|
||||
|
||||
func (s *SamlCertificateStatus) ToJson() string {
|
||||
b, _ := json.Marshal(s)
|
||||
return string(b)
|
||||
@@ -35,3 +184,14 @@ func SamlCertificateStatusFromJson(data io.Reader) *SamlCertificateStatus {
|
||||
json.NewDecoder(data).Decode(&status)
|
||||
return status
|
||||
}
|
||||
|
||||
func (s *SamlMetadataResponse) ToJson() string {
|
||||
b, _ := json.Marshal(s)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func SamlMetadataResponseFromJson(data io.Reader) *SamlMetadataResponse {
|
||||
var status *SamlMetadataResponse
|
||||
json.NewDecoder(data).Decode(&status)
|
||||
return status
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user