#616 added modal on icon click (#747)

* Added refresh tenant functionality

add icon to Users page to change password

commit work to date to github for ongoing use

add modal with fields for current and new password on icon click

missing swagger files

remove unneeded files

move changeUserPassword to admin_api, remove field for current password,
include selected user

Please enter the commit message for your changes. Lines starting

added missing js files

asset and function signature

formatting changes

* fixed lint

* removed Current Password field, returned Groups label, added
selectedUser to modal text

* disabled save button if newPasssword and reNewPassword don't match, removed commented out code

* Added refresh tenant functionality

add icon to Users page to change password

commit work to date to github for ongoing use

add modal with fields for current and new password on icon click

missing swagger files

remove unneeded files

move changeUserPassword to admin_api, remove field for current password,
include selected user

Please enter the commit message for your changes. Lines starting

added missing js files

asset and function signature

formatting changes

* removed Current Password field, returned Groups label, added
selectedUser to modal text

* changed Swagger parameters to camel case

Co-authored-by: Jill <jill@minio.io>
This commit is contained in:
jinapurapu
2021-06-03 15:32:22 -07:00
committed by GitHub
parent f18360416b
commit a9e82eb909
18 changed files with 1163 additions and 31 deletions

View File

@@ -0,0 +1,98 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// ChangeUserPasswordRequest change user password request
//
// swagger:model changeUserPasswordRequest
type ChangeUserPasswordRequest struct {
// new secret key
// Required: true
NewSecretKey *string `json:"newSecretKey"`
// selected user
// Required: true
SelectedUser *string `json:"selectedUser"`
}
// Validate validates this change user password request
func (m *ChangeUserPasswordRequest) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateNewSecretKey(formats); err != nil {
res = append(res, err)
}
if err := m.validateSelectedUser(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *ChangeUserPasswordRequest) validateNewSecretKey(formats strfmt.Registry) error {
if err := validate.Required("newSecretKey", "body", m.NewSecretKey); err != nil {
return err
}
return nil
}
func (m *ChangeUserPasswordRequest) validateSelectedUser(formats strfmt.Registry) error {
if err := validate.Required("selectedUser", "body", m.SelectedUser); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *ChangeUserPasswordRequest) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *ChangeUserPasswordRequest) UnmarshalBinary(b []byte) error {
var res ChangeUserPasswordRequest
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,271 @@
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
/*!
Copyright (c) 2017 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
/*!
* Chart.js v2.9.4
* https://www.chartjs.org
* (c) 2020 Chart.js Contributors
* Released under the MIT License
*/
/*!
* cookie
* Copyright(c) 2012-2014 Roman Shtylman
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*/
/*! Conditions:: INITIAL */
/*! Moment Duration Format v2.2.2
* https://github.com/jsmreese/moment-duration-format
* Date: 2018-02-16
*
* Duration format plugin function for the Moment.js library
* http://momentjs.com/
*
* Copyright 2018 John Madhavan-Reese
* Released under the MIT license
*/
/*! Production:: $accept : expression $end */
/*! Production:: css_value : ANGLE */
/*! Production:: css_value : CHS */
/*! Production:: css_value : EMS */
/*! Production:: css_value : EXS */
/*! Production:: css_value : FREQ */
/*! Production:: css_value : LENGTH */
/*! Production:: css_value : PERCENTAGE */
/*! Production:: css_value : REMS */
/*! Production:: css_value : RES */
/*! Production:: css_value : SUB css_value */
/*! Production:: css_value : TIME */
/*! Production:: css_value : VHS */
/*! Production:: css_value : VMAXS */
/*! Production:: css_value : VMINS */
/*! Production:: css_value : VWS */
/*! Production:: css_variable : CSS_VAR LPAREN CSS_CPROP COMMA math_expression RPAREN */
/*! Production:: css_variable : CSS_VAR LPAREN CSS_CPROP RPAREN */
/*! Production:: expression : math_expression EOF */
/*! Production:: math_expression : LPAREN math_expression RPAREN */
/*! Production:: math_expression : NESTED_CALC LPAREN math_expression RPAREN */
/*! Production:: math_expression : SUB PREFIX SUB NESTED_CALC LPAREN math_expression RPAREN */
/*! Production:: math_expression : css_value */
/*! Production:: math_expression : css_variable */
/*! Production:: math_expression : math_expression ADD math_expression */
/*! Production:: math_expression : math_expression DIV math_expression */
/*! Production:: math_expression : math_expression MUL math_expression */
/*! Production:: math_expression : math_expression SUB math_expression */
/*! Production:: math_expression : value */
/*! Production:: value : NUMBER */
/*! Production:: value : SUB NUMBER */
/*! Rule:: $ */
/*! Rule:: (--[0-9a-z-A-Z-]*) */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)% */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)Hz\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)ch\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)cm\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)deg\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)dpcm\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)dpi\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)dppx\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)em\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)ex\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)grad\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)in\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)kHz\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)mm\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)ms\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)pc\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)pt\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)px\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)rad\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)rem\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)s\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)turn\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)vh\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)vmax\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)vmin\b */
/*! Rule:: ([0-9]+(\.[0-9]*)?|\.[0-9]+)vw\b */
/*! Rule:: ([a-z]+) */
/*! Rule:: (calc) */
/*! Rule:: (var) */
/*! Rule:: , */
/*! Rule:: - */
/*! Rule:: \( */
/*! Rule:: \) */
/*! Rule:: \* */
/*! Rule:: \+ */
/*! Rule:: \/ */
/*! Rule:: \s+ */
/*! decimal.js-light v2.5.1 https://github.com/MikeMcl/decimal.js-light/LICENCE */
/**
* A better abstraction over CSS.
*
* @copyright Oleg Isonen (Slobodskoi) / Isonen 2014-present
* @website https://github.com/cssinjs/jss
* @license MIT
*/
/** @license React v0.20.1
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v16.13.1
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.1
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.1
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.1
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** @license React v17.0.1
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.16.1-lts
* @license
* Copyright (c) 2016 Federico Zivolo and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
//! moment.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,167 @@
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import React, { useState } from "react";
import { connect } from "react-redux";
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
import ModalWrapper from "../Common/ModalWrapper/ModalWrapper";
import Grid from "@material-ui/core/Grid";
import InputBoxWrapper from "../Common/FormComponents/InputBoxWrapper/InputBoxWrapper";
import { Button, LinearProgress } from "@material-ui/core";
import {
actionsTray,
containerForHeader,
modalBasic,
} from "../Common/FormComponents/common/styleLibrary";
import { ChangeUserPasswordRequest } from "../Buckets/types";
import api from "../../../common/api";
import { setModalErrorSnackMessage } from "../../../actions";
import { User, UsersList } from "../Users/types";
const styles = (theme: Theme) =>
createStyles({
buttonContainer: {
textAlign: "right",
},
...actionsTray,
...modalBasic,
...containerForHeader(theme.spacing(4)),
});
interface IChangeUserPasswordProps {
classes: any;
open: boolean;
selectedUser: User | null;
closeModal: () => void;
setModalErrorSnackMessage: typeof setModalErrorSnackMessage;
}
const ChangeUserPassword = ({
classes,
open,
selectedUser,
closeModal,
setModalErrorSnackMessage,
}: IChangeUserPasswordProps) => {
const [newPassword, setNewPassword] = useState<string>("");
const [reNewPassword, setReNewPassword] = useState<string>("");
const [loading, setLoading] = useState<boolean>(false);
const changeUserPassword = (event: React.FormEvent) => {
event.preventDefault();
if (loading) {
return;
}
setLoading(true);
let request: ChangeUserPasswordRequest = {
selectedUser: String(selectedUser?.accessKey),
newSecretKey: newPassword,
};
api
.invoke("POST", "/api/v1/account/change-user-password", request)
.then((res) => {
setLoading(false);
setNewPassword("");
setReNewPassword("");
closeModal();
})
.catch((err) => {
setLoading(false);
setNewPassword("");
setReNewPassword("");
setModalErrorSnackMessage(err);
});
};
return open ? (
<ModalWrapper
title="Change User Password"
modalOpen={open}
onClose={() => {
setNewPassword("");
setReNewPassword("");
closeModal();
}}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<form
noValidate
autoComplete="off"
onSubmit={(e: React.FormEvent<HTMLFormElement>) => {
changeUserPassword(e);
}}
>
<Grid container>
<Grid item xs={12} className={classes.formScrollable}>
<h3>Change password for {selectedUser?.accessKey}</h3>
<Grid item xs={12}>
<InputBoxWrapper
id="new-password"
name="new-password"
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setNewPassword(event.target.value);
}}
label="New Password"
type="password"
value={newPassword}
/>
</Grid>
<Grid item xs={12}>
<InputBoxWrapper
id="re-new-password"
name="re-new-password"
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setReNewPassword(event.target.value);
}}
label="Type New Password Again"
type="password"
value={reNewPassword}
/>
</Grid>
</Grid>
<Grid item xs={12} className={classes.buttonContainer}>
<Button
type="submit"
variant="contained"
color="primary"
disabled={
loading ||
!(reNewPassword.length > 0 && newPassword == reNewPassword)
}
>
Save
</Button>
</Grid>
{loading && (
<Grid item xs={12}>
<LinearProgress />
</Grid>
)}
</Grid>
</form>
</ModalWrapper>
) : null;
};
const connector = connect(null, {
setModalErrorSnackMessage,
});
export default withStyles(styles)(connector(ChangeUserPassword));

View File

@@ -116,6 +116,11 @@ export interface ChangePasswordRequest {
new_secret_key: string;
}
export interface ChangeUserPasswordRequest {
selectedUser: string;
newSecretKey: string;
}
export interface SubscriptionActivateRequest {
license: string;
email: string;

View File

@@ -37,6 +37,7 @@ import TableWrapper from "../Common/TableWrapper/TableWrapper";
import SetPolicy from "../Policies/SetPolicy";
import PageHeader from "../Common/PageHeader/PageHeader";
import history from "../../../history";
import ChangeUserPasswordModal from "../Account/ChangeUserPasswordModal";
const styles = (theme: Theme) =>
createStyles({
@@ -90,6 +91,9 @@ const ListUsers = ({ classes, setErrorSnackMessage }: IUsersProps) => {
const [filter, setFilter] = useState<string>("");
const [checkedUsers, setCheckedUsers] = useState<string[]>([]);
const [policyOpen, setPolicyOpen] = useState<boolean>(false);
const [resetPWOpen, setResetPWOpen] = useState<boolean>(false);
const [ChangeUserPasswordModalOpen, setChangeUserPasswordModalOpen] =
useState<boolean>(false);
const fetchRecords = useCallback(() => {
setLoading(true);
@@ -165,8 +169,14 @@ const ListUsers = ({ classes, setErrorSnackMessage }: IUsersProps) => {
const userLoggedIn = atob(localStorage.getItem("userLoggedIn") || "");
const setNewPW = (selectionElement: any): void => {
setChangeUserPasswordModalOpen(true);
setSelectedUser(selectionElement);
};
const tableActions = [
{ type: "view", onClick: viewAction },
{ type: "edit", onClick: setNewPW },
{
type: "delete",
onClick: deleteAction,
@@ -214,6 +224,13 @@ const ListUsers = ({ classes, setErrorSnackMessage }: IUsersProps) => {
}}
/>
)}
{ChangeUserPasswordModalOpen && (
<ChangeUserPasswordModal
open={ChangeUserPasswordModalOpen}
closeModal={() => setChangeUserPasswordModalOpen(false)}
selectedUser={selectedUser}
/>
)}
<PageHeader label={"Users"} />
<Grid container>
<Grid item xs={12} className={classes.container}>

View File

@@ -107,6 +107,14 @@ func registerUsersHandlers(api *operations.ConsoleAPI) {
}
return admin_api.NewListUsersWithAccessToBucketOK().WithPayload(response)
})
// Change User Password
api.AdminAPIChangeUserPasswordHandler = admin_api.ChangeUserPasswordHandlerFunc(func(params admin_api.ChangeUserPasswordParams, session *models.Principal) middleware.Responder {
err := getChangeUserPasswordResponse(session, params)
if err != nil {
return admin_api.NewChangeUserPasswordDefault(int(err.Code)).WithPayload(err)
}
return admin_api.NewChangeUserPasswordCreated()
})
}
func listUsers(ctx context.Context, client MinioAdmin) ([]*models.User, error) {
@@ -584,3 +592,33 @@ func listUsersWithAccessToBucket(ctx context.Context, adminClient MinioAdmin, bu
sort.Strings(retval)
return retval, nil
}
// changeUserPassword changes password of selectedUser to newSecretKey
func changeUserPassword(ctx context.Context, client MinioAdmin, selectedUser string, newSecretKey string) error {
if err := client.changePassword(ctx, selectedUser, newSecretKey); err != nil {
return err
}
return nil
}
// getChangeUserPasswordResponse will change the password of selctedUser to newSecretKey
func getChangeUserPasswordResponse(session *models.Principal, params admin_api.ChangeUserPasswordParams) *models.Error {
ctx := context.Background()
mAdmin, err := newMAdminClient(session)
if err != nil {
return prepareError(err)
}
// create a minioClient interface implementation
// defining the client to be used
adminClient := adminClient{client: mAdmin}
// params will contain selectedUser and newSecretKey credentials for the user
user := *params.Body.SelectedUser
newSecretKey := *params.Body.NewSecretKey
// changes password of user to newSecretKey
if err := changeUserPassword(ctx, adminClient, user, newSecretKey); err != nil {
return prepareError(err)
}
return nil
}

View File

@@ -85,6 +85,36 @@ func init() {
}
}
},
"/account/change-user-password": {
"post": {
"tags": [
"AdminAPI"
],
"summary": "Change password of currently logged in user.",
"operationId": "ChangeUserPassword",
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/changeUserPasswordRequest"
}
}
],
"responses": {
"201": {
"description": "Password successfully changed."
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/admin/arns": {
"get": {
"tags": [
@@ -4432,6 +4462,21 @@ func init() {
}
}
},
"changeUserPasswordRequest": {
"type": "object",
"required": [
"selectedUser",
"newSecretKey"
],
"properties": {
"newSecretKey": {
"type": "string"
},
"selectedUser": {
"type": "string"
}
}
},
"configDescription": {
"type": "object",
"properties": {
@@ -7321,6 +7366,36 @@ func init() {
}
}
},
"/account/change-user-password": {
"post": {
"tags": [
"AdminAPI"
],
"summary": "Change password of currently logged in user.",
"operationId": "ChangeUserPassword",
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/changeUserPasswordRequest"
}
}
],
"responses": {
"201": {
"description": "Password successfully changed."
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/admin/arns": {
"get": {
"tags": [
@@ -12308,6 +12383,21 @@ func init() {
}
}
},
"changeUserPasswordRequest": {
"type": "object",
"required": [
"selectedUser",
"newSecretKey"
],
"properties": {
"newSecretKey": {
"type": "string"
},
"selectedUser": {
"type": "string"
}
}
},
"configDescription": {
"type": "object",
"properties": {

View File

@@ -0,0 +1,90 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package admin_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"net/http"
"github.com/go-openapi/runtime/middleware"
"github.com/minio/console/models"
)
// ChangeUserPasswordHandlerFunc turns a function with the right signature into a change user password handler
type ChangeUserPasswordHandlerFunc func(ChangeUserPasswordParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn ChangeUserPasswordHandlerFunc) Handle(params ChangeUserPasswordParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// ChangeUserPasswordHandler interface for that can handle valid change user password params
type ChangeUserPasswordHandler interface {
Handle(ChangeUserPasswordParams, *models.Principal) middleware.Responder
}
// NewChangeUserPassword creates a new http.Handler for the change user password operation
func NewChangeUserPassword(ctx *middleware.Context, handler ChangeUserPasswordHandler) *ChangeUserPassword {
return &ChangeUserPassword{Context: ctx, Handler: handler}
}
/*ChangeUserPassword swagger:route POST /account/change-user-password AdminAPI changeUserPassword
Change password of currently logged in user.
*/
type ChangeUserPassword struct {
Context *middleware.Context
Handler ChangeUserPasswordHandler
}
func (o *ChangeUserPassword) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
r = rCtx
}
var Params = NewChangeUserPasswordParams()
uprinc, aCtx, err := o.Context.Authorize(r, route)
if err != nil {
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
if aCtx != nil {
r = aCtx
}
var principal *models.Principal
if uprinc != nil {
principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise
}
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
res := o.Handler.Handle(Params, principal) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}

View File

@@ -0,0 +1,94 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package admin_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"io"
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/minio/console/models"
)
// NewChangeUserPasswordParams creates a new ChangeUserPasswordParams object
// no default values defined in spec.
func NewChangeUserPasswordParams() ChangeUserPasswordParams {
return ChangeUserPasswordParams{}
}
// ChangeUserPasswordParams contains all the bound params for the change user password operation
// typically these are obtained from a http.Request
//
// swagger:parameters ChangeUserPassword
type ChangeUserPasswordParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
Required: true
In: body
*/
Body *models.ChangeUserPasswordRequest
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewChangeUserPasswordParams() beforehand.
func (o *ChangeUserPasswordParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
if runtime.HasBody(r) {
defer r.Body.Close()
var body models.ChangeUserPasswordRequest
if err := route.Consumer.Consume(r.Body, &body); err != nil {
if err == io.EOF {
res = append(res, errors.Required("body", "body", ""))
} else {
res = append(res, errors.NewParseError("body", "body", "", err))
}
} else {
// validate body object
if err := body.Validate(route.Formats); err != nil {
res = append(res, err)
}
if len(res) == 0 {
o.Body = &body
}
}
} else {
res = append(res, errors.Required("body", "body", ""))
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,113 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package admin_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/runtime"
"github.com/minio/console/models"
)
// ChangeUserPasswordCreatedCode is the HTTP code returned for type ChangeUserPasswordCreated
const ChangeUserPasswordCreatedCode int = 201
/*ChangeUserPasswordCreated Password successfully changed.
swagger:response changeUserPasswordCreated
*/
type ChangeUserPasswordCreated struct {
}
// NewChangeUserPasswordCreated creates ChangeUserPasswordCreated with default headers values
func NewChangeUserPasswordCreated() *ChangeUserPasswordCreated {
return &ChangeUserPasswordCreated{}
}
// WriteResponse to the client
func (o *ChangeUserPasswordCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(201)
}
/*ChangeUserPasswordDefault Generic error response.
swagger:response changeUserPasswordDefault
*/
type ChangeUserPasswordDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewChangeUserPasswordDefault creates ChangeUserPasswordDefault with default headers values
func NewChangeUserPasswordDefault(code int) *ChangeUserPasswordDefault {
if code <= 0 {
code = 500
}
return &ChangeUserPasswordDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the change user password default response
func (o *ChangeUserPasswordDefault) WithStatusCode(code int) *ChangeUserPasswordDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the change user password default response
func (o *ChangeUserPasswordDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the change user password default response
func (o *ChangeUserPasswordDefault) WithPayload(payload *models.Error) *ChangeUserPasswordDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the change user password default response
func (o *ChangeUserPasswordDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *ChangeUserPasswordDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(o._statusCode)
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
}

View File

@@ -0,0 +1,104 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2021 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package admin_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"errors"
"net/url"
golangswaggerpaths "path"
)
// ChangeUserPasswordURL generates an URL for the change user password operation
type ChangeUserPasswordURL struct {
_basePath string
}
// WithBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *ChangeUserPasswordURL) WithBasePath(bp string) *ChangeUserPasswordURL {
o.SetBasePath(bp)
return o
}
// SetBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *ChangeUserPasswordURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *ChangeUserPasswordURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/account/change-user-password"
_basePath := o._basePath
if _basePath == "" {
_basePath = "/api/v1"
}
_result.Path = golangswaggerpaths.Join(_basePath, _path)
return &_result, nil
}
// Must is a helper function to panic when the url builder returns an error
func (o *ChangeUserPasswordURL) Must(u *url.URL, err error) *url.URL {
if err != nil {
panic(err)
}
if u == nil {
panic("url can't be nil")
}
return u
}
// String returns the string representation of the path with query string
func (o *ChangeUserPasswordURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *ChangeUserPasswordURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on ChangeUserPasswordURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on ChangeUserPasswordURL")
}
base, err := o.Build()
if err != nil {
return nil, err
}
base.Scheme = scheme
base.Host = host
return base, nil
}
// StringFull returns the string representation of a complete url
func (o *ChangeUserPasswordURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -104,6 +104,9 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI {
AdminAPIBulkUpdateUsersGroupsHandler: admin_api.BulkUpdateUsersGroupsHandlerFunc(func(params admin_api.BulkUpdateUsersGroupsParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.BulkUpdateUsersGroups has not yet been implemented")
}),
AdminAPIChangeUserPasswordHandler: admin_api.ChangeUserPasswordHandlerFunc(func(params admin_api.ChangeUserPasswordParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.ChangeUserPassword has not yet been implemented")
}),
AdminAPIConfigInfoHandler: admin_api.ConfigInfoHandlerFunc(func(params admin_api.ConfigInfoParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.ConfigInfo has not yet been implemented")
}),
@@ -482,6 +485,8 @@ type ConsoleAPI struct {
UserAPIBucketSetPolicyHandler user_api.BucketSetPolicyHandler
// AdminAPIBulkUpdateUsersGroupsHandler sets the operation handler for the bulk update users groups operation
AdminAPIBulkUpdateUsersGroupsHandler admin_api.BulkUpdateUsersGroupsHandler
// AdminAPIChangeUserPasswordHandler sets the operation handler for the change user password operation
AdminAPIChangeUserPasswordHandler admin_api.ChangeUserPasswordHandler
// AdminAPIConfigInfoHandler sets the operation handler for the config info operation
AdminAPIConfigInfoHandler admin_api.ConfigInfoHandler
// UserAPICreateBucketEventHandler sets the operation handler for the create bucket event operation
@@ -797,6 +802,9 @@ func (o *ConsoleAPI) Validate() error {
if o.AdminAPIBulkUpdateUsersGroupsHandler == nil {
unregistered = append(unregistered, "admin_api.BulkUpdateUsersGroupsHandler")
}
if o.AdminAPIChangeUserPasswordHandler == nil {
unregistered = append(unregistered, "admin_api.ChangeUserPasswordHandler")
}
if o.AdminAPIConfigInfoHandler == nil {
unregistered = append(unregistered, "admin_api.ConfigInfoHandler")
}
@@ -1251,6 +1259,10 @@ func (o *ConsoleAPI) initHandlerCache() {
o.handlers["PUT"] = make(map[string]http.Handler)
}
o.handlers["PUT"]["/users-groups-bulk"] = admin_api.NewBulkUpdateUsersGroups(o.context, o.AdminAPIBulkUpdateUsersGroupsHandler)
if o.handlers["POST"] == nil {
o.handlers["POST"] = make(map[string]http.Handler)
}
o.handlers["POST"]["/account/change-user-password"] = admin_api.NewChangeUserPassword(o.context, o.AdminAPIChangeUserPasswordHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}

View File

@@ -68,23 +68,24 @@ func changePassword(ctx context.Context, client MinioAdmin, session *models.Prin
func getChangePasswordResponse(session *models.Principal, params user_api.AccountChangePasswordParams) (*models.LoginResponse, *models.Error) {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
accessKey := session.AccountAccessKey
currentSecretKey := *params.Body.CurrentSecretKey
newSecretKey := *params.Body.NewSecretKey
// changePassword operations requires an AdminClient initialized with parent account credentials not
// STS credentials
parentAccountClient, err := newMAdminClient(&models.Principal{
STSAccessKeyID: session.AccountAccessKey,
STSSecretAccessKey: currentSecretKey,
STSSecretAccessKey: *params.Body.CurrentSecretKey,
})
if err != nil {
return nil, prepareError(err)
}
// parentAccountClient will contain access and secret key credentials for the user
userClient := adminClient{client: parentAccountClient}
accessKey := session.AccountAccessKey
newSecretKey := *params.Body.NewSecretKey
// currentSecretKey will compare currentSecretKey against the stored secret key inside the encrypted session
if err := changePassword(ctx, userClient, session, newSecretKey); err != nil {
return nil, prepareError(err)
return nil, prepareError(errChangePassword, nil, err)
}
// user credentials are updated at this point, we need to generate a new admin client and authenticate using
// the new credentials

View File

@@ -19,7 +19,7 @@ securityDefinitions:
tokenUrl: http://min.io
# Apply the key security definition to all APIs
security:
- key: [ ]
- key: []
paths:
/login:
get:
@@ -35,7 +35,7 @@ paths:
schema:
$ref: "#/definitions/error"
# Exclude this API from the authentication requirement
security: [ ]
security: []
tags:
- UserAPI
post:
@@ -57,7 +57,7 @@ paths:
schema:
$ref: "#/definitions/error"
# Exclude this API from the authentication requirement
security: [ ]
security: []
tags:
- UserAPI
/login/operator:
@@ -79,7 +79,7 @@ paths:
description: Generic error response.
schema:
$ref: "#/definitions/error"
security: [ ]
security: []
tags:
- UserAPI
@@ -102,7 +102,7 @@ paths:
description: Generic error response.
schema:
$ref: "#/definitions/error"
security: [ ]
security: []
tags:
- UserAPI
@@ -158,6 +158,26 @@ paths:
tags:
- UserAPI
/account/change-user-password:
post:
summary: Change password of currently logged in user.
operationId: ChangeUserPassword
parameters:
- name: body
in: body
required: true
schema:
$ref: "#/definitions/changeUserPasswordRequest"
responses:
201:
description: Password successfully changed.
default:
description: Generic error response.
schema:
$ref: "#/definitions/error"
tags:
- AdminAPI
/buckets:
get:
summary: List Buckets
@@ -732,7 +752,6 @@ paths:
tags:
- UserAPI
/buckets-replication:
post:
summary: Sets Multi Bucket Replication in multiple Buckets
@@ -2086,7 +2105,7 @@ paths:
- name: order
in: query
type: string
enum: [ timeDesc, timeAsc ]
enum: [timeDesc, timeAsc]
default: timeDesc
- name: timeStart
in: query
@@ -2604,7 +2623,7 @@ paths:
$ref: "#/definitions/error"
tags:
- AdminAPI
/direct-csi/drives/format:
post:
summary: Format direct-csi drives from a list
@@ -2671,6 +2690,17 @@ definitions:
new_secret_key:
type: string
changeUserPasswordRequest:
type: object
required:
- selectedUser
- newSecretKey
properties:
selectedUser:
type: string
newSecretKey:
type: string
bucketEncryptionType:
type: string
enum:
@@ -3258,7 +3288,7 @@ definitions:
properties:
loginStrategy:
type: string
enum: [ form, redirect, service-account ]
enum: [form, redirect, service-account]
redirect:
type: string
loginOauth2AuthRequest:
@@ -3359,7 +3389,7 @@ definitions:
type: string
status:
type: string
enum: [ ok ]
enum: [ok]
operator:
type: boolean
widgetResult:
@@ -3371,7 +3401,7 @@ definitions:
type: string
values:
type: array
items: { }
items: {}
resultTarget:
type: object
properties:
@@ -3589,7 +3619,7 @@ definitions:
type: string
service:
type: string
enum: [ replication ]
enum: [replication]
syncMode:
type: string
bandwidth:
@@ -3725,7 +3755,6 @@ definitions:
status:
$ref: "#/definitions/tenantStatus"
tenantUsage:
type: object
properties:
@@ -4153,7 +4182,7 @@ definitions:
type: array
items:
$ref: "#/definitions/tenantResponseItem"
tenantResponseItem:
type: object
properties:
@@ -4168,11 +4197,9 @@ definitions:
- name
properties:
name:
type:
string
type: string
status:
type:
string
type: string
timeCreated:
type: integer
podIP:
@@ -4746,7 +4773,7 @@ definitions:
validity:
type: integer
format: int32
bucketLifecycleResponse:
type: object
properties:
@@ -4758,14 +4785,14 @@ definitions:
expirationResponse:
type: object
properties:
date:
date:
type: string
days:
type: integer
format: int64
delete_marker:
type: boolean
transitionResponse:
type: object
properties:
@@ -4776,7 +4803,7 @@ definitions:
days:
type: integer
format: int64
lifecycleTag:
type: object
properties:
@@ -4803,7 +4830,6 @@ definitions:
items:
$ref: "#/definitions/lifecycleTag"
addBucketLifecycle:
type: object
properties:
@@ -4851,7 +4877,7 @@ definitions:
noncurrentversion_transition_storage_class:
description: Non required, can be set in case of transition is enabled
type: string
updateBucketLifecycle:
type: object
properties:
@@ -4867,7 +4893,6 @@ definitions:
description: Returns wheter server needs to restart to apply changes or not
type: boolean
subscriptionValidateRequest:
type: object
properties:
@@ -5131,7 +5156,7 @@ definitions:
properties:
yaml:
type: string
listPVCsResponse:
type: object
properties: