new version provision

This commit is contained in:
MaxKey
2022-09-13 11:09:18 +08:00
parent 9e230e20c5
commit 8e5fc93d13
43 changed files with 1711 additions and 425 deletions

View File

@@ -106,7 +106,7 @@ public class MaxKeyMvcConfig implements WebMvcConfigurer {
//addPathPatterns 用于添加拦截规则 先把所有路径都加入拦截, 再一个个排除
//excludePathPatterns 表示改路径不用拦截
_logger.debug("add HttpKerberosEntryPoint");
_logger.debug("add Http Kerberos Entry Point");
registry.addInterceptor(new HttpKerberosEntryPoint(
authenticationProvider,kerberosService,applicationConfig,true))
.addPathPatterns("/login");
@@ -115,13 +115,13 @@ public class MaxKeyMvcConfig implements WebMvcConfigurer {
if(httpHeaderEnable) {
registry.addInterceptor(new HttpHeaderEntryPoint(httpHeaderName,httpHeaderEnable))
.addPathPatterns("/*");
_logger.debug("add HttpHeaderEntryPoint");
_logger.debug("add Http Header Entry Point");
}
if(basicEnable) {
registry.addInterceptor(new BasicEntryPoint(basicEnable))
.addPathPatterns("/*");
_logger.debug("add BasicEntryPoint");
_logger.debug("add Basic Entry Point");
}
//for frontend

View File

@@ -44,8 +44,8 @@ maxkey.server.authz.uri =${maxkey.server.name}:${server.
maxkey.server.frontend.uri =/maxkey
#InMemory 0 , Redis 2
maxkey.server.persistence =${SERVER_PERSISTENCE:0}
#identity none, provision
maxkey.server.message.queue =${SERVER_MESSAGE_QUEUE:none}
#identity true,false
maxkey.server.provision =${SERVER_PROVISION:false}
#issuer name
maxkey.app.issuer =CN=ConSec,CN=COM,CN=SH
#must > jwt expire * 2

View File

@@ -18,11 +18,15 @@
package org.maxkey;
import org.maxkey.authn.session.SessionManager;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.listener.DynamicRolesListenerAdapter;
import org.maxkey.listener.ListenerAdapter;
import org.maxkey.listener.ListenerParameter;
import org.maxkey.listener.SessionListenerAdapter;
import org.maxkey.persistence.service.ConnectorsService;
import org.maxkey.persistence.service.RolesService;
import org.maxkey.provision.thread.ProvisioningRunner;
import org.maxkey.provision.thread.ProvisioningRunnerThread;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
@@ -31,6 +35,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
@Configuration
public class MaxKeyMgtListenerConfig implements InitializingBean {
@@ -69,6 +74,23 @@ public class MaxKeyMgtListenerConfig implements InitializingBean {
return "dynamicRolesListenerAdapter";
}
@Bean
public String provisioningRunnerThread(
ConnectorsService connectorsService,
JdbcTemplate jdbcTemplate,
ApplicationConfig applicationConfig
) throws SchedulerException {
if(applicationConfig.isProvisionSupport()) {
ProvisioningRunner runner = new ProvisioningRunner(connectorsService,jdbcTemplate);
ProvisioningRunnerThread runnerThread = new ProvisioningRunnerThread(runner);
runnerThread.start();
_logger.debug("provisioning Runner Thread .");
}else {
_logger.debug("not need init provisioning Runner Thread .");
}
return "provisioningRunnerThread";
}
@Override
public void afterPropertiesSet() throws Exception {

View File

@@ -84,7 +84,7 @@ public class MaxKeyMgtMvcConfig implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
//addPathPatterns 用于添加拦截规则 先把所有路径都加入拦截, 再一个个排除
//excludePathPatterns 表示改路径不用拦截
_logger.debug("add HttpJwtEntryPoint");
_logger.debug("add Interceptors");
permissionInterceptor.setMgmt(true);
@@ -118,7 +118,7 @@ public class MaxKeyMgtMvcConfig implements WebMvcConfigurer {
.addPathPatterns("/logout/**")
;
_logger.debug("add PermissionAdapter");
_logger.debug("add Permission Adapter");
registry.addInterceptor(historyLogsAdapter)
.addPathPatterns("/userinfo/**")
@@ -131,7 +131,7 @@ public class MaxKeyMgtMvcConfig implements WebMvcConfigurer {
.addPathPatterns("/apps/**")
.addPathPatterns("/approles/**")
;
_logger.debug("add HistoryLogsAdapter");
_logger.debug("add History Logs Adapter");
/*
* api
@@ -144,7 +144,7 @@ public class MaxKeyMgtMvcConfig implements WebMvcConfigurer {
.addPathPatterns("/api/idm/scim/**")
;
_logger.debug("add RestApiPermissionAdapter");
_logger.debug("add Rest Api Permission Adapter");
}

View File

@@ -0,0 +1,105 @@
/*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.maxkey.web.config.contorller;
import org.apache.commons.lang3.StringUtils;
import org.apache.mybatis.jpa.persistence.JpaPageResults;
import org.maxkey.authn.annotation.CurrentUser;
import org.maxkey.crypto.password.PasswordReciprocal;
import org.maxkey.entity.Connectors;
import org.maxkey.entity.Message;
import org.maxkey.entity.UserInfo;
import org.maxkey.persistence.service.ConnectorsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping(value={"/config/connectors"})
public class ConnectorsController {
final static Logger _logger = LoggerFactory.getLogger(ConnectorsController.class);
@Autowired
ConnectorsService connectorsService;
@RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public ResponseEntity<?> fetch(Connectors connector,@CurrentUser UserInfo currentUser) {
_logger.debug(""+connector);
connector.setInstId(currentUser.getInstId());
return new Message<JpaPageResults<Connectors>>(
connectorsService.queryPageResults(connector)).buildResponse();
}
@RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> get(@PathVariable("id") String id) {
Connectors connector = connectorsService.get(id);
if(StringUtils.isNotBlank(connector.getCredentials())) {
connector.setCredentials(PasswordReciprocal.getInstance().decoder(connector.getCredentials()));
}
return new Message<Connectors>(connector).buildResponse();
}
@ResponseBody
@RequestMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> insert(@RequestBody Connectors connector,@CurrentUser UserInfo currentUser) {
_logger.debug("-Add :" + connector);
connector.setInstId(currentUser.getInstId());
if(StringUtils.isNotBlank(connector.getCredentials())) {
connector.setCredentials(PasswordReciprocal.getInstance().encode(connector.getCredentials()));
}
if (connectorsService.insert(connector)) {
return new Message<Connectors>(Message.SUCCESS).buildResponse();
} else {
return new Message<Connectors>(Message.FAIL).buildResponse();
}
}
@ResponseBody
@RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> update(@RequestBody Connectors connector,@CurrentUser UserInfo currentUser) {
_logger.debug("-update :" + connector);
connector.setInstId(currentUser.getInstId());
connector.setCredentials(PasswordReciprocal.getInstance().encode(connector.getCredentials()));
if (connectorsService.update(connector)) {
return new Message<Connectors>(Message.SUCCESS).buildResponse();
} else {
return new Message<Connectors>(Message.FAIL).buildResponse();
}
}
@ResponseBody
@RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) {
_logger.debug("-delete ids : {} " , ids);
if (connectorsService.deleteBatch(ids)) {
return new Message<Connectors>(Message.SUCCESS).buildResponse();
} else {
return new Message<Connectors>(Message.FAIL).buildResponse();
}
}
}

View File

@@ -33,8 +33,8 @@ maxkey.server.mgt.uri =${maxkey.server.uri}
maxkey.server.authz.uri =https://${maxkey.server.domain}/maxkey
#InMemory 0 , Redis 2
maxkey.server.persistence =0
#identity none, provision
maxkey.server.message.queue =${SERVER_MESSAGE_QUEUE:none}
#identity true,false
maxkey.server.provision =${SERVER_PROVISION:false}
maxkey.session.timeout =${SERVER_SESSION_TIMEOUT:1800}