1- import { Button , Divider , Drawer , Form , Input , InputNumber , Radio , Select , Spin , Space , Utils , Tabs , Collapse , Empty } from 'knowdesign' ;
1+ import { Button , Divider , Drawer , Form , Input , InputNumber , Radio , Select , Spin , Space , Utils , Tabs , Collapse , Empty , Checkbox } from 'knowdesign' ;
22import message from '@src/components/Message' ;
33import React , { forwardRef , useEffect , useImperativeHandle , useLayoutEffect , useRef , useState } from 'react' ;
44import { useIntl } from 'react-intl' ;
55import api from '@src/api' ;
6- import { regClusterName , regIpAndPort , regUsername } from '@src/constants/reg' ;
6+ import { regClusterName , regIpAndPort , regUsername , regJmxPassword } from '@src/constants/reg' ;
77import { bootstrapServersErrCodes , jmxErrCodes , zkErrCodes } from './config' ;
88import CodeMirrorFormItem from '@src/components/CodeMirrorFormItem' ;
99import { IconFont } from '@knowdesign/icons' ;
@@ -169,7 +169,16 @@ const ClusterTabContent = forwardRef((props: any, ref): JSX.Element => {
169169 const originValue = obj ?. jmxProperties ;
170170 if ( originValue ) {
171171 const jmxProperties = JSON . parse ( originValue ) ;
172- typeof jmxProperties === 'object' && jmxProperties !== null && Object . assign ( res , jmxProperties ) ;
172+ if ( typeof jmxProperties === 'object' && jmxProperties !== null ) {
173+ Object . assign ( res , jmxProperties ) ;
174+ // 根据是否有 username/token 判断是否启用密码认证
175+ const hasPasswordAuth = ! ! ( jmxProperties . username && jmxProperties . token ) ;
176+ res . hasPasswordAuth = hasPasswordAuth ;
177+ // 如果没有密码认证,确保 openSSL 为 false
178+ if ( ! hasPasswordAuth ) {
179+ res . openSSL = false ;
180+ }
181+ }
173182 }
174183 } catch ( err ) {
175184 console . error ( 'jmxProperties not JSON: ' , err ) ;
@@ -257,8 +266,8 @@ const ClusterTabContent = forwardRef((props: any, ref): JSX.Element => {
257266 if ( ! value ) {
258267 return Promise . reject ( '密码不能为空' ) ;
259268 }
260- if ( ! new RegExp ( regUsername ) . test ( value ) ) {
261- return Promise . reject ( '密码只能由大小写 、下划线、短划线(-)组成' ) ;
269+ if ( ! new RegExp ( regJmxPassword ) . test ( value ) ) {
270+ return Promise . reject ( '密码只能由大小写字母、数字 、下划线、短划线(-)组成' ) ;
262271 }
263272 if ( value . length < 6 || value . length > 32 ) {
264273 return Promise . reject ( '密码长度限制在6~32字符' ) ;
@@ -360,15 +369,15 @@ const ClusterTabContent = forwardRef((props: any, ref): JSX.Element => {
360369 < InputNumber addonAfter = "个" min = { 0 } max = { 99999 } style = { { width : 124 } } />
361370 </ Form . Item >
362371 </ div >
363- < Form . Item name = "openSSL " label = "Security :" >
372+ < Form . Item name = "hasPasswordAuth " label = "Security :" >
364373 < Radio . Group >
365374 < Radio value = { false } > None</ Radio >
366375 < Radio value = { true } > Password Authentication</ Radio >
367376 </ Radio . Group >
368377 </ Form . Item >
369- < Form . Item dependencies = { [ 'openSSL ' ] } noStyle >
378+ < Form . Item dependencies = { [ 'hasPasswordAuth ' ] } noStyle >
370379 { ( { getFieldValue } ) => {
371- return getFieldValue ( 'openSSL ' ) ? (
380+ return getFieldValue ( 'hasPasswordAuth ' ) ? (
372381 < div className = "user-info-form-items" >
373382 < Form . Item className = "user-info-label" label = "User Info :" required />
374383 < div className = "inline-items" >
@@ -379,6 +388,7 @@ const ClusterTabContent = forwardRef((props: any, ref): JSX.Element => {
379388 validator : validators . securityUserName ,
380389 } ,
381390 ] }
391+ style = { { width : '140px' , marginRight : '8px' } }
382392 >
383393 < Input placeholder = "请输入用户名" />
384394 </ Form . Item >
@@ -390,9 +400,13 @@ const ClusterTabContent = forwardRef((props: any, ref): JSX.Element => {
390400 validator : validators . securityToken ,
391401 } ,
392402 ] }
403+ style = { { width : '140px' , marginRight : '8px' } }
393404 >
394405 < Input placeholder = "请输入密码" />
395406 </ Form . Item >
407+ < Form . Item name = "openSSL" valuePropName = "checked" style = { { marginBottom : 0 , alignSelf : 'center' } } >
408+ < Checkbox > 启用 SSL</ Checkbox >
409+ </ Form . Item >
396410 </ div >
397411 </ div >
398412 ) : null ;
@@ -759,9 +773,9 @@ const AccessClusterDrawer = (props: AccessClusterDrawerProps) => {
759773 jmxProperties : {
760774 jmxPort : res . jmxPort ,
761775 maxConn : res . maxConn ,
762- openSSL : res . openSSL || false ,
763- token : res . token ,
764- username : res . username ,
776+ openSSL : res . hasPasswordAuth ? ( res . openSSL || false ) : false ,
777+ token : res . hasPasswordAuth ? res . token : '' ,
778+ username : res . hasPasswordAuth ? res . username : '' ,
765779 } ,
766780 kafkaVersion : res . kafkaVersion ,
767781 name : res . name ,
0 commit comments