PLT-3629 fix uploading certificates if the files in the config do not exists (#3634)
Этот коммит содержится в:
11
api/admin.go
11
api/admin.go
@@ -45,6 +45,7 @@ func InitAdmin() {
|
||||
BaseRoutes.Admin.Handle("/saml_metadata", ApiAppHandler(samlMetadata)).Methods("GET")
|
||||
BaseRoutes.Admin.Handle("/add_certificate", ApiAdminSystemRequired(addCertificate)).Methods("POST")
|
||||
BaseRoutes.Admin.Handle("/remove_certificate", ApiAdminSystemRequired(removeCertificate)).Methods("POST")
|
||||
BaseRoutes.Admin.Handle("/saml_cert_status", ApiAdminSystemRequired(samlCertificateStatus)).Methods("GET")
|
||||
}
|
||||
|
||||
func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -659,3 +660,13 @@ func removeCertificate(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func samlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
status := make(map[string]interface{})
|
||||
|
||||
status["IdpCertificateFile"] = utils.FileExistsInConfigFolder(*utils.Cfg.SamlSettings.IdpCertificateFile)
|
||||
status["PrivateKeyFile"] = utils.FileExistsInConfigFolder(*utils.Cfg.SamlSettings.PrivateKeyFile)
|
||||
status["PublicCertificateFile"] = utils.FileExistsInConfigFolder(*utils.Cfg.SamlSettings.PublicCertificateFile)
|
||||
|
||||
w.Write([]byte(model.StringInterfaceToJson(status)))
|
||||
}
|
||||
|
||||
@@ -1730,7 +1730,7 @@ func (c *Client) UploadCertificateFile(data []byte, contentType string) *AppErro
|
||||
}
|
||||
|
||||
// Removes a x509 base64 Certificate or Private Key file used with SAML.
|
||||
// filename is required. Returns nil if succesful, otherwise returns an AppError
|
||||
// filename is required. Returns nil if successful, otherwise returns an AppError
|
||||
func (c *Client) RemoveCertificateFile(filename string) *AppError {
|
||||
if r, err := c.DoApiPost("/admin/remove_certificate", MapToJson(map[string]string{"filename": filename})); err != nil {
|
||||
return err
|
||||
@@ -1739,3 +1739,14 @@ func (c *Client) RemoveCertificateFile(filename string) *AppError {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Checks if the x509 base64 Certificates and Private Key files used with SAML exists on the file system.
|
||||
// Returns a map[string]interface{} if successful, otherwise returns an AppError. Must be System Admin authenticated.
|
||||
func (c *Client) SamlCertificateStatus(filename string) (map[string]interface{}, *AppError) {
|
||||
if r, err := c.DoApiGet("/admin/remove_certificate", "", ""); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return StringInterfaceFromJson(r.Body), nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func StringArrayIntersection(arr1, arr2 []string) []string {
|
||||
arrMap := map[string]bool{}
|
||||
result := []string{}
|
||||
@@ -19,3 +23,14 @@ func StringArrayIntersection(arr1, arr2 []string) []string {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func FileExistsInConfigFolder(filename string) bool {
|
||||
if len(filename) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if _, err := os.Stat(FindConfigFile(filename)); err == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1667,4 +1667,17 @@ export default class Client {
|
||||
send({filename}).
|
||||
end(this.handleResponse.bind(this, 'removeCertificateFile', success, error));
|
||||
}
|
||||
|
||||
samlCertificateStatus(success, error) {
|
||||
request.get(`${this.getAdminRoute()}/saml_cert_status`).
|
||||
set(this.defaultHeaders).
|
||||
type('application/json').
|
||||
accept('application/json').
|
||||
end((err, res) => {
|
||||
if (err) {
|
||||
return error(err);
|
||||
}
|
||||
return success(res.body);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,26 @@ export default class SamlSettings extends AdminSettings {
|
||||
};
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
Client.samlCertificateStatus(
|
||||
(data) => {
|
||||
const files = {};
|
||||
if (!data.IdpCertificateFile) {
|
||||
files.idpCertificateFile = '';
|
||||
}
|
||||
|
||||
if (!data.PublicCertificateFile) {
|
||||
files.publicCertificateFile = '';
|
||||
}
|
||||
|
||||
if (!data.PrivateKeyFile) {
|
||||
files.privateKeyFile = '';
|
||||
}
|
||||
this.setState(files);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
uploadCertificate(id, file, callback) {
|
||||
Client.uploadCertificateFile(
|
||||
file,
|
||||
|
||||
Ссылка в новой задаче
Block a user