mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-08 09:58:56 +08:00
dynamicGroupsListenerAdapter
This commit is contained in:
parent
c717ea7892
commit
d7e94db901
@ -65,7 +65,7 @@ public class GroupsService extends JpaService<Groups> implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Groups> queryDynamicRoles(Groups groups){
|
public List<Groups> queryDynamicGroups(Groups groups){
|
||||||
return this.getMapper().queryDynamic(groups);
|
return this.getMapper().queryDynamic(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,13 +143,13 @@ public class GroupsService extends JpaService<Groups> implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshAllDynamicRoles(){
|
public void refreshAllDynamicGroups(){
|
||||||
List<Institutions> instList =
|
List<Institutions> instList =
|
||||||
institutionsService.find("where status = ? ", new Object[]{ConstsStatus.ACTIVE}, new int[]{Types.INTEGER});
|
institutionsService.find("where status = ? ", new Object[]{ConstsStatus.ACTIVE}, new int[]{Types.INTEGER});
|
||||||
for(Institutions inst : instList) {
|
for(Institutions inst : instList) {
|
||||||
Groups group = new Groups();
|
Groups group = new Groups();
|
||||||
group.setInstId(inst.getId());
|
group.setInstId(inst.getId());
|
||||||
List<Groups> groupsList = queryDynamicRoles(group);
|
List<Groups> groupsList = queryDynamicGroups(group);
|
||||||
for(Groups g : groupsList) {
|
for(Groups g : groupsList) {
|
||||||
_logger.debug("role {}" , g);
|
_logger.debug("role {}" , g);
|
||||||
refreshDynamicRoles(g);
|
refreshDynamicRoles(g);
|
||||||
|
|||||||
@ -19,7 +19,7 @@ package org.dromara.maxkey.autoconfigure;
|
|||||||
|
|
||||||
import org.dromara.maxkey.authn.session.SessionManager;
|
import org.dromara.maxkey.authn.session.SessionManager;
|
||||||
import org.dromara.maxkey.configuration.ApplicationConfig;
|
import org.dromara.maxkey.configuration.ApplicationConfig;
|
||||||
import org.dromara.maxkey.listener.DynamicRolesListenerAdapter;
|
import org.dromara.maxkey.listener.DynamicGroupsListenerAdapter;
|
||||||
import org.dromara.maxkey.listener.ListenerAdapter;
|
import org.dromara.maxkey.listener.ListenerAdapter;
|
||||||
import org.dromara.maxkey.listener.ListenerParameter;
|
import org.dromara.maxkey.listener.ListenerParameter;
|
||||||
import org.dromara.maxkey.listener.SessionListenerAdapter;
|
import org.dromara.maxkey.listener.SessionListenerAdapter;
|
||||||
@ -57,21 +57,21 @@ public class MaxKeyMgtListenerConfig implements InitializingBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public String dynamicRolesListenerAdapter(
|
public String dynamicGroupsListenerAdapter(
|
||||||
Scheduler scheduler,
|
Scheduler scheduler,
|
||||||
GroupsService rolesService,
|
GroupsService groupsService,
|
||||||
@Value("${maxkey.job.cron.schedule}") String cronSchedule
|
@Value("${maxkey.job.cron.schedule}") String cronSchedule
|
||||||
) throws SchedulerException {
|
) throws SchedulerException {
|
||||||
|
|
||||||
ListenerAdapter.addListener(
|
ListenerAdapter.addListener(
|
||||||
DynamicRolesListenerAdapter.class,
|
DynamicGroupsListenerAdapter.class,
|
||||||
scheduler,
|
scheduler,
|
||||||
new ListenerParameter().add("rolesService",rolesService).build(),
|
new ListenerParameter().add("groupsService",groupsService).build(),
|
||||||
cronSchedule,
|
cronSchedule,
|
||||||
DynamicRolesListenerAdapter.class.getSimpleName()
|
DynamicGroupsListenerAdapter.class.getSimpleName()
|
||||||
);
|
);
|
||||||
logger.debug("DynamicRoles ListenerAdapter inited .");
|
logger.debug("DynamicGroups ListenerAdapter inited .");
|
||||||
return "dynamicRolesListenerAdapter";
|
return "dynamicGroupsListenerAdapter";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
@ -25,12 +25,12 @@ import org.quartz.JobExecutionContext;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class DynamicRolesListenerAdapter extends ListenerAdapter implements Job , Serializable {
|
public class DynamicGroupsListenerAdapter extends ListenerAdapter implements Job , Serializable {
|
||||||
static final Logger logger = LoggerFactory.getLogger(DynamicRolesListenerAdapter.class);
|
static final Logger logger = LoggerFactory.getLogger(DynamicGroupsListenerAdapter.class);
|
||||||
|
|
||||||
private static final long serialVersionUID = 8831626240807856084L;
|
private static final long serialVersionUID = 8831626240807856084L;
|
||||||
|
|
||||||
private GroupsService rolesService = null;
|
private GroupsService groupsService = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(JobExecutionContext context){
|
public void execute(JobExecutionContext context){
|
||||||
@ -41,8 +41,8 @@ public class DynamicRolesListenerAdapter extends ListenerAdapter implements Job
|
|||||||
logger.debug("running ... " );
|
logger.debug("running ... " );
|
||||||
jobStatus = JOBSTATUS.RUNNING;
|
jobStatus = JOBSTATUS.RUNNING;
|
||||||
try {
|
try {
|
||||||
if(rolesService != null) {
|
if(groupsService != null) {
|
||||||
rolesService.refreshAllDynamicRoles();
|
groupsService.refreshAllDynamicGroups();
|
||||||
Thread.sleep(10 * 1000);//10 minutes
|
Thread.sleep(10 * 1000);//10 minutes
|
||||||
}
|
}
|
||||||
logger.debug("finished " );
|
logger.debug("finished " );
|
||||||
@ -56,8 +56,8 @@ public class DynamicRolesListenerAdapter extends ListenerAdapter implements Job
|
|||||||
@Override
|
@Override
|
||||||
void init(JobExecutionContext context){
|
void init(JobExecutionContext context){
|
||||||
super.init(context);
|
super.init(context);
|
||||||
if(rolesService == null) {
|
if(groupsService == null) {
|
||||||
rolesService = getParameter("rolesService",GroupsService.class);
|
groupsService = getParameter("groupsService",GroupsService.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user