* Implement LDAP Certificate

* add diagnostics and translations

* update from code review

* pass pointer to update pict function

* pass object to first function

* remove debug log messages

* update test to add localmode test

* update lint errors

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Scott Bishel
2020-09-14 12:53:42 -06:00
коммит произвёл GitHub
родитель 6fd7cb2a80
Коммит eba38625eb
14 изменённых файлов: 517 добавлений и 11 удалений

Просмотреть файл

@@ -3671,7 +3671,7 @@ func (c *Client4) GetSamlMetadata() (string, *Response) {
return buf.String(), BuildResponse(r)
}
func samlFileToMultipart(data []byte, filename string) ([]byte, *multipart.Writer, error) {
func fileToMultipart(data []byte, filename string) ([]byte, *multipart.Writer, error) {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
@@ -3694,7 +3694,7 @@ func samlFileToMultipart(data []byte, filename string) ([]byte, *multipart.Write
// UploadSamlIdpCertificate will upload an IDP certificate for SAML and set the config to use it.
// The filename parameter is deprecated and ignored: the server will pick a hard-coded filename when writing to disk.
func (c *Client4) UploadSamlIdpCertificate(data []byte, filename string) (bool, *Response) {
body, writer, err := samlFileToMultipart(data, filename)
body, writer, err := fileToMultipart(data, filename)
if err != nil {
return false, &Response{Error: NewAppError("UploadSamlIdpCertificate", "model.client.upload_saml_cert.app_error", nil, err.Error(), http.StatusBadRequest)}
}
@@ -3706,7 +3706,7 @@ func (c *Client4) UploadSamlIdpCertificate(data []byte, filename string) (bool,
// UploadSamlPublicCertificate will upload a public certificate for SAML and set the config to use it.
// The filename parameter is deprecated and ignored: the server will pick a hard-coded filename when writing to disk.
func (c *Client4) UploadSamlPublicCertificate(data []byte, filename string) (bool, *Response) {
body, writer, err := samlFileToMultipart(data, filename)
body, writer, err := fileToMultipart(data, filename)
if err != nil {
return false, &Response{Error: NewAppError("UploadSamlPublicCertificate", "model.client.upload_saml_cert.app_error", nil, err.Error(), http.StatusBadRequest)}
}
@@ -3718,7 +3718,7 @@ func (c *Client4) UploadSamlPublicCertificate(data []byte, filename string) (boo
// UploadSamlPrivateCertificate will upload a private key for SAML and set the config to use it.
// The filename parameter is deprecated and ignored: the server will pick a hard-coded filename when writing to disk.
func (c *Client4) UploadSamlPrivateCertificate(data []byte, filename string) (bool, *Response) {
body, writer, err := samlFileToMultipart(data, filename)
body, writer, err := fileToMultipart(data, filename)
if err != nil {
return false, &Response{Error: NewAppError("UploadSamlPrivateCertificate", "model.client.upload_saml_cert.app_error", nil, err.Error(), http.StatusBadRequest)}
}
@@ -4079,6 +4079,48 @@ func (c *Client4) MigrateAuthToSaml(fromAuthService string, usersMap map[string]
return CheckStatusOK(r), BuildResponse(r)
}
// UploadLdapPublicCertificate will upload a public certificate for LDAP and set the config to use it.
func (c *Client4) UploadLdapPublicCertificate(data []byte) (bool, *Response) {
body, writer, err := fileToMultipart(data, LDAP_PUBIC_CERTIFICATE_NAME)
if err != nil {
return false, &Response{Error: NewAppError("UploadLdapPublicCertificate", "model.client.upload_ldap_cert.app_error", nil, err.Error(), http.StatusBadRequest)}
}
_, resp := c.DoUploadFile(c.GetLdapRoute()+"/certificate/public", body, writer.FormDataContentType())
return resp.Error == nil, resp
}
// UploadLdapPrivateCertificate will upload a private key for LDAP and set the config to use it.
func (c *Client4) UploadLdapPrivateCertificate(data []byte) (bool, *Response) {
body, writer, err := fileToMultipart(data, LDAP_PRIVATE_KEY_NAME)
if err != nil {
return false, &Response{Error: NewAppError("UploadLdapPrivateCertificate", "model.client.upload_Ldap_cert.app_error", nil, err.Error(), http.StatusBadRequest)}
}
_, resp := c.DoUploadFile(c.GetLdapRoute()+"/certificate/private", body, writer.FormDataContentType())
return resp.Error == nil, resp
}
// DeleteLdapPublicCertificate deletes the LDAP IDP certificate from the server and updates the config to not use it and disable LDAP.
func (c *Client4) DeleteLdapPublicCertificate() (bool, *Response) {
r, err := c.DoApiDelete(c.GetLdapRoute() + "/certificate/public")
if err != nil {
return false, BuildErrorResponse(r, err)
}
defer closeBody(r)
return CheckStatusOK(r), BuildResponse(r)
}
// DeleteLDAPPrivateCertificate deletes the LDAP IDP certificate from the server and updates the config to not use it and disable LDAP.
func (c *Client4) DeleteLdapPrivateCertificate() (bool, *Response) {
r, err := c.DoApiDelete(c.GetLdapRoute() + "/certificate/private")
if err != nil {
return false, BuildErrorResponse(r, err)
}
defer closeBody(r)
return CheckStatusOK(r), BuildResponse(r)
}
// Audits Section
// GetAudits returns a list of audits for the whole system.

Просмотреть файл

@@ -1943,9 +1943,11 @@ type LdapSettings struct {
SyncIntervalMinutes *int `access:"authentication"`
// Advanced
SkipCertificateVerification *bool `access:"authentication"`
QueryTimeout *int `access:"authentication"`
MaxPageSize *int `access:"authentication"`
SkipCertificateVerification *bool `access:"authentication"`
PublicCertificateFile *string `access:"authentication"`
PrivateKeyFile *string `access:"authentication"`
QueryTimeout *int `access:"authentication"`
MaxPageSize *int `access:"authentication"`
// Customization
LoginFieldName *string `access:"authentication"`
@@ -1983,6 +1985,14 @@ func (s *LdapSettings) SetDefaults() {
s.ConnectionSecurity = NewString("")
}
if s.PublicCertificateFile == nil {
s.PublicCertificateFile = NewString("")
}
if s.PrivateKeyFile == nil {
s.PrivateKeyFile = NewString("")
}
if s.BaseDN == nil {
s.BaseDN = NewString("")
}

Просмотреть файл

@@ -4,5 +4,7 @@
package model
const (
USER_AUTH_SERVICE_LDAP = "ldap"
USER_AUTH_SERVICE_LDAP = "ldap"
LDAP_PUBIC_CERTIFICATE_NAME = "ldap-public.crt"
LDAP_PRIVATE_KEY_NAME = "ldap-private.key"
)