Skip to content

Commit

Permalink
Merge pull request #40 from MZC-CSC/develop
Browse files Browse the repository at this point in the history
bugfix connection add password
  • Loading branch information
MZC-CSC authored Dec 4, 2024
2 parents c784e00 + 421162f commit 15f06c3
Show file tree
Hide file tree
Showing 32 changed files with 248 additions and 125 deletions.
8 changes: 6 additions & 2 deletions api/actions/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ func App() *buffalo.App {
apiPath := "/api"

auth := app.Group(apiPath + "/auth")
auth.Middleware.Skip(SetContextMiddleware, AuthLogin)

auth.Middleware.Skip(SetContextMiddleware, AuthLogin, AuthLoginRefresh)
auth.POST("/login", AuthLogin)
auth.POST("/refresh", AuthLoginRefresh)
auth.POST("/validate", AuthValidate)
auth.POST("/logout", AuthLogout)
auth.POST("/userinfo", AuthUserinfo)

refresh := auth.Group("/refresh")
refresh.Use(SetRefreshCtxMiddleware)
refresh.POST("", AuthLoginRefresh)

api := app.Group(apiPath)
api.POST("/disklookup", DiskLookup)
api.POST("/availabledisktypebyproviderregion", AvailableDiskTypeByProviderRegion)
Expand Down
10 changes: 8 additions & 2 deletions api/actions/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"

"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/pop/v6"
)

Expand Down Expand Up @@ -54,16 +55,21 @@ func AuthLoginRefresh(c buffalo.Context) error {
return c.Render(commonResponse.Status.StatusCode, r.JSON(commonResponse))
}

refreshToken := c.Value("refreshToken").(string)
if refreshToken != sess.RefreshToken {
return c.Render(http.StatusForbidden, render.JSON(map[string]interface{}{"error": http.StatusText(http.StatusForbidden)}))
}

tokenSet, err := handler.RefreshAccessToken(sess.RefreshToken)
if err != nil {
app.Logger.Error(err.Error())
commonResponse := handler.CommonResponseStatusBadRequest(err.Error())
commonResponse := handler.CommonResponseStatusForbidden(err.Error())
return c.Render(commonResponse.Status.StatusCode, r.JSON(commonResponse))
}

sess.AccessToken = tokenSet.Accesstoken
sess.ExpiresIn = float64(tokenSet.ExpiresIn)
sess.RefreshToken = tokenSet.Accesstoken
sess.RefreshToken = tokenSet.RefreshToken
sess.RefreshExpiresIn = float64(tokenSet.RefreshExpiresIn)

_, err = handler.UpdateUserSess(tx, sess)
Expand Down
31 changes: 31 additions & 0 deletions api/actions/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,34 @@ func SetContextMiddleware(next buffalo.Handler) buffalo.Handler {
return next(c)
}
}

func SetRefreshCtxMiddleware(next buffalo.Handler) buffalo.Handler {
return func(c buffalo.Context) error {
accessToken := strings.TrimPrefix(c.Request().Header.Get("Authorization"), "Bearer ")
_, err := handler.GetTokenClaims(accessToken)
if errMsg := err.Error(); err != nil && !strings.Contains(errMsg, "token is expired") {
app.Logger.Error(errMsg)
app.Logger.Error("error occured from token claim")
return c.Render(http.StatusUnauthorized, render.JSON(map[string]interface{}{"error": "Unauthorized"}))
}

commonRequest := &handler.CommonRequest{}
if err := c.Bind(commonRequest); err != nil {
app.Logger.Error(err.Error())
return c.Render(http.StatusBadRequest, render.JSON(map[string]interface{}{"error": http.StatusText(http.StatusBadRequest)}))
}

refreshToken := commonRequest.Request.(map[string]interface{})["refresh_token"].(string)

refreshTokenClaim, err := handler.GetRefreshTokenClaims(refreshToken)
if err != nil {
app.Logger.Error(err.Error())
return c.Render(http.StatusForbidden, render.JSON(map[string]interface{}{"error": http.StatusText(http.StatusForbidden)}))
}

c.Set("UserId", refreshTokenClaim.Upn)
c.Set("refreshToken", refreshToken)

return next(c)
}
}
32 changes: 25 additions & 7 deletions api/handler/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ func generateJWT() (*CmigUserLoginResponse, error) {

refreshExp := time.Now().Add(refreshTokenExpired).Unix()
refreshClaims := CmigRefreshtokenClaims{
Exp: exp,
Exp: refreshExp,
Upn: user.Id,
MapClaims: &jwt.MapClaims{
"exp": exp,
"exp": refreshExp,
},
}
refreshToken := jwt.NewWithClaims(jwt.SigningMethodHS256, refreshClaims)
Expand All @@ -242,7 +243,7 @@ func GetUserToken(id string, password string) (*CmigUserLoginResponse, error) {
}

func RefreshAccessToken(refreshToken string) (*CmigUserLoginResponse, error) {
token, err := jwt.ParseWithClaims(refreshToken, &CmigAccesstokenClaims{}, func(token *jwt.Token) (interface{}, error) {
token, err := jwt.ParseWithClaims(refreshToken, &CmigRefreshtokenClaims{}, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
Expand All @@ -251,7 +252,7 @@ func RefreshAccessToken(refreshToken string) (*CmigUserLoginResponse, error) {
if err != nil {
return nil, fmt.Errorf("token is invalid : %s", err.Error())
}
if claims, ok := token.Claims.(*CmigAccesstokenClaims); ok && token.Valid {
if claims, ok := token.Claims.(*CmigRefreshtokenClaims); ok && token.Valid {
if time.Now().Unix() > claims.Exp {
return nil, fmt.Errorf("refresh token expired")
}
Expand All @@ -261,15 +262,32 @@ func RefreshAccessToken(refreshToken string) (*CmigUserLoginResponse, error) {
}
}

func GetTokenClaims(tokenString string) (*CmigAccesstokenClaims, error) {
token, err := jwt.ParseWithClaims(tokenString, &CmigAccesstokenClaims{}, func(token *jwt.Token) (interface{}, error) {
func GetRefreshTokenClaims(tokenString string) (*CmigRefreshtokenClaims, error) {
token, err := jwt.ParseWithClaims(tokenString, &CmigRefreshtokenClaims{}, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
return encryptionKey, nil
})
if err != nil {
return nil, fmt.Errorf("token is invalid : %s", err.Error())
return nil, err
}
if claims, ok := token.Claims.(*CmigRefreshtokenClaims); ok && token.Valid {
return claims, nil
} else {
return nil, fmt.Errorf("token is invalid")
}
}

func GetTokenClaims(tokenString string) (*CmigAccesstokenClaims, error) {
token, err := jwt.ParseWithClaims(tokenString, &CmigAccesstokenClaims{}, func(t *jwt.Token) (interface{}, error) {
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", t.Header["alg"])
}
return encryptionKey, nil
})
if err != nil {
return nil, err
}
if claims, ok := token.Claims.(*CmigAccesstokenClaims); ok && token.Valid {
return claims, nil
Expand Down
13 changes: 12 additions & 1 deletion api/handler/http-util.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type ApiYaml struct {
// ////////////////////////////////////////////////////////////////

var (
ApiYamlSet ApiYaml
ApiYamlSet ApiYaml
)

func init() {
Expand Down Expand Up @@ -359,6 +359,17 @@ func CommonResponseStatusBadRequest(responseData interface{}) *CommonResponse {
}
}

func CommonResponseStatusForbidden(responseData interface{}) *CommonResponse {
webStatus := WebStatus{
StatusCode: http.StatusForbidden,
Message: http.StatusText(http.StatusForbidden),
}
return &CommonResponse{
ResponseData: responseData,
Status: webStatus,
}
}

func CommonResponseStatusInternalServerError(responseData interface{}) *CommonResponse {
webStatus := WebStatus{
StatusCode: http.StatusInternalServerError,
Expand Down
2 changes: 1 addition & 1 deletion front/.env.local
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VITE_BACKEND_ENDPOINT = '/api'
VITE_BACKEND_URL = 'http://cm-butterfly-api:4000'
VITE_BACKEND_URL = 'https://devmigapi.onecloudcon.com'
VITE_PROJECT_NAME = 'MIGRATOR'
VITE_LANGUAGE = 'en'
7 changes: 6 additions & 1 deletion front/src/app/providers/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ import { AuthorizationType } from '../../../shared/libs/store/auth';
import { useAuthStore } from '../../../shared/libs/store/auth';
import { ROLE_TYPE } from '../../../shared/libs/accessControl/pageAccessHelper/constant';
import { RoleType } from '../../../shared/libs/accessControl/pageAccessHelper/types';
import { getMinimalPageAccessPermissionList } from '../../../shared/libs';
import {
axiosPost,
getMinimalPageAccessPermissionList,
} from '../../../shared/libs';
import { toLower } from 'lodash';
import { tempRoutes } from './routes/temp.ts';
import NotFound from '@/pages/error/404/NotFound.vue';
import { axiosInstance, createInstance } from '@/shared/libs/api/instance.ts';
//TODO admin부분 고려

const accessiblePagesWithRoles = [] as any[];
Expand Down Expand Up @@ -62,6 +66,7 @@ export class McmpRouter {
mode: 'history',
routes: McmpRouter.rootRoute,
});

McmpRouter.router.beforeEach((to: Route, from: Route, next) => {
const requiresAuth = to.matched.some(
record => record.meta?.requiresAuth,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { insertDynamicComponent } from '@/shared/utils';
import { getSequencePath } from '@/features/workflow/workflowEditor/sequential/designer/editor/model/utils.ts';
import BeetleTaskEditor from '@/features/workflow/workflowEditor/sequential/designer/editor/ui/BeetleTaskEditor.vue';
import { getSequencePath } from '@/features/sequential/designer/editor/model/utils.ts';
import BeetleTaskEditor from '@/features/sequential/designer/editor/ui/BeetleTaskEditor.vue';

export function editorProviders() {
const editor = document.createElement('div');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import Vue, {
watch,
} from 'vue';
import { useInputModel } from '@/shared/hooks/input/useInputModel.ts';
import { useTaskEditorModel } from '@/features/workflow/workflowEditor/sequential/designer/editor/model/beetleTaskEditorModel.ts';
import { useTaskEditorModel } from '@/features/sequential/designer/editor/model/beetleTaskEditorModel.ts';
import BAccordion from '@/shared/ui/Input/Accordian/BAccordion.vue';
import SequentialShortCut from '@/features/workflow/workflowEditor/sequential/designer/shortcut/ui/SequentialShortCut.vue';
import SequentialShortCut from '@/features/sequential/designer/shortcut/ui/SequentialShortCut.vue';
import { Step } from '@/features/workflow/workflowEditor/model/types.ts';
interface IProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
} from 'sequential-workflow-designer';
import { Definition, Step } from 'sequential-workflow-model';
import getRandomId from '@/shared/utils/uuid';
import { toolboxSteps } from '@/features/workflow/workflowEditor/sequential/designer/toolbox/model/toolboxSteps.ts';
import { editorProviders } from '@/features/workflow/workflowEditor/sequential/designer/editor/model/editorProviders.ts';
import { toolboxSteps } from '@/features/sequential/designer/toolbox/model/toolboxSteps.ts';
import { editorProviders } from '@/features/sequential/designer/editor/model/editorProviders.ts';
import testSvg from '@/shared/asset/image/testSvg.svg';

export function useSequentialDesignerModel(refs: any) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
getTaskComponentList,
ITaskComponentInfoResponse,
} from '@/features/workflow/workflowEditor/sequential/designer/toolbox/model/api';
} from '@/features/sequential/designer/toolbox/model/api';
import { parseRequestBody } from '@/shared/utils/stringToObject';
import getRandomId from '@/shared/utils/uuid';
import {
fixedModel,
Step,
} from '@/features/workflow/workflowEditor/model/types.ts';
import { toolboxSteps } from '@/features/workflow/workflowEditor/sequential/designer/toolbox/model/toolboxSteps.ts';
import { toolboxSteps } from '@/features/sequential/designer/toolbox/model/toolboxSteps.ts';
import { ITaskResponse } from '@/entities';

export function useSequentialToolboxModel() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script setup lang="ts">
import { onMounted, reactive, ref, triggerRef, watch } from 'vue';
import { useSequentialDesignerModel } from '@/features/workflow/workflowEditor/sequential/designer/model/sequentialDesignerModel.ts';
import { useSequentialDesignerModel } from '@/features/sequential/designer/model/sequentialDesignerModel.ts';
import { useSequentialToolboxModel } from '@/features/workflow/workflowEditor/sequential/designer/toolbox/model/toolboxModel.ts';
import { useSequentialToolboxModel } from '@/features/sequential/designer/toolbox/model/toolboxModel.ts';
import { Designer } from 'sequential-workflow-designer';
import { Step } from '@/features/workflow/workflowEditor/model/types.ts';
import { ITaskComponentInfoResponse } from '@/features/workflow/workflowEditor/sequential/designer/toolbox/model/api';
import { ITaskComponentInfoResponse } from '@/features/sequential/designer/toolbox/model/api';
import { Definition } from 'sequential-workflow-model';
interface IProps {
Expand Down Expand Up @@ -64,9 +64,9 @@ watch(
</template>

<style lang="postcss">
@import '@/../node_modules/sequential-workflow-designer/css/designer.css';
@import '@/../node_modules/sequential-workflow-designer/css/designer-light.css';
@import '@/../node_modules/sequential-workflow-designer/css/designer-dark.css';
@import 'sequential-workflow-designer/css/designer.css';
@import 'sequential-workflow-designer/css/designer-light.css';
@import 'sequential-workflow-designer/css/designer-dark.css';
.source-template-workflow-edit-container {
.workflow-box {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,13 @@ watch(
:invalid="!info.user"
/>
</p-field-group>
<p-field-group label="Password" invalid required>
<p-field-group label="Password">
<p-text-input
v-model="info.password"
placeholder="Password"
:invalid="!info.password"
/>
</p-field-group>
<p-field-group class="private-key" label="Private Key" invalid>
<p-field-group class="private-key" label="Private Key">
<p-text-input v-model="info.private_key" />
</p-field-group>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ watchEffect(() => {
:invalid="!sourceConnection.user"
/>
</p-field-group>
<p-field-group label="Password" invalid required>
<p-field-group label="Password">
<p-text-input
v-model="sourceConnection.password"
placeholder="Password"
:invalid="sourceConnection.password === ''"
/>
</p-field-group>
<p-field-group class="private-key" label="Private Key">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function handleConvertInfra(): (
<simple-edit-form
v-if="isSaveModal"
name=""
header-title="Save Source Modal"
header-title="Save Source Model"
name-label="Name"
name-placeholder="Source Service name"
@update:close-modal="isSaveModal = false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
IWorkflowResponse,
} from '@/entities/workflow/model/types.ts';
import getRandomId from '@/shared/utils/uuid';
import { toolboxSteps } from '@/features/workflow/workflowEditor/sequential/designer/toolbox/model/toolboxSteps.ts';
import { toolboxSteps } from '@/features/sequential/designer/toolbox/model/toolboxSteps.ts';
import { parseRequestBody } from '@/shared/utils/stringToObject';
import { ITaskComponentInfoResponse } from '@/features/workflow/workflowEditor/sequential/designer/toolbox/model/api';
import { ITaskComponentInfoResponse } from '@/features/sequential/designer/toolbox/model/api';
import { isNullOrUndefined, showErrorMessage } from '@/shared/utils';
import { reactive } from 'vue';
import { useSequentialToolboxModel } from '@/features/workflow/workflowEditor/sequential/designer/toolbox/model/toolboxModel.ts';
import { useSequentialToolboxModel } from '@/features/sequential/designer/toolbox/model/toolboxModel.ts';

type dropDownType = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import {
useUpdateWorkflowV2,
} from '@/entities';
import { Designer } from 'sequential-workflow-designer';
import SequentialDesigner from '@/features/workflow/workflowEditor/sequential/designer/ui/SequentialDesigner.vue';
import { showErrorMessage, showSuccessMessage } from '@/shared/utils';
import {
getTaskComponentList,
ITaskComponentInfoResponse,
} from '@/features/workflow/workflowEditor/sequential/designer/toolbox/model/api';
} from '@/features/sequential/designer/toolbox/model/api';
import getRandomId from '@/shared/utils/uuid';
import { parseRequestBody } from '@/shared/utils/stringToObject';
import SequentialDesigner from '@/features/sequential/designer/ui/SequentialDesigner.vue';
interface IProps {
wftId: string;
Expand Down Expand Up @@ -304,8 +304,8 @@ function handleSelectTemplate(e) {
<p-button
:loading="resUpdateWorkflow.isLoading.value"
@click="handleSave"
>Save</p-button
>
>Save
</p-button>
</template>
</create-form>
</div>
Expand Down
Loading

0 comments on commit 15f06c3

Please sign in to comment.