组和角色优化,增加角色动态任务,删除resumeTime和suspendTime
This commit is contained in:
@@ -20,11 +20,13 @@ package org.dromara.maxkey.autoconfigure;
|
||||
import org.dromara.maxkey.authn.session.SessionManager;
|
||||
import org.dromara.maxkey.configuration.ApplicationConfig;
|
||||
import org.dromara.maxkey.listener.DynamicGroupsListenerAdapter;
|
||||
import org.dromara.maxkey.listener.DynamicRolesListenerAdapter;
|
||||
import org.dromara.maxkey.listener.ReorgDeptListenerAdapter;
|
||||
import org.dromara.maxkey.listener.SessionListenerAdapter;
|
||||
import org.dromara.maxkey.persistence.service.ConnectorsService;
|
||||
import org.dromara.maxkey.persistence.service.GroupsService;
|
||||
import org.dromara.maxkey.persistence.service.OrganizationsService;
|
||||
import org.dromara.maxkey.persistence.service.RolesService;
|
||||
import org.dromara.maxkey.provision.thread.ProvisioningRunner;
|
||||
import org.dromara.maxkey.provision.thread.ProvisioningRunnerThread;
|
||||
import org.dromara.maxkey.schedule.ScheduleAdapterBuilder;
|
||||
@@ -85,6 +87,23 @@ public class MaxKeyMgtListenerConfig {
|
||||
logger.debug("DynamicGroups ListenerAdapter inited .");
|
||||
return "dynamicGroupsListenerAdapter";
|
||||
}
|
||||
|
||||
@Bean
|
||||
String dynamicRolesListenerAdapter(
|
||||
Scheduler scheduler,
|
||||
RolesService rolesService,
|
||||
@Value("${maxkey.job.cron.schedule}") String cronSchedule
|
||||
) throws SchedulerException {
|
||||
new ScheduleAdapterBuilder()
|
||||
.setScheduler(scheduler)
|
||||
.setCron(cronSchedule)
|
||||
.setJobClass(DynamicRolesListenerAdapter.class)
|
||||
.setJobData("rolesService",rolesService)
|
||||
.build();
|
||||
|
||||
logger.debug("Dynamic Roles ListenerAdapter inited .");
|
||||
return "dynamicRolesListenerAdapter";
|
||||
}
|
||||
|
||||
@Bean
|
||||
String provisioningRunnerThread(
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright [2024] [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.dromara.maxkey.listener;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.dromara.maxkey.persistence.service.RolesService;
|
||||
import org.dromara.maxkey.schedule.ScheduleAdapter;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DynamicRolesListenerAdapter extends ScheduleAdapter implements Job , Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 7000735366821127880L;
|
||||
|
||||
static final Logger logger = LoggerFactory.getLogger(DynamicRolesListenerAdapter.class);
|
||||
|
||||
transient RolesService rolesService;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext context){
|
||||
if(jobStatus == JOBSTATUS.RUNNING) {return;}
|
||||
|
||||
init(context);
|
||||
|
||||
logger.debug("running ... " );
|
||||
jobStatus = JOBSTATUS.RUNNING;
|
||||
try {
|
||||
if(rolesService != null) {
|
||||
rolesService.refreshAllDynamicRoles();
|
||||
Thread.sleep(10 * 1000);//10 minutes
|
||||
}
|
||||
logger.debug("finished " );
|
||||
jobStatus = JOBSTATUS.FINISHED;
|
||||
}catch(Exception e) {
|
||||
jobStatus = JOBSTATUS.ERROR;
|
||||
logger.error("Exception " ,e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(JobExecutionContext context){
|
||||
super.init(context);
|
||||
if(rolesService == null) {
|
||||
rolesService = getParameter("rolesService",RolesService.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user