diff --git a/maxkey-lib/mybatis-jpa-extra-3.3.1.jar b/maxkey-lib/mybatis-jpa-extra-3.3.2.jar similarity index 77% rename from maxkey-lib/mybatis-jpa-extra-3.3.1.jar rename to maxkey-lib/mybatis-jpa-extra-3.3.2.jar index 4c72c031..b91b50fe 100644 Binary files a/maxkey-lib/mybatis-jpa-extra-3.3.1.jar and b/maxkey-lib/mybatis-jpa-extra-3.3.2.jar differ diff --git a/maxkey-lib/mybatis-jpa-extra-spring-boot-starter-3.3.1.jar b/maxkey-lib/mybatis-jpa-extra-spring-boot-starter-3.3.2.jar similarity index 81% rename from maxkey-lib/mybatis-jpa-extra-spring-boot-starter-3.3.1.jar rename to maxkey-lib/mybatis-jpa-extra-spring-boot-starter-3.3.2.jar index 88e68e4c..ffb4128a 100644 Binary files a/maxkey-lib/mybatis-jpa-extra-spring-boot-starter-3.3.1.jar and b/maxkey-lib/mybatis-jpa-extra-spring-boot-starter-3.3.2.jar differ diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AccessService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AccessService.java index 97e7dea9..149aa525 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AccessService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AccessService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -18,25 +18,9 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.Access; -import org.dromara.maxkey.persistence.mapper.AccessMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class AccessService extends JpaService{ - - public AccessService() { - super(AccessMapper.class); - } - - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public AccessMapper getMapper() { - return (AccessMapper)super.getMapper(); - } +public interface AccessService extends IJpaService{ } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AccountsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AccountsService.java index 73412eba..1371a87a 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AccountsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AccountsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -19,246 +19,30 @@ package org.dromara.maxkey.persistence.service; import java.util.List; -import org.apache.commons.lang3.StringUtils; -import org.dromara.maxkey.constants.ConstsStatus; -import org.dromara.maxkey.crypto.password.PasswordReciprocal; import org.dromara.maxkey.entity.Accounts; import org.dromara.maxkey.entity.AccountsStrategy; -import org.dromara.maxkey.entity.OrganizationsCast; import org.dromara.maxkey.entity.idm.UserInfo; -import org.dromara.maxkey.persistence.mapper.AccountsMapper; -import org.dromara.maxkey.provision.ProvisionAct; -import org.dromara.maxkey.provision.ProvisionService; -import org.dromara.maxkey.provision.ProvisionTopic; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -import net.sourceforge.pinyin4j.PinyinHelper; -import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; -import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; -import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; -import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; -import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; +public interface AccountsService extends IJpaService{ -@Repository -public class AccountsService extends JpaService{ - - @Autowired - ProvisionService provisionService; - - @Autowired - UserInfoService userInfoService; - - @Autowired - AccountsStrategyService accountsStrategyService; - - @Autowired - OrganizationsCastService organizationsCastService; - - public AccountsService() { - super(AccountsMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public AccountsMapper getMapper() { - return (AccountsMapper)super.getMapper(); - } + public boolean updateStatus(Accounts accounts) ; + + public boolean remove(String id) ; + + public void refreshByStrategy(AccountsStrategy strategy) ; + + public void refreshAllByStrategy() ; + + public List queryUserNotInStrategy(AccountsStrategy strategy); + + public long deleteByStrategy(AccountsStrategy strategy) ; - @Override - public boolean insert(Accounts account) { - if (super.insert(account)) { - if(provisionService.getApplicationConfig().isProvisionSupport()) { - UserInfo loadUserInfo = userInfoService.findUserRelated(account.getUserId()); - account.setUserInfo(loadUserInfo); - OrganizationsCast cast = new OrganizationsCast(); - cast.setProvider(account.getAppId()); - cast.setOrgId(loadUserInfo.getDepartmentId()); - account.setOrgCast(organizationsCastService.query(cast)); - provisionService.send( - ProvisionTopic.ACCOUNT_TOPIC, - account, - ProvisionAct.CREATE); - } - - return true; - } - return false; - } - - @Override - public boolean update(Accounts account) { - if (super.update(account)) { - if(provisionService.getApplicationConfig().isProvisionSupport()) { - UserInfo loadUserInfo = userInfoService.findUserRelated(account.getUserId()); - account.setUserInfo(loadUserInfo); - OrganizationsCast cast = new OrganizationsCast(); - cast.setProvider(account.getAppId()); - cast.setOrgId(loadUserInfo.getDepartmentId()); - account.setOrgCast(organizationsCastService.query(cast)); - provisionService.send( - ProvisionTopic.ACCOUNT_TOPIC, - account, - ProvisionAct.UPDATE); - } - - return true; - } - return false; - } + public List queryByAppIdAndDate(Accounts account) ; - public boolean updateStatus(Accounts accounts) { - return this.getMapper().updateStatus(accounts) > 0; - } + public List queryByAppIdAndAccount(String appId,String relatedUsername); - public boolean remove(String id) { - Accounts account = this.get(id); - if (super.delete(id)) { - UserInfo loadUserInfo = null; - if(provisionService.getApplicationConfig().isProvisionSupport()) { - loadUserInfo = userInfoService.findUserRelated(account.getUserId()); - account.setUserInfo(loadUserInfo); - provisionService.send( - ProvisionTopic.ACCOUNT_TOPIC, - account, - ProvisionAct.DELETE); - } - - return true; - } - return false; - } - - public void refreshByStrategy(AccountsStrategy strategy) { - if(StringUtils.isNotBlank(strategy.getOrgIdsList())) { - strategy.setOrgIdsList("'"+strategy.getOrgIdsList().replace(",", "','")+"'"); - } - List userList = queryUserNotInStrategy(strategy); - for(UserInfo user : userList) { - Accounts account = new Accounts(); - account.setAppId(strategy.getAppId()); - account.setAppName(strategy.getAppName()); - - account.setUserId(user.getId()); - account.setUsername(user.getUsername()); - account.setDisplayName(user.getDisplayName()); - account.setRelatedUsername(generateAccount(user,strategy)); - account.setRelatedPassword(PasswordReciprocal.getInstance().encode(userInfoService.randomPassword())); - - account.setInstId(strategy.getInstId()); - account.setCreateType("automatic"); - account.setStatus(ConstsStatus.ACTIVE); - account.setStrategyId(strategy.getId()); - - insert(account); - } - deleteByStrategy(strategy); - } - public void refreshAllByStrategy() { - AccountsStrategy queryStrategy = new AccountsStrategy(); - queryStrategy.setCreateType("automatic"); - for( AccountsStrategy strategy : accountsStrategyService.query(queryStrategy)) { - refreshByStrategy(strategy); - } - } - - - public List queryUserNotInStrategy(AccountsStrategy strategy){ - return getMapper().queryUserNotInStrategy(strategy); - } - - public long deleteByStrategy(AccountsStrategy strategy) { - return getMapper().deleteByStrategy(strategy); - } - - - public List queryByAppIdAndDate(Accounts account) { - return getMapper().queryByAppIdAndDate(account); - } - - public List queryByAppIdAndAccount(String appId,String relatedUsername){ - return getMapper().queryByAppIdAndAccount(appId,relatedUsername); - } - - - public String generateAccount(UserInfo userInfo,AccountsStrategy accountsStrategy) { - String shortAccount = generateAccount(userInfo,accountsStrategy,true); - String account = generateAccount(userInfo,accountsStrategy,false); - String accountResult = shortAccount; - List accountsList =getMapper().queryByAppIdAndAccount(accountsStrategy.getAppId(),shortAccount +accountsStrategy.getSuffixes()); - if(!accountsList.isEmpty()) { - if(accountsStrategy.getMapping().equalsIgnoreCase("email")) { - accountResult = account; - accountsList =getMapper().queryByAppIdAndAccount(accountsStrategy.getAppId(),account + accountsStrategy.getSuffixes()); - } - if(!accountsList.isEmpty()) { - for(int i =1 ;i < 100 ;i++) { - accountResult = account + i; - accountsList =getMapper().queryByAppIdAndAccount(accountsStrategy.getAppId(),accountResult + accountsStrategy.getSuffixes()); - if(accountsList.isEmpty()) { - break; - } - } - } - } - if(StringUtils.isNotBlank(accountsStrategy.getSuffixes())){ - accountResult = accountResult + accountsStrategy.getSuffixes(); - } - return accountResult; - } - - - private String generateAccount(UserInfo userInfo,AccountsStrategy strategy,boolean isShort) { - String account = ""; - if(strategy.getMapping().equalsIgnoreCase("username")) { - account = userInfo.getUsername(); - }else if(strategy.getMapping().equalsIgnoreCase("mobile")) { - account = userInfo.getMobile(); - }else if(strategy.getMapping().equalsIgnoreCase("email")) { - try { - if(isShort) { - account = getPinYinShortName(userInfo.getDisplayName()); - }else { - account = getPinYinName(userInfo.getDisplayName()); - } - }catch(Exception e) { - e.printStackTrace(); - } - }else if(strategy.getMapping().equalsIgnoreCase("employeeNumber")) { - account = userInfo.getEmployeeNumber(); - }else if(strategy.getMapping().equalsIgnoreCase("windowsAccount")) { - account = userInfo.getWindowsAccount(); - }else if(strategy.getMapping().equalsIgnoreCase("idCardNo")) { - account = userInfo.getIdCardNo(); - }else { - account = userInfo.getUsername(); - } - - return account; - } - - public static String getPinYinName(String name) throws BadHanyuPinyinOutputFormatCombination { - HanyuPinyinOutputFormat pinyinFormat = new HanyuPinyinOutputFormat(); - pinyinFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); - pinyinFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); - pinyinFormat.setVCharType(HanyuPinyinVCharType.WITH_V); - return PinyinHelper.toHanYuPinyinString(name, pinyinFormat, "",false); - } - - public static String getPinYinShortName(String name) throws BadHanyuPinyinOutputFormatCombination { - char[] strs = name.toCharArray(); - String pinyinName = ""; - for(int i=0;i implements Serializable { - /** - * - */ - private static final long serialVersionUID = -921086134545225302L; - - static final Logger _logger = LoggerFactory.getLogger(AccountsStrategyService.class); - /* - @Autowired - @Qualifier("groupMemberService") - GroupMemberService accountsStrategyService; - */ - public AccountsStrategyService() { - super(AccountsStrategyMapper.class); - } +public interface AccountsStrategyService extends IJpaService { - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public AccountsStrategyMapper getMapper() { - return (AccountsStrategyMapper)super.getMapper(); - } + public List queryDynamicGroups(Roles groups); - - public List queryDynamicGroups(Roles groups){ - return this.getMapper().queryDynamicGroups(groups); - } - - public boolean deleteById(String groupId) { - this.delete(groupId); - //groupMemberService.deleteByGroupId(groupId); - return true; - } - /* - public void refreshDynamicGroups(Groups dynamicGroup){ - if(dynamicGroup.getDynamic().equals("1")) { - boolean isDynamicTimeSupport = false; - boolean isBetweenEffectiveTime = false; - if(dynamicGroup.getResumeTime()!=null&&dynamicGroup.getResumeTime().equals("") - &&dynamicGroup.getSuspendTime()!=null&&dynamicGroup.getSuspendTime().equals("")) { - LocalTime currentTime = LocalDateTime.now().toLocalTime(); - LocalTime resumeTime = LocalTime.parse(dynamicGroup.getResumeTime()); - LocalTime suspendTime = LocalTime.parse(dynamicGroup.getSuspendTime()); - - _logger.info("currentTime: " + currentTime - + " , resumeTime : " + resumeTime - + " , suspendTime: " + suspendTime); - isDynamicTimeSupport = true; - - if(resumeTime.isBefore(currentTime) && currentTime.isBefore(suspendTime)) { - isBetweenEffectiveTime = true; - } - - } - - if(dynamicGroup.getOrgIdsList()!=null && !dynamicGroup.getOrgIdsList().equals("")) { - dynamicGroup.setOrgIdsList("'"+dynamicGroup.getOrgIdsList().replace(",", "','")+"'"); - } - String filters = dynamicGroup.getFilters(); - if(StringUtils.filtersSQLInjection(filters.toLowerCase())) { - _logger.info("filters include SQL Injection Attack Risk."); - return; - } - - filters = filters.replace("&", " AND "); - filters = filters.replace("|", " OR "); - - dynamicGroup.setFilters(filters); - - if(isDynamicTimeSupport) { - if(isBetweenEffectiveTime) { - groupMemberService.deleteDynamicGroupMember(dynamicGroup); - groupMemberService.addDynamicGroupMember(dynamicGroup); - }else { - groupMemberService.deleteDynamicGroupMember(dynamicGroup); - } - }else{ - groupMemberService.deleteDynamicGroupMember(dynamicGroup); - groupMemberService.addDynamicGroupMember(dynamicGroup); - } - } - }*/ - - - - + public boolean deleteById(String groupId) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsAdaptersService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsAdaptersService.java index 28145ba5..7bb06daf 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsAdaptersService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsAdaptersService.java @@ -1,5 +1,5 @@ /* - * Copyright [2021] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -18,22 +18,8 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.apps.AppsAdapters; -import org.dromara.maxkey.persistence.mapper.AppsAdaptersMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class AppsAdaptersService extends JpaService{ +public interface AppsAdaptersService extends IJpaService{ - public AppsAdaptersService() { - super(AppsAdaptersMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public AppsAdaptersMapper getMapper() { - return (AppsAdaptersMapper)super.getMapper(); - } } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsCasDetailsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsCasDetailsService.java index 57f5cf6f..514f173b 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsCasDetailsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsCasDetailsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -17,50 +17,10 @@ package org.dromara.maxkey.persistence.service; -import java.util.concurrent.TimeUnit; - import org.dromara.maxkey.entity.apps.AppsCasDetails; -import org.dromara.maxkey.persistence.mapper.AppsCasDetailsMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; +public interface AppsCasDetailsService extends IJpaService{ -@Repository -public class AppsCasDetailsService extends JpaService{ - - protected static final Cache detailsCache = - Caffeine.newBuilder() - .expireAfterWrite(30, TimeUnit.MINUTES) - .maximumSize(200000) - .build(); - - public AppsCasDetailsService() { - super(AppsCasDetailsMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public AppsCasDetailsMapper getMapper() { - return (AppsCasDetailsMapper)super.getMapper(); - } - - public AppsCasDetails getAppDetails(String id , boolean cached) { - AppsCasDetails details = null; - if(cached) { - details = detailsCache.getIfPresent(id); - if(details == null) { - details = getMapper().getAppDetails(id); - if(details != null) { - detailsCache.put(id, details); - } - } - }else { - details = getMapper().getAppDetails(id); - } - return details; - } + public AppsCasDetails getAppDetails(String id , boolean cached) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsFormBasedDetailsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsFormBasedDetailsService.java index 53636b2f..0bcb8da5 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsFormBasedDetailsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsFormBasedDetailsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -17,48 +17,10 @@ package org.dromara.maxkey.persistence.service; -import java.util.concurrent.TimeUnit; - import org.dromara.maxkey.entity.apps.AppsFormBasedDetails; -import org.dromara.maxkey.persistence.mapper.AppsFormBasedDetailsMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; +public interface AppsFormBasedDetailsService extends IJpaService{ -@Repository -public class AppsFormBasedDetailsService extends JpaService{ - - protected static final Cache detailsCache = - Caffeine.newBuilder() - .expireAfterWrite(30, TimeUnit.MINUTES) - .maximumSize(200000) - .build(); - - public AppsFormBasedDetailsService() { - super(AppsFormBasedDetailsMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public AppsFormBasedDetailsMapper getMapper() { - return (AppsFormBasedDetailsMapper)super.getMapper(); - } - - public AppsFormBasedDetails getAppDetails(String id,boolean cached) { - AppsFormBasedDetails details = null; - if(cached) { - details = detailsCache.getIfPresent(id); - if(details == null) { - details = getMapper().getAppDetails(id); - detailsCache.put(id, details); - } - }else { - details = getMapper().getAppDetails(id); - } - return details; - } + public AppsFormBasedDetails getAppDetails(String id,boolean cached) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsJwtDetailsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsJwtDetailsService.java index f6a511c7..c0c76d97 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsJwtDetailsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsJwtDetailsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -17,48 +17,10 @@ package org.dromara.maxkey.persistence.service; -import java.util.concurrent.TimeUnit; - import org.dromara.maxkey.entity.apps.AppsJwtDetails; -import org.dromara.maxkey.persistence.mapper.AppsJwtDetailsMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; +public interface AppsJwtDetailsService extends IJpaService{ -@Repository -public class AppsJwtDetailsService extends JpaService{ - - protected static final Cache detailsCache = - Caffeine.newBuilder() - .expireAfterWrite(30, TimeUnit.MINUTES) - .maximumSize(200000) - .build(); - - public AppsJwtDetailsService() { - super(AppsJwtDetailsMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public AppsJwtDetailsMapper getMapper() { - return (AppsJwtDetailsMapper)super.getMapper(); - } - - public AppsJwtDetails getAppDetails(String id , boolean cached) { - AppsJwtDetails details = null; - if(cached) { - details = detailsCache.getIfPresent(id); - if(details == null) { - details = getMapper().getAppDetails(id); - detailsCache.put(id, details); - } - }else { - details = getMapper().getAppDetails(id); - } - return details; - } + public AppsJwtDetails getAppDetails(String id , boolean cached) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsSaml20DetailsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsSaml20DetailsService.java index 9691e0b3..282368e0 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsSaml20DetailsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsSaml20DetailsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -17,48 +17,10 @@ package org.dromara.maxkey.persistence.service; -import java.util.concurrent.TimeUnit; - import org.dromara.maxkey.entity.apps.AppsSAML20Details; -import org.dromara.maxkey.persistence.mapper.AppsSaml20DetailsMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; +public interface AppsSaml20DetailsService extends IJpaService{ -@Repository -public class AppsSaml20DetailsService extends JpaService{ - - protected static final Cache detailsCache = - Caffeine.newBuilder() - .expireAfterWrite(30, TimeUnit.MINUTES) - .maximumSize(200000) - .build(); - - public AppsSaml20DetailsService() { - super(AppsSaml20DetailsMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public AppsSaml20DetailsMapper getMapper() { - return (AppsSaml20DetailsMapper)super.getMapper(); - } - - public AppsSAML20Details getAppDetails(String id , boolean cached){ - AppsSAML20Details details = null; - if(cached) { - details = detailsCache.getIfPresent(id); - if(details == null) { - details = getMapper().getAppDetails(id); - detailsCache.put(id, details); - } - }else { - details = getMapper().getAppDetails(id); - } - return details; - } + public AppsSAML20Details getAppDetails(String id , boolean cached); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsService.java index af3f31a0..afcfde14 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -18,74 +18,23 @@ package org.dromara.maxkey.persistence.service; import java.util.List; -import java.util.concurrent.TimeUnit; - import org.dromara.maxkey.entity.apps.Apps; import org.dromara.maxkey.entity.apps.UserApps; -import org.dromara.maxkey.persistence.mapper.AppsMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; - -@Repository -public class AppsService extends JpaService{ - //maxkey-mgt - public static final String MGT_APP_ID = "622076759805923328"; +public interface AppsService extends IJpaService{ - public static final String DETAIL_SUFFIX = "_detail"; + public boolean insertApp(Apps app) ; - protected static final Cache detailsCacheStore = - Caffeine.newBuilder() - .expireAfterWrite(30, TimeUnit.MINUTES) - .build(); + public boolean updateApp(Apps app) ; - public AppsService() { - super(AppsMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public AppsMapper getMapper() { - return (AppsMapper)super.getMapper(); - } + public boolean updateExtendAttr(Apps app) ; - public boolean insertApp(Apps app) { - return ((AppsMapper)super.getMapper()).insertApp(app)>0; - }; - public boolean updateApp(Apps app) { - return ((AppsMapper)super.getMapper()).updateApp(app)>0; - }; - - public boolean updateExtendAttr(Apps app) { - return ((AppsMapper)super.getMapper()).updateExtendAttr(app)>0; - } - - public List queryMyApps(UserApps userApplications){ - return getMapper().queryMyApps(userApplications); - } + public List queryMyApps(UserApps userApplications); //cache for running - public void put(String appId, Apps appDetails) { - detailsCacheStore.put(appId + DETAIL_SUFFIX, appDetails); - } + public void put(String appId, Apps appDetails) ; - public Apps get(String appId, boolean cached) { - appId = appId.equalsIgnoreCase("maxkey_mgt") ? MGT_APP_ID : appId; - Apps appDetails = null; - if(cached) { - appDetails = detailsCacheStore.getIfPresent(appId + DETAIL_SUFFIX); - if(appDetails == null) { - appDetails = this.get(appId); - detailsCacheStore.put(appId, appDetails); - } - }else { - appDetails = this.get(appId); - } - return appDetails; - } + public Apps get(String appId, boolean cached); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsTokenBasedDetailsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsTokenBasedDetailsService.java index 74531e77..703632c0 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsTokenBasedDetailsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/AppsTokenBasedDetailsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -17,48 +17,10 @@ package org.dromara.maxkey.persistence.service; -import java.util.concurrent.TimeUnit; - import org.dromara.maxkey.entity.apps.AppsTokenBasedDetails; -import org.dromara.maxkey.persistence.mapper.AppsTokenBasedDetailsMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; +public interface AppsTokenBasedDetailsService extends IJpaService{ -@Repository -public class AppsTokenBasedDetailsService extends JpaService{ - - protected static final Cache detailsCache = - Caffeine.newBuilder() - .expireAfterWrite(30, TimeUnit.MINUTES) - .maximumSize(200000) - .build(); - - public AppsTokenBasedDetailsService() { - super(AppsTokenBasedDetailsMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public AppsTokenBasedDetailsMapper getMapper() { - return (AppsTokenBasedDetailsMapper)super.getMapper(); - } - - public AppsTokenBasedDetails getAppDetails(String id , boolean cached) { - AppsTokenBasedDetails details = null; - if(cached) { - details = detailsCache.getIfPresent(id); - if(details == null) { - details = getMapper().getAppDetails(id); - detailsCache.put(id, details); - } - }else { - details = getMapper().getAppDetails(id); - } - return details; - } + public AppsTokenBasedDetails getAppDetails(String id , boolean cached) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfEmailSendersService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfEmailSendersService.java index 5b958bd7..f0d21048 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfEmailSendersService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfEmailSendersService.java @@ -1,5 +1,5 @@ /* - * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -19,25 +19,9 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.cnf.CnfEmailSenders; -import org.dromara.maxkey.persistence.mapper.CnfEmailSendersMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; +public interface CnfEmailSendersService extends IJpaService{ -@Repository -public class CnfEmailSendersService extends JpaService{ - - public CnfEmailSendersService() { - super(CnfEmailSendersMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public CnfEmailSendersMapper getMapper() { - return (CnfEmailSendersMapper)super.getMapper(); - } - } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfLdapContextService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfLdapContextService.java index a2b01701..7c51e708 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfLdapContextService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfLdapContextService.java @@ -1,5 +1,5 @@ /* - * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -18,25 +18,9 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.cnf.CnfLdapContext; -import org.dromara.maxkey.persistence.mapper.CnfLdapContextMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class CnfLdapContextService extends JpaService{ - - public CnfLdapContextService() { - super(CnfLdapContextMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public CnfLdapContextMapper getMapper() { - return (CnfLdapContextMapper)super.getMapper(); - } +public interface CnfLdapContextService extends IJpaService{ - } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfPasswordPolicyService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfPasswordPolicyService.java index 120f567a..756108dc 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfPasswordPolicyService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfPasswordPolicyService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -18,23 +18,8 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy; -import org.dromara.maxkey.persistence.mapper.CnfPasswordPolicyMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class CnfPasswordPolicyService extends JpaService{ - - public CnfPasswordPolicyService() { - super(CnfPasswordPolicyMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public CnfPasswordPolicyMapper getMapper() { - return (CnfPasswordPolicyMapper)super.getMapper(); - } +public interface CnfPasswordPolicyService extends IJpaService{ } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfSmsProviderService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfSmsProviderService.java index 5d12b556..a2fac18f 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfSmsProviderService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/CnfSmsProviderService.java @@ -18,25 +18,9 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.cnf.CnfSmsProvider; -import org.dromara.maxkey.persistence.mapper.CnfSmsProviderMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class CnfSmsProviderService extends JpaService{ +public interface CnfSmsProviderService extends IJpaService{ - public CnfSmsProviderService() { - super(CnfSmsProviderMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public CnfSmsProviderMapper getMapper() { - return (CnfSmsProviderMapper)super.getMapper(); - } - - } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ConnectorsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ConnectorsService.java index 9551a0db..be89a029 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ConnectorsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ConnectorsService.java @@ -18,25 +18,8 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.Connectors; -import org.dromara.maxkey.persistence.mapper.ConnectorsMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class ConnectorsService extends JpaService{ - static final Logger _logger = LoggerFactory.getLogger(ConnectorsService.class); - - public ConnectorsService() { - super(ConnectorsMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public ConnectorsMapper getMapper() { - return (ConnectorsMapper)super.getMapper(); - } +public interface ConnectorsService extends IJpaService{ + } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/FileUploadService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/FileUploadService.java index cb740cc0..535a671a 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/FileUploadService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/FileUploadService.java @@ -18,22 +18,8 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.FileUpload; -import org.dromara.maxkey.persistence.mapper.FileUploadMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class FileUploadService extends JpaService{ +public interface FileUploadService extends IJpaService{ - public FileUploadService() { - super(FileUploadMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public FileUploadMapper getMapper() { - return (FileUploadMapper)super.getMapper(); - } } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/GroupMemberService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/GroupMemberService.java index e52b8eb3..6fd744d6 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/GroupMemberService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/GroupMemberService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -22,68 +22,19 @@ import java.util.List; import org.dromara.maxkey.entity.idm.GroupMember; import org.dromara.maxkey.entity.idm.Groups; import org.dromara.maxkey.entity.idm.UserInfo; -import org.dromara.maxkey.persistence.mapper.GroupMemberMapper; -import org.dromara.mybatis.jpa.JpaService; +import org.dromara.mybatis.jpa.IJpaService; import org.dromara.mybatis.jpa.entity.JpaPageResults; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Repository; -@Repository -public class GroupMemberService extends JpaService{ - static final Logger _logger = LoggerFactory.getLogger(GroupMemberService.class); +public interface GroupMemberService extends IJpaService{ + + public int addDynamicMember(Groups dynamicGroup) ; - public GroupMemberService() { - super(GroupMemberMapper.class); - } + public int deleteDynamicMember(Groups dynamicGroup) ; - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public GroupMemberMapper getMapper() { - return (GroupMemberMapper)super.getMapper(); - } + public int deleteByGroupId(String groupId); - public int addDynamicMember(Groups dynamicGroup) { - return getMapper().addDynamicMember(dynamicGroup); - } + public List queryMemberByGroupId(String groupId); - public int deleteDynamicMember(Groups dynamicGroup) { - return getMapper().deleteDynamicMember(dynamicGroup); - } - - public int deleteByGroupId(String groupId) { - return getMapper().deleteByGroupId(groupId); - } - - public List queryMemberByGroupId(String groupId){ - return getMapper().queryMemberByGroupId(groupId); - } - - - public JpaPageResults noMember(GroupMember entity) { - entity.setPageSelectId(entity.generateId()); - entity.setStartRow(calculateStartRow(entity.getPageNumber() ,entity.getPageSize())); - - entity.setPageable(true); - List resultslist = null; - try { - resultslist = getMapper().noMember(entity); - } catch (Exception e) { - _logger.error("queryPageResults Exception " , e); - } - entity.setPageable(false); - Integer totalPage = resultslist.size(); - - Integer totalCount = 0; - if(entity.getPageNumber() == 1 && totalPage < entity.getPageSize()) { - totalCount = totalPage; - }else { - totalCount = parseCount(getMapper().fetchCount(entity)); - } - - return new JpaPageResults(entity.getPageNumber(),entity.getPageSize(),totalPage,totalCount,resultslist); - } + public JpaPageResults noMember(GroupMember entity) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/GroupsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/GroupsService.java index 1a11b1c4..5bb6ffe6 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/GroupsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/GroupsService.java @@ -17,108 +17,21 @@ package org.dromara.maxkey.persistence.service; -import java.sql.Types; import java.util.List; -import org.apache.commons.lang3.StringUtils; -import org.dromara.maxkey.constants.ConstsStatus; -import org.dromara.maxkey.entity.Institutions; import org.dromara.maxkey.entity.idm.Groups; -import org.dromara.maxkey.entity.permissions.Roles; -import org.dromara.maxkey.persistence.mapper.GroupsMapper; -import org.dromara.maxkey.util.StrUtils; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class GroupsService extends JpaService{ - static final Logger _logger = LoggerFactory.getLogger(GroupsService.class); +public interface GroupsService extends IJpaService{ - @Autowired - GroupMemberService groupMemberService; - - @Autowired - InstitutionsService institutionsService; - - public GroupsService() { - super(GroupsMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public GroupsMapper getMapper() { - return (GroupsMapper)super.getMapper(); - } + public List queryDynamicGroups(Groups groups); + public boolean deleteById(String groupId) ; - public List queryDynamicGroups(Groups groups){ - return this.getMapper().queryDynamic(groups); - } + public List queryByUserId(String userId); - public boolean deleteById(String groupId) { - this.delete(groupId); - groupMemberService.deleteByGroupId(groupId); - return true; - } + public void refreshDynamicGroups(Groups dynamicGroup); - public List queryByUserId(String userId){ - return this.getMapper().queryByUserId(userId); - } - - public void refreshDynamicGroups(Groups dynamicGroup){ - if(dynamicGroup.getCategory().equals(Roles.Category.DYNAMIC)) { - - if(StringUtils.isNotBlank(dynamicGroup.getOrgIdsList())) { - String []orgIds = dynamicGroup.getOrgIdsList().split(","); - StringBuffer orgIdFilters = new StringBuffer(); - for(String orgId : orgIds) { - if(StringUtils.isNotBlank(orgId)) { - if(orgIdFilters.length() > 0) { - orgIdFilters.append(","); - } - orgIdFilters.append("'").append(orgId).append("'"); - } - } - if(orgIdFilters.length() > 0) { - dynamicGroup.setOrgIdsList(orgIdFilters.toString()); - } - } - - String filters = dynamicGroup.getFilters(); - if(StringUtils.isNotBlank(filters)) { - if(StrUtils.filtersSQLInjection(filters.toLowerCase())) { - _logger.info("filters include SQL Injection Attack Risk."); - return; - } - //replace & with AND, | with OR - filters = filters.replace("&", " AND ").replace("|", " OR "); - - dynamicGroup.setFilters(filters); - } - - groupMemberService.deleteDynamicMember(dynamicGroup); - groupMemberService.addDynamicMember(dynamicGroup); - - } - } - - public void refreshAllDynamicGroups(){ - List instList = - institutionsService.find("where status = ? ", new Object[]{ConstsStatus.ACTIVE}, new int[]{Types.INTEGER}); - for(Institutions inst : instList) { - Groups group = new Groups(); - group.setInstId(inst.getId()); - List groupsList = queryDynamicGroups(group); - for(Groups g : groupsList) { - _logger.debug("role {}" , g); - refreshDynamicGroups(g); - } - } - } + public void refreshAllDynamicGroups(); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryConnectorService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryConnectorService.java index a7527093..b0f91cc5 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryConnectorService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryConnectorService.java @@ -18,22 +18,8 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.history.HistoryConnector; -import org.dromara.maxkey.persistence.mapper.HistoryConnectorMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class HistoryConnectorService extends JpaService{ +public interface HistoryConnectorService extends IJpaService{ - public HistoryConnectorService() { - super(HistoryConnectorMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public HistoryConnectorMapper getMapper() { - return (HistoryConnectorMapper)super.getMapper(); - } } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryLoginAppsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryLoginAppsService.java index 992e6271..ce71e54a 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryLoginAppsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryLoginAppsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -18,47 +18,8 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.history.HistoryLoginApps; -import org.dromara.maxkey.persistence.mapper.HistoryLoginAppsMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class HistoryLoginAppsService extends JpaService{ +public interface HistoryLoginAppsService extends IJpaService{ - public HistoryLoginAppsService() { - super(HistoryLoginAppsMapper.class); - } - - - @Override - public HistoryLoginAppsMapper getMapper() { - return (HistoryLoginAppsMapper)super.getMapper(); - } - - @Override - public boolean insert(HistoryLoginApps loginAppsHistory){ - //new Thread insert login app history - new Thread(new HistoryLoginAppsRunnable(getMapper(),loginAppsHistory)).start(); - return true; - } - - public class HistoryLoginAppsRunnable implements Runnable{ - - HistoryLoginAppsMapper historyLoginAppsMapper; - - HistoryLoginApps loginAppsHistory; - - public HistoryLoginAppsRunnable(HistoryLoginAppsMapper historyLoginAppsMapper, - HistoryLoginApps loginAppsHistory) { - super(); - this.historyLoginAppsMapper = historyLoginAppsMapper; - this.loginAppsHistory = loginAppsHistory; - } - - @Override - public void run() { - historyLoginAppsMapper.insert(loginAppsHistory); - } - - } } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryLoginService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryLoginService.java index 5d9b2483..fc1022c4 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryLoginService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistoryLoginService.java @@ -18,27 +18,10 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.history.HistoryLogin; -import org.dromara.maxkey.persistence.mapper.HistoryLoginMapper; -import org.dromara.mybatis.jpa.JpaService; +import org.dromara.mybatis.jpa.IJpaService; import org.dromara.mybatis.jpa.entity.JpaPageResults; -import org.springframework.stereotype.Repository; -@Repository -public class HistoryLoginService extends JpaService{ +public interface HistoryLoginService extends IJpaService{ - public HistoryLoginService() { - super(HistoryLoginMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public HistoryLoginMapper getMapper() { - return (HistoryLoginMapper)super.getMapper(); - } - - public JpaPageResults queryOnlineSession(HistoryLogin historyLogin) { - return this.fetchPageResults("queryOnlineSession",historyLogin); - } + public JpaPageResults queryOnlineSession(HistoryLogin historyLogin); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistorySynchronizerService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistorySynchronizerService.java index 329f8c8a..acc1387a 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistorySynchronizerService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistorySynchronizerService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -18,22 +18,8 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.history.HistorySynchronizer; -import org.dromara.maxkey.persistence.mapper.HistorySynchronizerMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class HistorySynchronizerService extends JpaService{ +public interface HistorySynchronizerService extends IJpaService{ - public HistorySynchronizerService() { - super(HistorySynchronizerMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public HistorySynchronizerMapper getMapper() { - return (HistorySynchronizerMapper)super.getMapper(); - } } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistorySystemLogsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistorySystemLogsService.java index fcc57435..77c5cab2 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistorySystemLogsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/HistorySystemLogsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -17,193 +17,14 @@ package org.dromara.maxkey.persistence.service; -import org.dromara.maxkey.entity.Accounts; -import org.dromara.maxkey.entity.ChangePassword; - -import java.util.Date; - -import org.dromara.maxkey.entity.Access; -import org.dromara.maxkey.entity.SocialsProvider; -import org.dromara.maxkey.entity.Synchronizers; import org.dromara.maxkey.entity.history.HistorySystemLogs; -import org.dromara.maxkey.entity.idm.Organizations; import org.dromara.maxkey.entity.idm.UserInfo; -import org.dromara.maxkey.entity.permissions.Permission; -import org.dromara.maxkey.entity.permissions.Resources; -import org.dromara.maxkey.entity.permissions.RoleMember; -import org.dromara.maxkey.entity.permissions.Roles; -import org.dromara.maxkey.persistence.mapper.HistorySystemLogsMapper; -import org.dromara.maxkey.util.JsonUtils; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class HistorySystemLogsService extends JpaService{ - static final Logger _logger = LoggerFactory.getLogger(HistorySystemLogsService.class); +public interface HistorySystemLogsService extends IJpaService{ - public HistorySystemLogsService() { - super(HistorySystemLogsMapper.class); - - } - - @Override - public HistorySystemLogsMapper getMapper() { - return (HistorySystemLogsMapper)super.getMapper(); - } + public void insert(String topic,Object entity,String action,String result,UserInfo operator) ; - public void insert(String topic,Object entity,String action,String result,UserInfo operator) { - String message = ""; - if(entity != null) { - if(entity instanceof UserInfo userInfo) { - message = buildMsg(userInfo); - }else if(entity instanceof Organizations organization) { - message = buildMsg(organization); - }else if(entity instanceof ChangePassword changePassword) { - message = buildMsg(changePassword); - }else if(entity instanceof Accounts account) { - message = buildMsg(account); - }else if(entity instanceof Roles role) { - message = buildMsg(role); - }else if(entity instanceof RoleMember roleMember) { - message = buildMsg(roleMember); - }else if(entity instanceof Access access) { - message = buildMsg(access); - }else if(entity instanceof Resources resource) { - message = buildMsg(resource); - }else if(entity instanceof Synchronizers synchronizer) { - message = buildMsg(synchronizer); - }else if(entity instanceof SocialsProvider socialsProvider) { - message = buildMsg(socialsProvider); - }else if(entity instanceof Permission permission) { - message = buildMsg(permission); - }else if(entity instanceof String) { - message = entity.toString(); - } - - } - - insert(topic,message,action,result,operator, entity); - } - - public void insert(String topic,String message,String action,String result,UserInfo operator,Object entity) { - HistorySystemLogs systemLog = new HistorySystemLogs(); - systemLog.setId(systemLog.generateId()); - systemLog.setTopic(topic); - systemLog.setMessage(message); - systemLog.setMessageAction(action); - systemLog.setMessageResult(result); - systemLog.setUserId(operator.getId()); - systemLog.setUsername(operator.getUsername()); - systemLog.setDisplayName(operator.getDisplayName()); - systemLog.setInstId(operator.getInstId()); - systemLog.setJsonCotent(JsonUtils.gsonToString(entity)); - systemLog.setExecuteTime(new Date()); - _logger.trace("System Log {}" ,systemLog); - getMapper().insert(systemLog); - } - - public String buildMsg(UserInfo userInfo) { - return new StringBuilder() - .append(userInfo.getDisplayName()) - .append("[") - .append(userInfo.getUsername()) - .append("]") - .toString(); - } - - public String buildMsg(Organizations org) { - return new StringBuilder() - .append(org.getOrgName()) - .append("[") - .append(org.getOrgCode()) - .append("]") - .toString(); - } - - public String buildMsg(Accounts account) { - return new StringBuilder() - .append(account.getRelatedUsername()) - .append("[") - .append(account.getDisplayName()).append(",") - .append(account.getUsername()).append(",") - .append(account.getAppName()) - .append("]") - .toString(); - } - - public String buildMsg(ChangePassword changePassword) { - return new StringBuilder() - .append(changePassword.getDisplayName()) - .append("[") - .append(changePassword.getUsername()) - .append("]") - .toString(); - } - - public String buildMsg(Roles g) { - return new StringBuilder() - .append(g.getRoleName()) - .toString(); - } - - public String buildMsg(RoleMember rm) { - return new StringBuilder() - .append(rm.getRoleName()) - .append("[") - .append(rm.getUsername()).append(",") - .append(rm.getDisplayName()) - .append("]") - .toString(); - } - - public String buildMsg(Access permission) { - return new StringBuilder() - .append(permission.getGroupName()) - .append("[") - .append(permission.getAppName()) - .append("]") - .toString(); - } - - public String buildMsg(Permission privilege) { - return new StringBuilder() - .append(privilege.getGroupId()) - .append("[") - .append(privilege.getResourceId()) - .append("]") - .toString(); - } - - - public String buildMsg(Resources r) { - return new StringBuilder() - .append(r.getResourceName()) - .append("[") - .append(r.getResourceType()) - .append("]") - .toString(); - } - - - public String buildMsg(Synchronizers s) { - return new StringBuilder() - .append(s.getName()) - .append("[") - .append(s.getSourceType()).append(",") - .append(s.getScheduler()).append(",") - .append("]") - .toString(); - } - - public String buildMsg(SocialsProvider s) { - return new StringBuilder() - .append(s.getProviderName()) - .append("[") - .append(s.getProvider()) - .append("]") - .toString(); - } + public void insert(String topic,String message,String action,String result,UserInfo operator,Object entity) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/InstitutionsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/InstitutionsService.java index d8d3b0a3..57b098af 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/InstitutionsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/InstitutionsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -18,28 +18,10 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.Institutions; -import org.dromara.maxkey.persistence.mapper.InstitutionsMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; +public interface InstitutionsService extends IJpaService{ -@Repository -public class InstitutionsService extends JpaService{ - - public InstitutionsService() { - super(InstitutionsMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public InstitutionsMapper getMapper() { - return (InstitutionsMapper)super.getMapper(); - } - - public Institutions findByDomain(String domain) { - return getMapper().findByDomain(domain); - } + public Institutions findByDomain(String domain) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/OrganizationsCastService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/OrganizationsCastService.java index 3d854b9b..09d1bdac 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/OrganizationsCastService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/OrganizationsCastService.java @@ -18,33 +18,10 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.OrganizationsCast; -import org.dromara.maxkey.persistence.mapper.OrganizationsCastMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; +public interface OrganizationsCastService extends IJpaService{ -@Repository -public class OrganizationsCastService extends JpaService{ - - static final Logger _logger = LoggerFactory.getLogger(OrganizationsCastService.class); - - - public OrganizationsCastService() { - super(OrganizationsCastMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public OrganizationsCastMapper getMapper() { - return (OrganizationsCastMapper)super.getMapper(); - } - - public boolean updateCast(OrganizationsCast organizationsCast) { - return getMapper().updateCast(organizationsCast) > 0; - } + public boolean updateCast(OrganizationsCast organizationsCast) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/OrganizationsService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/OrganizationsService.java index 063df3c2..c8c85c60 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/OrganizationsService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/OrganizationsService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -17,172 +17,20 @@ package org.dromara.maxkey.persistence.service; -import java.sql.Types; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import org.apache.commons.lang3.StringUtils; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellType; import org.dromara.maxkey.entity.idm.Organizations; -import org.dromara.maxkey.persistence.mapper.OrganizationsMapper; -import org.dromara.maxkey.provision.ProvisionAct; -import org.dromara.maxkey.provision.ProvisionService; -import org.dromara.maxkey.provision.ProvisionTopic; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class OrganizationsService extends JpaService{ - static final Logger _logger = LoggerFactory.getLogger(OrganizationsService.class); - - @Autowired - ProvisionService provisionService; - - public OrganizationsService() { - super(OrganizationsMapper.class); - } +public interface OrganizationsService extends IJpaService{ - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public OrganizationsMapper getMapper() { - return (OrganizationsMapper)super.getMapper(); - } - - @Override - public boolean insert(Organizations organization) { - if(super.insert(organization)){ - provisionService.send( - ProvisionTopic.ORG_TOPIC, organization, ProvisionAct.CREATE); - return true; - } - return false; - } + public void saveOrUpdate(Organizations organization) ; - @Override - public boolean update(Organizations organization) { - if(super.update(organization)){ - provisionService.send( - ProvisionTopic.ORG_TOPIC, organization, ProvisionAct.UPDATE); - return true; - } - return false; - } - - public void saveOrUpdate(Organizations organization) { - Organizations loadOrg =findOne(" id = ? and instid = ?", - new Object[] { organization.getId(), organization.getInstId() }, - new int[] { Types.VARCHAR, Types.VARCHAR }); - if( loadOrg == null) { - insert(organization); - }else { - organization.setId(organization.getId()); - update(organization); - } - } - public List queryOrgs(Organizations organization){ - return getMapper().queryOrgs(organization); - } + public List queryOrgs(Organizations organization); - public boolean delete(Organizations organization) { - if(super.delete(organization.getId())){ - provisionService.send( - ProvisionTopic.ORG_TOPIC, organization, ProvisionAct.DELETE); - return true; - } - return false; - } + public boolean delete(Organizations organization) ; + public void reorgNamePath(String instId) ; - public void reorgNamePath(String instId) { - _logger.debug("instId {}", instId); - if (StringUtils.isBlank(instId)) { - instId = "1"; - } - - HashMap reorgOrgMap = new HashMap<>(); - List orgList = find(" where instid ='" + instId + "'"); - List originOrgList = new ArrayList<>(); - Organizations rootOrg = null; - for (Organizations org : orgList) { - reorgOrgMap.put(org.getId(), org); - if (isRootOrg(org)) { - rootOrg = org; - } - Organizations cloneOrg = new Organizations(); - BeanUtils.copyProperties(org, cloneOrg); - originOrgList.add(cloneOrg); - } - try { - reorg(reorgOrgMap, orgList, rootOrg); - _logger.debug("reorged ."); - long reorgCount = 0; - for (Organizations originOrg : originOrgList) { - Organizations reorgOrg = reorgOrgMap.get(originOrg.getId()); - _logger.trace("reorged Organization {}", reorgOrg); - if (originOrg.getNamePath() == null || !originOrg.getNamePath().equals(reorgOrg.getNamePath())) { - _logger.debug("update reorgCount {} , Organization {}", ++reorgCount, reorgOrg); - getMapper().updateNamePath(reorgOrg); - } - } - _logger.debug("reorg finished ."); - } catch (Exception e) { - _logger.error("reorgNamePath Exception ", e); - } - } - - boolean isRootOrg(Organizations rootOrg) { - if (rootOrg.getParentId() == null || rootOrg.getParentId().equalsIgnoreCase("-1") - || rootOrg.getParentId().equalsIgnoreCase(rootOrg.getId()) - || rootOrg.getParentId().equalsIgnoreCase(rootOrg.getInstId())) { - return true; - } - return false; - } - - void reorg(HashMap orgMap, List orgList, Organizations rootOrg) { - if (isRootOrg(rootOrg)) { - rootOrg.setCodePath("/" + rootOrg.getId() + "/"); - rootOrg.setNamePath("/" + rootOrg.getOrgName() + "/"); - } else { - Organizations parent = orgMap.get(rootOrg.getParentId()); - rootOrg.setCodePath(parent.getCodePath() + rootOrg.getId() + "/"); - rootOrg.setNamePath(parent.getNamePath() + rootOrg.getOrgName() + "/"); - } - rootOrg.setReorgNamePath(true); - - for (Organizations org : orgList) { - if (org.isReorgNamePath()) - continue; - if (org.getParentId().equalsIgnoreCase(rootOrg.getId())) { - reorg(orgMap, orgList, org); - } - } - } - /** - * 根据数据格式返回数据 - * - * @param cell - * @return - */ - public static String getValue(Cell cell) { - if (cell == null) { - return ""; - } else if (cell.getCellType() == CellType.BOOLEAN) { - return String.valueOf(cell.getBooleanCellValue()); - } else if (cell.getCellType() == CellType.NUMERIC) { - cell.setBlank(); - return String.valueOf(cell.getStringCellValue().trim()); - } else { - return String.valueOf(cell.getStringCellValue().trim()); - } - } } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/PermissionRoleService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/PermissionRoleService.java index 168abcf1..5aa4a0db 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/PermissionRoleService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/PermissionRoleService.java @@ -21,36 +21,14 @@ package org.dromara.maxkey.persistence.service; import java.util.List; import org.dromara.maxkey.entity.permissions.PermissionRole; -import org.dromara.maxkey.persistence.mapper.PermissionRoleMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class PermissionRoleService extends JpaService{ - static final Logger _logger = LoggerFactory.getLogger(PermissionRoleService.class); - - - public PermissionRoleService() { - super(PermissionRoleMapper.class); - } +public interface PermissionRoleService extends IJpaService{ - @Override - public PermissionRoleMapper getMapper() { - return (PermissionRoleMapper)super.getMapper(); - } - - public boolean insertPermissionRoles(List permissionRolesList) { - return getMapper().insertPermissionRoles(permissionRolesList)>0; - } + public boolean insertPermissionRoles(List permissionRolesList); - public boolean deletePermissionRoles(List permissionRolesList) { - return getMapper().deletePermissionRoles(permissionRolesList)>=0; - } + public boolean deletePermissionRoles(List permissionRolesList) ; - public List queryPermissionRoles(PermissionRole permissionRole){ - return getMapper().queryPermissionRoles(permissionRole); - } + public List queryPermissionRoles(PermissionRole permissionRole); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/PermissionService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/PermissionService.java index 4638193f..f95c7ac3 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/PermissionService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/PermissionService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -20,39 +20,14 @@ package org.dromara.maxkey.persistence.service; import java.util.List; import org.dromara.maxkey.entity.permissions.Permission; -import org.dromara.maxkey.persistence.mapper.PermissionMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class PermissionService extends JpaService{ - static final Logger _logger = LoggerFactory.getLogger(PermissionService.class); - - - public PermissionService() { - super(PermissionMapper.class); - } +public interface PermissionService extends IJpaService{ - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public PermissionMapper getMapper() { - return (PermissionMapper)super.getMapper(); - } - - public boolean insertGroupPrivileges(List rolePermissionsList) { - return getMapper().insertGroupPrivileges(rolePermissionsList)>0; - }; + public boolean insertGroupPrivileges(List rolePermissionsList) ; - public boolean deleteGroupPrivileges(List rolePermissionsList) { - return getMapper().deleteGroupPrivileges(rolePermissionsList)>=0; - } + public boolean deleteGroupPrivileges(List rolePermissionsList); - public List queryGroupPrivileges(Permission rolePermissions){ - return getMapper().queryGroupPrivileges(rolePermissions); - } + public List queryGroupPrivileges(Permission rolePermissions); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RegisterService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RegisterService.java index 4db770ef..0a3268d7 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RegisterService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RegisterService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -17,33 +17,12 @@ package org.dromara.maxkey.persistence.service; -import java.util.List; - import org.dromara.maxkey.entity.Register; import org.dromara.maxkey.entity.idm.UserInfo; -import org.dromara.maxkey.persistence.mapper.RegisterMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class RegisterService extends JpaService{ +public interface RegisterService extends IJpaService{ - public RegisterService() { - super(RegisterMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public RegisterMapper getMapper() { - return (RegisterMapper)super.getMapper(); - } - - - public UserInfo findByEmail(String email){ - List listUserInfo=getMapper().findByEmail(email); - return listUserInfo.size()>0?listUserInfo.get(0):null; - } + public UserInfo findByEmail(String email); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ReportService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ReportService.java index 39921f39..3fdd32d0 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ReportService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ReportService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -20,59 +20,26 @@ package org.dromara.maxkey.persistence.service; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.dromara.maxkey.persistence.mapper.ReportMapper; -import org.dromara.mybatis.jpa.JpaService; +import org.dromara.mybatis.jpa.IJpaService; import org.dromara.mybatis.jpa.entity.JpaEntity; -import org.springframework.stereotype.Repository; -@Repository -public class ReportService extends JpaService{ +public interface ReportService extends IJpaService{ - public Integer analysisDay(HashMap reportParameter) { - return getMapper().analysisDay(reportParameter); - }; + public Integer analysisDay(HashMap reportParameter) ; - public Integer analysisNewUsers(HashMap reportParameter) { - return getMapper().analysisNewUsers(reportParameter); - }; + public Integer analysisNewUsers(HashMap reportParameter) ; - public Integer analysisOnlineUsers(HashMap reportParameter) { - return getMapper().analysisOnlineUsers(reportParameter); - }; + public Integer analysisOnlineUsers(HashMap reportParameter) ; - public Integer analysisActiveUsers(HashMap reportParameter) { - return getMapper().analysisActiveUsers(reportParameter); - }; + public Integer analysisActiveUsers(HashMap reportParameter); - public List> analysisDayHour(HashMap reportParameter){ - return getMapper().analysisDayHour(reportParameter); - } + public List> analysisDayHour(HashMap reportParameter); - public List> analysisMonth(HashMap reportParameter){ - return getMapper().analysisMonth(reportParameter); - } + public List> analysisMonth(HashMap reportParameter); - public List> analysisBrowser(HashMap reportParameter){ - return getMapper().analysisBrowser(reportParameter); - } + public List> analysisBrowser(HashMap reportParameter); - public List> analysisApp(HashMap reportParameter){ - return getMapper().analysisApp(reportParameter); - } - - - - public ReportService() { - super(ReportMapper.class); - - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public ReportMapper getMapper() { - return (ReportMapper)super.getMapper(); - } + public List> analysisApp(HashMap reportParameter); + } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ResourcesService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ResourcesService.java index e67ff182..936ee5dc 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ResourcesService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/ResourcesService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -20,26 +20,9 @@ package org.dromara.maxkey.persistence.service; import java.util.List; import org.dromara.maxkey.entity.permissions.Resources; -import org.dromara.maxkey.persistence.mapper.ResourcesMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class ResourcesService extends JpaService{ +public interface ResourcesService extends IJpaService{ - public ResourcesService() { - super(ResourcesMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public ResourcesMapper getMapper() { - return (ResourcesMapper)super.getMapper(); - } - - public List queryResourcesTree(Resources resource){ - return getMapper().fetchPageResults(resource); - } + public List queryResourcesTree(Resources resource); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RoleMemberService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RoleMemberService.java index e32948ea..f78ad2fc 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RoleMemberService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RoleMemberService.java @@ -23,65 +23,20 @@ import java.util.List; import org.dromara.maxkey.entity.idm.UserInfo; import org.dromara.maxkey.entity.permissions.RoleMember; import org.dromara.maxkey.entity.permissions.Roles; -import org.dromara.maxkey.persistence.mapper.RoleMemberMapper; -import org.dromara.mybatis.jpa.JpaService; +import org.dromara.mybatis.jpa.IJpaService; import org.dromara.mybatis.jpa.entity.JpaPageResults; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Repository; -@Repository -public class RoleMemberService extends JpaService{ - static final Logger _logger = LoggerFactory.getLogger(RoleMemberService.class); - - public RoleMemberService() { - super(RoleMemberMapper.class); - } +public interface RoleMemberService extends IJpaService{ - @Override - public RoleMemberMapper getMapper() { - return (RoleMemberMapper)super.getMapper(); - } + public int addDynamicRoleMember(Roles dynamicGroup); - public int addDynamicRoleMember(Roles dynamicGroup) { - return getMapper().addDynamicRoleMember(dynamicGroup); - } + public int deleteDynamicRoleMember(Roles dynamicGroup) ; - public int deleteDynamicRoleMember(Roles dynamicGroup) { - return getMapper().deleteDynamicRoleMember(dynamicGroup); - } + public int deleteByRoleId(String groupId) ; - public int deleteByRoleId(String groupId) { - return getMapper().deleteByRoleId(groupId); - } - - public List queryMemberByRoleId(String groupId){ - return getMapper().queryMemberByRoleId(groupId); - } + public List queryMemberByRoleId(String groupId); - public JpaPageResults rolesNoMember(RoleMember entity) { - entity.setPageSelectId(entity.generateId()); - entity.setStartRow(calculateStartRow(entity.getPageNumber() ,entity.getPageSize())); - - entity.setPageable(true); - List resultslist = null; - try { - resultslist = getMapper().rolesNoMember(entity); - } catch (Exception e) { - _logger.error("fetchPageResults Exception " , e); - } - entity.setPageable(false); - Integer totalPage = resultslist.size(); - - Integer totalCount = 0; - if(entity.getPageNumber() == 1 && totalPage < entity.getPageSize()) { - totalCount = totalPage; - }else { - totalCount = parseCount(getMapper().fetchCount(entity)); - } - - return new JpaPageResults(entity.getPageNumber(),entity.getPageSize(),totalPage,totalCount,resultslist); - } + public JpaPageResults rolesNoMember(RoleMember entity) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RolesService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RolesService.java index 25e2a212..8f419660 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RolesService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/RolesService.java @@ -19,106 +19,21 @@ package org.dromara.maxkey.persistence.service; -import java.sql.Types; import java.util.List; -import org.apache.commons.lang3.StringUtils; -import org.dromara.maxkey.constants.ConstsStatus; -import org.dromara.maxkey.entity.Institutions; import org.dromara.maxkey.entity.permissions.Roles; -import org.dromara.maxkey.persistence.mapper.RolesMapper; -import org.dromara.maxkey.util.StrUtils; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class RolesService extends JpaService { - static final Logger _logger = LoggerFactory.getLogger(RolesService.class); - - @Autowired - RoleMemberService roleMemberService; - - @Autowired - InstitutionsService institutionsService; - - public RolesService() { - super(RolesMapper.class); - } +public interface RolesService extends IJpaService { - @Override - public RolesMapper getMapper() { - return (RolesMapper)super.getMapper(); - } + public List queryDynamicRoles(Roles groups); + public boolean deleteById(String groupId); - public List queryDynamicRoles(Roles groups){ - return this.getMapper().queryDynamicRoles(groups); - } + public List queryRolesByUserId(String userId); - public boolean deleteById(String groupId) { - this.delete(groupId); - roleMemberService.deleteByRoleId(groupId); - return true; - } + public void refreshDynamicRoles(Roles dynamicRole); - public List queryRolesByUserId(String userId){ - return this.getMapper().queryRolesByUserId(userId); - } - - public void refreshDynamicRoles(Roles dynamicRole){ - if(dynamicRole.getCategory().equals(Roles.Category.DYNAMIC)) { - - if(StringUtils.isNotBlank(dynamicRole.getOrgIdsList())) { - String []orgIds = dynamicRole.getOrgIdsList().split(","); - StringBuffer orgIdFilters = new StringBuffer(); - for(String orgId : orgIds) { - if(StringUtils.isNotBlank(orgId)) { - if(orgIdFilters.length() > 0) { - orgIdFilters.append(","); - } - orgIdFilters.append("'").append(orgId).append("'"); - } - } - if(orgIdFilters.length() > 0) { - dynamicRole.setOrgIdsList(orgIdFilters.toString()); - } - } - - String filters = dynamicRole.getFilters(); - _logger.debug("filters {}" , filters); - if(StringUtils.isNotBlank(filters)) { - if(StrUtils.filtersSQLInjection(filters.toLowerCase())) { - _logger.info("filters include SQL Injection Attack Risk."); - return; - } - //replace & with AND, | with OR - filters = filters.replace("&", " AND ").replace("\\|", " OR "); - - _logger.debug("set filters {}" , filters); - dynamicRole.setFilters(filters); - } - - roleMemberService.deleteDynamicRoleMember(dynamicRole); - roleMemberService.addDynamicRoleMember(dynamicRole); - - } - } - - public void refreshAllDynamicRoles(){ - List instList = - institutionsService.find("where status = ? ", new Object[]{ConstsStatus.ACTIVE}, new int[]{Types.INTEGER}); - for(Institutions inst : instList) { - Roles role = new Roles(); - role.setInstId(inst.getId()); - List rolesList = queryDynamicRoles(role); - for(Roles r : rolesList) { - _logger.debug("role {}" , r); - refreshDynamicRoles(r); - } - } - } + public void refreshAllDynamicRoles(); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SocialsAssociatesService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SocialsAssociatesService.java index b6a4f070..6dd44462 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SocialsAssociatesService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SocialsAssociatesService.java @@ -21,29 +21,11 @@ import java.util.List; import org.dromara.maxkey.entity.SocialsAssociate; import org.dromara.maxkey.entity.idm.UserInfo; -import org.dromara.maxkey.persistence.mapper.SocialsAssociateMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class SocialsAssociatesService extends JpaService{ - - public SocialsAssociatesService() { - super(SocialsAssociateMapper.class); - } +public interface SocialsAssociatesService extends IJpaService{ - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public SocialsAssociateMapper getMapper() { - return (SocialsAssociateMapper)super.getMapper(); - } - - - public List queryByUser(UserInfo user) { - return getMapper().queryByUser(user); - } + public List queryByUser(UserInfo user); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SocialsProviderService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SocialsProviderService.java index 395fd941..ed51f78a 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SocialsProviderService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SocialsProviderService.java @@ -18,28 +18,8 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.SocialsProvider; -import org.dromara.maxkey.persistence.mapper.SocialsProviderMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class SocialsProviderService extends JpaService{ - static final Logger _logger = LoggerFactory.getLogger(SocialsProviderService.class); - - - public SocialsProviderService() { - super(SocialsProviderMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public SocialsProviderMapper getMapper() { - return (SocialsProviderMapper)super.getMapper(); - } - +public interface SocialsProviderService extends IJpaService{ } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SynchroRelatedService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SynchroRelatedService.java index bcd31b53..523a0023 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SynchroRelatedService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SynchroRelatedService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -17,61 +17,19 @@ package org.dromara.maxkey.persistence.service; -import java.sql.Types; -import java.util.Date; import java.util.List; import org.dromara.maxkey.entity.SynchroRelated; import org.dromara.maxkey.entity.Synchronizers; -import org.dromara.maxkey.entity.idm.Organizations; -import org.dromara.maxkey.persistence.mapper.SynchroRelatedMapper; -import org.dromara.maxkey.util.DateUtils; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Repository; +import org.dromara.mybatis.jpa.IJpaService; -@Repository -public class SynchroRelatedService extends JpaService{ +public interface SynchroRelatedService extends IJpaService{ - public SynchroRelatedService() { - super(SynchroRelatedMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public SynchroRelatedMapper getMapper() { - return (SynchroRelatedMapper)super.getMapper(); - } + public int updateSyncTime(SynchroRelated synchroRelated); - public int updateSyncTime(SynchroRelated synchroRelated) { - return getMapper().updateSyncTime(synchroRelated); - } + public List findOrgs(Synchronizers synchronizer) ; - public List findOrgs(Synchronizers synchronizer) { - return find( - "instid = ? and syncid = ? and objecttype = ? ", - new Object[] { synchronizer.getInstId() ,synchronizer.getId(),Organizations.CLASS_TYPE}, - new int[] { Types.VARCHAR,Types.VARCHAR,Types.VARCHAR} - ); - } + public SynchroRelated findByOriginId(Synchronizers synchronizer,String originId,String classType) ; - public SynchroRelated findByOriginId(Synchronizers synchronizer,String originId,String classType) { - return findOne("instid = ? and syncId = ? and originid = ? and objecttype = ? ", - new Object[] { synchronizer.getInstId(),synchronizer.getId(),originId,classType }, - new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,Types.VARCHAR}); - } - - public void updateSynchroRelated(Synchronizers synchronizer,SynchroRelated synchroRelated,String classType) { - SynchroRelated loadSynchroRelated = - findByOriginId( - synchronizer,synchroRelated.getOriginId(),classType ); - if(loadSynchroRelated == null) { - insert(synchroRelated); - }else { - synchroRelated.setId(loadSynchroRelated.getId()); - synchroRelated.setSyncTime(DateUtils.formatDateTime(new Date())); - updateSyncTime(synchroRelated); - } - } + public void updateSynchroRelated(Synchronizers synchronizer,SynchroRelated synchroRelated,String classType) ; } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SynchronizersService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SynchronizersService.java index 5ad0a6fe..faaddec1 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SynchronizersService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/SynchronizersService.java @@ -18,30 +18,8 @@ package org.dromara.maxkey.persistence.service; import org.dromara.maxkey.entity.Synchronizers; -import org.dromara.maxkey.persistence.mapper.SynchronizersMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Repository; - -@Repository -public class SynchronizersService extends JpaService{ - static final Logger _logger = LoggerFactory.getLogger(SynchronizersService.class); - - public SynchronizersService() { - super(SynchronizersMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public SynchronizersMapper getMapper() { - return (SynchronizersMapper)super.getMapper(); - } - - - +import org.dromara.mybatis.jpa.IJpaService; +public interface SynchronizersService extends IJpaService{ } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/UserInfoService.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/UserInfoService.java index fa8d0092..3440de4d 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/UserInfoService.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/UserInfoService.java @@ -1,5 +1,5 @@ /* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top] + * 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. @@ -18,242 +18,42 @@ package org.dromara.maxkey.persistence.service; -import java.sql.Types; -import java.util.Date; - -import org.apache.commons.lang3.StringUtils; -import org.dromara.maxkey.constants.ConstsStatus; -import org.dromara.maxkey.crypto.password.PasswordReciprocal; -import org.dromara.maxkey.entity.Accounts; import org.dromara.maxkey.entity.ChangePassword; import org.dromara.maxkey.entity.idm.UserInfo; -import org.dromara.maxkey.persistence.mapper.UserInfoMapper; import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator; -import org.dromara.maxkey.provision.ProvisionAct; -import org.dromara.maxkey.provision.ProvisionService; -import org.dromara.maxkey.provision.ProvisionTopic; -import org.dromara.maxkey.web.WebContext; -import org.dromara.mybatis.jpa.JpaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Repository; - +import org.dromara.mybatis.jpa.IJpaService; /** * @author Crystal.Sea * */ -@Repository -public class UserInfoService extends JpaService { - static final Logger _logger = LoggerFactory.getLogger(UserInfoService.class); +public interface UserInfoService extends IJpaService { - @Autowired - private PasswordEncoder passwordEncoder; + public boolean insert(UserInfo userInfo,boolean passwordEncoder) ; - @Autowired - PasswordPolicyValidator passwordPolicyValidator; - - @Autowired - ProvisionService provisionService; - - AccountsService accountsService; - - public UserInfoService() { - super(UserInfoMapper.class); - } - - /* (non-Javadoc) - * @see com.connsec.db.service.BaseService#getMapper() - */ - @Override - public UserInfoMapper getMapper() { - return (UserInfoMapper)super.getMapper(); - } - - @Override - public boolean insert(UserInfo userInfo) { - this.passwordEncoder(userInfo); - if (super.insert(userInfo)) { - if(provisionService.getApplicationConfig().isProvisionSupport()) { - UserInfo loadUserInfo = findUserRelated(userInfo.getId()); - provisionService.send( - ProvisionTopic.USERINFO_TOPIC, - loadUserInfo, - ProvisionAct.CREATE); - } - - return true; - } - - return false; - } - - public boolean insert(UserInfo userInfo,boolean passwordEncoder) { - if(passwordEncoder) { - this.passwordEncoder(userInfo); - } - if (super.insert(userInfo)) { - if(provisionService.getApplicationConfig().isProvisionSupport()) { - UserInfo loadUserInfo = findUserRelated(userInfo.getId()); - provisionService.send( - ProvisionTopic.USERINFO_TOPIC, - loadUserInfo, - ProvisionAct.CREATE); - } - - return true; - } - - return false; - } - - @Override - public boolean update(UserInfo userInfo) { - ChangePassword changePassword = this.passwordEncoder(userInfo); - if (super.update(userInfo)) { - if(provisionService.getApplicationConfig().isProvisionSupport()) { - UserInfo loadUserInfo = findUserRelated(userInfo.getId()); - accountUpdate(loadUserInfo); - provisionService.send( - ProvisionTopic.USERINFO_TOPIC, - loadUserInfo, - ProvisionAct.UPDATE); - } - if(userInfo.getPassword() != null) { - changePasswordProvisioning(changePassword); - } - return true; - } - return false; - } - - public boolean delete(UserInfo userInfo) { - UserInfo loadUserInfo = null; - if(provisionService.getApplicationConfig().isProvisionSupport()) { - loadUserInfo = findUserRelated(userInfo.getId()); - } - - if( super.delete(userInfo.getId())){ - provisionService.send( - ProvisionTopic.USERINFO_TOPIC, - loadUserInfo, - ProvisionAct.DELETE); - accountUpdate(loadUserInfo); - return true; - } - return false; - } + public boolean delete(UserInfo userInfo) ; //更新账号状态 - public void accountUpdate(UserInfo userInfo) { - if(userInfo.getStatus() != ConstsStatus.ACTIVE) { - if(accountsService==null) { - accountsService = - WebContext.getBean("accountsService",AccountsService.class); - } - Accounts queryAcount =new Accounts(); - queryAcount.setUserId(userInfo.getId()); - for (Accounts acount : accountsService.query(queryAcount)) { - acount.setStatus(ConstsStatus.INACTIVE); - accountsService.update(acount); - } - } - } + public void accountUpdate(UserInfo userInfo) ; - public UserInfo findUserRelated(String userId) { - UserInfo loadUserInfo =this.get(userId); - loadUserInfo.setDepts(getMapper().findDeptsByUserId(userId)); - return loadUserInfo; - } + public UserInfo findUserRelated(String userId) ; - public boolean updateGridList(String gridList,UserInfo userInfo) { - try { - if (gridList != null && !gridList.equals("")) { - userInfo.setGridList(Integer.parseInt(gridList)); - getMapper().updateGridList(userInfo); - } - }catch(Exception e) { - e.printStackTrace(); - return false; - } - return true; - } + public boolean updateGridList(String gridList,UserInfo userInfo); - public void saveOrUpdate(UserInfo userInfo) { - UserInfo loadUserInfo = findOne(" username = ? and instid = ?", - new Object[] { userInfo.getUsername(),userInfo.getInstId() }, - new int[] { Types.VARCHAR,Types.VARCHAR}); - if(loadUserInfo == null) { - insert(userInfo); - }else { - userInfo.setId(loadUserInfo.getId()); - userInfo.setPassword(null); - update(userInfo); - } - } + public void saveOrUpdate(UserInfo userInfo) ; - public boolean updateProtectedApps(UserInfo userinfo) { - try { - userinfo.setModifiedDate(new Date()); - return getMapper().updateProtectedApps(userinfo) > 0; - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } + public boolean updateProtectedApps(UserInfo userinfo) ; - public UserInfo findByUsername(String username) { - return getMapper().findByUsername(username); - } + public UserInfo findByUsername(String username) ; - public UserInfo findByEmailMobile(String emailMobile) { - return getMapper().findByEmailMobile(emailMobile); - } + public UserInfo findByEmailMobile(String emailMobile) ; - public UserInfo findByAppIdAndUsername(String appId,String username){ - try { - UserInfo userinfo = new UserInfo(); - userinfo.setUsername(username); - return getMapper().findByAppIdAndUsername(userinfo) ; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } + public UserInfo findByAppIdAndUsername(String appId,String username); - public ChangePassword passwordEncoder(UserInfo userInfo) { - ChangePassword changePassword = null; - if(StringUtils.isNotBlank(userInfo.getPassword())) { - changePassword = new ChangePassword(userInfo); - passwordEncoder(changePassword); - userInfo.setPassword(changePassword.getPassword()); - userInfo.setDecipherable(changePassword.getDecipherable()); - userInfo.setPasswordLastSetTime(changePassword.getPasswordLastSetTime()); - }else { - userInfo.setPassword(null); - userInfo.setDecipherable(null); - } - return changePassword; - } + public ChangePassword passwordEncoder(UserInfo userInfo) ; - public ChangePassword passwordEncoder(ChangePassword changePassword) { - //密码不为空,则需要进行加密处理 - if(StringUtils.isNotBlank(changePassword.getPassword())) { - String password = passwordEncoder.encode(changePassword.getPassword()); - changePassword.setDecipherable(PasswordReciprocal.getInstance().encode(changePassword.getPassword())); - _logger.debug("decipherable : {}",changePassword.getDecipherable()); - changePassword.setPassword(password); - changePassword.setPasswordLastSetTime(new Date()); - - }else { - changePassword.setPassword(null); - changePassword.setDecipherable(null); - } - return changePassword; - } + public ChangePassword passwordEncoder(ChangePassword changePassword) ; /** * 认证密码修改 @@ -263,37 +63,7 @@ public class UserInfoService extends JpaService { * @param passwordSetType * @return */ - public boolean changePassword( ChangePassword changePassword) { - try { - WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, ""); - UserInfo userInfo = this.findByUsername(changePassword.getUsername()); - if(changePassword.getPassword().equals(changePassword.getConfirmPassword())){ - if(StringUtils.isNotBlank(changePassword.getOldPassword()) && - passwordEncoder.matches(changePassword.getOldPassword(), userInfo.getPassword())){ - if(changePassword(changePassword,true) ){ - return true; - } - return false; - }else { - if(StringUtils.isNotBlank(changePassword.getOldPassword())&& - passwordEncoder.matches(changePassword.getPassword(), userInfo.getPassword())) { - WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, - WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_MATCH")); - }else { - WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, - WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_NOT_MATCH")); - } - } - }else { - WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, - WebContext.getI18nValue("PasswordPolicy.CONFIRMPASSWORD_NOT_MATCH")); - } - } catch (Exception e) { - e.printStackTrace(); - } - - return false; - } + public boolean changePassword( ChangePassword changePassword) ; /** * 后台密码修改 @@ -301,130 +71,47 @@ public class UserInfoService extends JpaService { * @param passwordPolicy * @return */ - public boolean changePassword(ChangePassword changePassword,boolean passwordPolicy) { - try { - _logger.debug("decipherable old : {}" , changePassword.getDecipherable()); - _logger.debug("decipherable new : {}" , PasswordReciprocal.getInstance().encode(changePassword.getDecipherable())); - - if (passwordPolicy && !passwordPolicyValidator.validator(changePassword)) { - return false; - } - - changePassword = passwordEncoder(changePassword); - - if (getMapper().changePassword(changePassword) > 0) { - changePasswordProvisioning(changePassword); - return true; - } - return false; - - } catch (Exception e) { - e.printStackTrace(); - } - - return false; - } + public boolean changePassword(ChangePassword changePassword,boolean passwordPolicy) ; - public String randomPassword() { - return passwordPolicyValidator.generateRandomPassword(); - } + public String randomPassword() ; - public void changePasswordProvisioning(ChangePassword changePassworded) { - if(changePassworded !=null && StringUtils.isNotBlank(changePassworded.getPassword())) { - UserInfo loadUserInfo = findByUsername(changePassworded.getUsername()); - ChangePassword changePassword = new ChangePassword(loadUserInfo); - provisionService.send(ProvisionTopic.PASSWORD_TOPIC, changePassword, ProvisionAct.PASSWORD); - } - } + public void changePasswordProvisioning(ChangePassword changePassworded) ; - public boolean updateAppLoginPassword(UserInfo userinfo) { - try { - userinfo.setModifiedDate(new Date()); - return getMapper().updateAppLoginPassword(userinfo) > 0; - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } + public boolean updateAppLoginPassword(UserInfo userinfo) ; /** * 锁定用户:islock:1 用户解锁 2 用户锁定 * @param userInfo */ - public void updateLocked(UserInfo userInfo) { - try { - if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) { - userInfo.setIsLocked(ConstsStatus.LOCK); - getMapper().updateLocked(userInfo); - } - } catch(Exception e) { - e.printStackTrace(); - } - } + public void updateLocked(UserInfo userInfo) ; /** * 用户登录成功后,重置错误密码次数和解锁用户 * @param userInfo */ - public void updateLockout(UserInfo userInfo) { - try { - if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) { - userInfo.setIsLocked(ConstsStatus.START); - userInfo.setBadPasswordCount(0); - getMapper().updateLockout(userInfo); - } - } catch(Exception e) { - e.printStackTrace(); - } - } + public void updateLockout(UserInfo userInfo) ; /** * 更新错误密码次数 * @param userInfo */ - public void updateBadPasswordCount(UserInfo userInfo) { - try { - if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) { - int updateBadPWDCount = userInfo.getBadPasswordCount() + 1; - userInfo.setBadPasswordCount(updateBadPWDCount); - getMapper().updateBadPWDCount(userInfo); - } - } catch(Exception e) { - e.printStackTrace(); - } - } + public void updateBadPasswordCount(UserInfo userInfo) ; - public boolean updateSharedSecret(UserInfo userInfo){ - return getMapper().updateSharedSecret(userInfo)>0; - } + public boolean updateSharedSecret(UserInfo userInfo); - public boolean updatePasswordQuestion(UserInfo userInfo){ - return getMapper().updatePasswordQuestion(userInfo)>0; - } + public boolean updatePasswordQuestion(UserInfo userInfo); - public boolean updateAuthnType(UserInfo userInfo){ - return getMapper().updateAuthnType(userInfo)>0; - } + public boolean updateAuthnType(UserInfo userInfo); - public boolean updateEmail(UserInfo userInfo){ - return getMapper().updateEmail(userInfo)>0; - } + public boolean updateEmail(UserInfo userInfo); - public boolean updateMobile(UserInfo userInfo){ - return getMapper().updateMobile(userInfo)>0; - } + public boolean updateMobile(UserInfo userInfo); - public int updateProfile(UserInfo userInfo){ - return getMapper().updateProfile(userInfo); - } + public int updateProfile(UserInfo userInfo); - public boolean updateStatus(UserInfo userInfo) { - return getMapper().updateStatus(userInfo) > 0; - } + public boolean updateStatus(UserInfo userInfo); - public void setPasswordPolicyValidator(PasswordPolicyValidator passwordPolicyValidator) { - this.passwordPolicyValidator = passwordPolicyValidator; - } + public void setPasswordPolicyValidator(PasswordPolicyValidator passwordPolicyValidator); } diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/package-info.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AccessServiceImpl.java similarity index 64% rename from maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/package-info.java rename to maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AccessServiceImpl.java index fac0df93..7da278ba 100644 --- a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/package-info.java +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AccessServiceImpl.java @@ -15,8 +15,14 @@ */ -/** - * - * Mysql DAO Mapper XML Configuration. -*/ -package org.dromara.maxkey.persistence.service; +package org.dromara.maxkey.persistence.service.impl; + +import org.dromara.maxkey.entity.Access; +import org.dromara.maxkey.persistence.mapper.AccessMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class AccessServiceImpl extends JpaServiceImpl{ + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AccountsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AccountsServiceImpl.java new file mode 100644 index 00000000..f6c47e87 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AccountsServiceImpl.java @@ -0,0 +1,255 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.dromara.maxkey.constants.ConstsStatus; +import org.dromara.maxkey.crypto.password.PasswordReciprocal; +import org.dromara.maxkey.entity.Accounts; +import org.dromara.maxkey.entity.AccountsStrategy; +import org.dromara.maxkey.entity.OrganizationsCast; +import org.dromara.maxkey.entity.idm.UserInfo; +import org.dromara.maxkey.persistence.mapper.AccountsMapper; +import org.dromara.maxkey.persistence.service.AccountsStrategyService; +import org.dromara.maxkey.persistence.service.OrganizationsCastService; +import org.dromara.maxkey.persistence.service.UserInfoService; +import org.dromara.maxkey.provision.ProvisionAct; +import org.dromara.maxkey.provision.ProvisionService; +import org.dromara.maxkey.provision.ProvisionTopic; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import net.sourceforge.pinyin4j.PinyinHelper; +import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; +import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; +import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; +import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; +import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; + +@Repository +public class AccountsServiceImpl extends JpaServiceImpl{ + + @Autowired + ProvisionService provisionService; + + @Autowired + UserInfoService userInfoService; + + @Autowired + AccountsStrategyService accountsStrategyService; + + @Autowired + OrganizationsCastService organizationsCastService; + + @Override + public boolean insert(Accounts account) { + if (super.insert(account)) { + if(provisionService.getApplicationConfig().isProvisionSupport()) { + UserInfo loadUserInfo = userInfoService.findUserRelated(account.getUserId()); + account.setUserInfo(loadUserInfo); + OrganizationsCast cast = new OrganizationsCast(); + cast.setProvider(account.getAppId()); + cast.setOrgId(loadUserInfo.getDepartmentId()); + account.setOrgCast(organizationsCastService.query(cast)); + provisionService.send( + ProvisionTopic.ACCOUNT_TOPIC, + account, + ProvisionAct.CREATE); + } + + return true; + } + return false; + } + + @Override + public boolean update(Accounts account) { + if (super.update(account)) { + if(provisionService.getApplicationConfig().isProvisionSupport()) { + UserInfo loadUserInfo = userInfoService.findUserRelated(account.getUserId()); + account.setUserInfo(loadUserInfo); + OrganizationsCast cast = new OrganizationsCast(); + cast.setProvider(account.getAppId()); + cast.setOrgId(loadUserInfo.getDepartmentId()); + account.setOrgCast(organizationsCastService.query(cast)); + provisionService.send( + ProvisionTopic.ACCOUNT_TOPIC, + account, + ProvisionAct.UPDATE); + } + + return true; + } + return false; + } + + public boolean updateStatus(Accounts accounts) { + return this.getMapper().updateStatus(accounts) > 0; + } + + public boolean remove(String id) { + Accounts account = this.get(id); + if (super.delete(id)) { + UserInfo loadUserInfo = null; + if(provisionService.getApplicationConfig().isProvisionSupport()) { + loadUserInfo = userInfoService.findUserRelated(account.getUserId()); + account.setUserInfo(loadUserInfo); + provisionService.send( + ProvisionTopic.ACCOUNT_TOPIC, + account, + ProvisionAct.DELETE); + } + + return true; + } + return false; + } + + public void refreshByStrategy(AccountsStrategy strategy) { + if(StringUtils.isNotBlank(strategy.getOrgIdsList())) { + strategy.setOrgIdsList("'"+strategy.getOrgIdsList().replace(",", "','")+"'"); + } + List userList = queryUserNotInStrategy(strategy); + for(UserInfo user : userList) { + Accounts account = new Accounts(); + account.setAppId(strategy.getAppId()); + account.setAppName(strategy.getAppName()); + + account.setUserId(user.getId()); + account.setUsername(user.getUsername()); + account.setDisplayName(user.getDisplayName()); + account.setRelatedUsername(generateAccount(user,strategy)); + account.setRelatedPassword(PasswordReciprocal.getInstance().encode(userInfoService.randomPassword())); + + account.setInstId(strategy.getInstId()); + account.setCreateType("automatic"); + account.setStatus(ConstsStatus.ACTIVE); + account.setStrategyId(strategy.getId()); + + insert(account); + } + deleteByStrategy(strategy); + } + public void refreshAllByStrategy() { + AccountsStrategy queryStrategy = new AccountsStrategy(); + queryStrategy.setCreateType("automatic"); + for( AccountsStrategy strategy : accountsStrategyService.query(queryStrategy)) { + refreshByStrategy(strategy); + } + } + + + public List queryUserNotInStrategy(AccountsStrategy strategy){ + return getMapper().queryUserNotInStrategy(strategy); + } + + public long deleteByStrategy(AccountsStrategy strategy) { + return getMapper().deleteByStrategy(strategy); + } + + + public List queryByAppIdAndDate(Accounts account) { + return getMapper().queryByAppIdAndDate(account); + } + + public List queryByAppIdAndAccount(String appId,String relatedUsername){ + return getMapper().queryByAppIdAndAccount(appId,relatedUsername); + } + + + public String generateAccount(UserInfo userInfo,AccountsStrategy accountsStrategy) { + String shortAccount = generateAccount(userInfo,accountsStrategy,true); + String account = generateAccount(userInfo,accountsStrategy,false); + String accountResult = shortAccount; + List accountsList =getMapper().queryByAppIdAndAccount(accountsStrategy.getAppId(),shortAccount +accountsStrategy.getSuffixes()); + if(!accountsList.isEmpty()) { + if(accountsStrategy.getMapping().equalsIgnoreCase("email")) { + accountResult = account; + accountsList =getMapper().queryByAppIdAndAccount(accountsStrategy.getAppId(),account + accountsStrategy.getSuffixes()); + } + if(!accountsList.isEmpty()) { + for(int i =1 ;i < 100 ;i++) { + accountResult = account + i; + accountsList =getMapper().queryByAppIdAndAccount(accountsStrategy.getAppId(),accountResult + accountsStrategy.getSuffixes()); + if(accountsList.isEmpty()) { + break; + } + } + } + } + if(StringUtils.isNotBlank(accountsStrategy.getSuffixes())){ + accountResult = accountResult + accountsStrategy.getSuffixes(); + } + return accountResult; + } + + + private String generateAccount(UserInfo userInfo,AccountsStrategy strategy,boolean isShort) { + String account = ""; + if(strategy.getMapping().equalsIgnoreCase("username")) { + account = userInfo.getUsername(); + }else if(strategy.getMapping().equalsIgnoreCase("mobile")) { + account = userInfo.getMobile(); + }else if(strategy.getMapping().equalsIgnoreCase("email")) { + try { + if(isShort) { + account = getPinYinShortName(userInfo.getDisplayName()); + }else { + account = getPinYinName(userInfo.getDisplayName()); + } + }catch(Exception e) { + e.printStackTrace(); + } + }else if(strategy.getMapping().equalsIgnoreCase("employeeNumber")) { + account = userInfo.getEmployeeNumber(); + }else if(strategy.getMapping().equalsIgnoreCase("windowsAccount")) { + account = userInfo.getWindowsAccount(); + }else if(strategy.getMapping().equalsIgnoreCase("idCardNo")) { + account = userInfo.getIdCardNo(); + }else { + account = userInfo.getUsername(); + } + + return account; + } + + public static String getPinYinName(String name) throws BadHanyuPinyinOutputFormatCombination { + HanyuPinyinOutputFormat pinyinFormat = new HanyuPinyinOutputFormat(); + pinyinFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); + pinyinFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + pinyinFormat.setVCharType(HanyuPinyinVCharType.WITH_V); + return PinyinHelper.toHanYuPinyinString(name, pinyinFormat, "",false); + } + + public static String getPinYinShortName(String name) throws BadHanyuPinyinOutputFormatCombination { + char[] strs = name.toCharArray(); + String pinyinName = ""; + for(int i=0;i { + static final Logger _logger = LoggerFactory.getLogger(AccountsStrategyServiceImpl.class); + + + + public List queryDynamicGroups(Roles groups){ + return this.getMapper().queryDynamicGroups(groups); + } + + public boolean deleteById(String groupId) { + this.delete(groupId); + //groupMemberService.deleteByGroupId(groupId); + return true; + } + /* + public void refreshDynamicGroups(Groups dynamicGroup){ + if(dynamicGroup.getDynamic().equals("1")) { + boolean isDynamicTimeSupport = false; + boolean isBetweenEffectiveTime = false; + if(dynamicGroup.getResumeTime()!=null&&dynamicGroup.getResumeTime().equals("") + &&dynamicGroup.getSuspendTime()!=null&&dynamicGroup.getSuspendTime().equals("")) { + LocalTime currentTime = LocalDateTime.now().toLocalTime(); + LocalTime resumeTime = LocalTime.parse(dynamicGroup.getResumeTime()); + LocalTime suspendTime = LocalTime.parse(dynamicGroup.getSuspendTime()); + + _logger.info("currentTime: " + currentTime + + " , resumeTime : " + resumeTime + + " , suspendTime: " + suspendTime); + isDynamicTimeSupport = true; + + if(resumeTime.isBefore(currentTime) && currentTime.isBefore(suspendTime)) { + isBetweenEffectiveTime = true; + } + + } + + if(dynamicGroup.getOrgIdsList()!=null && !dynamicGroup.getOrgIdsList().equals("")) { + dynamicGroup.setOrgIdsList("'"+dynamicGroup.getOrgIdsList().replace(",", "','")+"'"); + } + String filters = dynamicGroup.getFilters(); + if(StringUtils.filtersSQLInjection(filters.toLowerCase())) { + _logger.info("filters include SQL Injection Attack Risk."); + return; + } + + filters = filters.replace("&", " AND "); + filters = filters.replace("|", " OR "); + + dynamicGroup.setFilters(filters); + + if(isDynamicTimeSupport) { + if(isBetweenEffectiveTime) { + groupMemberService.deleteDynamicGroupMember(dynamicGroup); + groupMemberService.addDynamicGroupMember(dynamicGroup); + }else { + groupMemberService.deleteDynamicGroupMember(dynamicGroup); + } + }else{ + groupMemberService.deleteDynamicGroupMember(dynamicGroup); + groupMemberService.addDynamicGroupMember(dynamicGroup); + } + } + }*/ + + + + + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsAdaptersServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsAdaptersServiceImpl.java new file mode 100644 index 00000000..a72cb983 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsAdaptersServiceImpl.java @@ -0,0 +1,28 @@ +/* + * Copyright [2021] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.apps.AppsAdapters; +import org.dromara.maxkey.persistence.mapper.AppsAdaptersMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class AppsAdaptersServiceImpl extends JpaServiceImpl{ + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsCasDetailsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsCasDetailsServiceImpl.java new file mode 100644 index 00000000..42731a53 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsCasDetailsServiceImpl.java @@ -0,0 +1,54 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.concurrent.TimeUnit; + +import org.dromara.maxkey.entity.apps.AppsCasDetails; +import org.dromara.maxkey.persistence.mapper.AppsCasDetailsMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +@Repository +public class AppsCasDetailsServiceImpl extends JpaServiceImpl{ + + protected static final Cache detailsCache = + Caffeine.newBuilder() + .expireAfterWrite(30, TimeUnit.MINUTES) + .maximumSize(200000) + .build(); + + public AppsCasDetails getAppDetails(String id , boolean cached) { + AppsCasDetails details = null; + if(cached) { + details = detailsCache.getIfPresent(id); + if(details == null) { + details = getMapper().getAppDetails(id); + if(details != null) { + detailsCache.put(id, details); + } + } + }else { + details = getMapper().getAppDetails(id); + } + return details; + } +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsFormBasedDetailsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsFormBasedDetailsServiceImpl.java new file mode 100644 index 00000000..9752c8da --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsFormBasedDetailsServiceImpl.java @@ -0,0 +1,52 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.concurrent.TimeUnit; + +import org.dromara.maxkey.entity.apps.AppsFormBasedDetails; +import org.dromara.maxkey.persistence.mapper.AppsFormBasedDetailsMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +@Repository +public class AppsFormBasedDetailsServiceImpl extends JpaServiceImpl{ + + protected static final Cache detailsCache = + Caffeine.newBuilder() + .expireAfterWrite(30, TimeUnit.MINUTES) + .maximumSize(200000) + .build(); + + public AppsFormBasedDetails getAppDetails(String id,boolean cached) { + AppsFormBasedDetails details = null; + if(cached) { + details = detailsCache.getIfPresent(id); + if(details == null) { + details = getMapper().getAppDetails(id); + detailsCache.put(id, details); + } + }else { + details = getMapper().getAppDetails(id); + } + return details; + } +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsJwtDetailsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsJwtDetailsServiceImpl.java new file mode 100644 index 00000000..37bc513f --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsJwtDetailsServiceImpl.java @@ -0,0 +1,53 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.concurrent.TimeUnit; + +import org.dromara.maxkey.entity.apps.AppsJwtDetails; +import org.dromara.maxkey.persistence.mapper.AppsJwtDetailsMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +@Repository +public class AppsJwtDetailsServiceImpl extends JpaServiceImpl{ + + protected static final Cache detailsCache = + Caffeine.newBuilder() + .expireAfterWrite(30, TimeUnit.MINUTES) + .maximumSize(200000) + .build(); + + + public AppsJwtDetails getAppDetails(String id , boolean cached) { + AppsJwtDetails details = null; + if(cached) { + details = detailsCache.getIfPresent(id); + if(details == null) { + details = getMapper().getAppDetails(id); + detailsCache.put(id, details); + } + }else { + details = getMapper().getAppDetails(id); + } + return details; + } +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsSaml20DetailsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsSaml20DetailsServiceImpl.java new file mode 100644 index 00000000..b091e0a3 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsSaml20DetailsServiceImpl.java @@ -0,0 +1,52 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.concurrent.TimeUnit; + +import org.dromara.maxkey.entity.apps.AppsSAML20Details; +import org.dromara.maxkey.persistence.mapper.AppsSaml20DetailsMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +@Repository +public class AppsSaml20DetailsServiceImpl extends JpaServiceImpl{ + + protected static final Cache detailsCache = + Caffeine.newBuilder() + .expireAfterWrite(30, TimeUnit.MINUTES) + .maximumSize(200000) + .build(); + + public AppsSAML20Details getAppDetails(String id , boolean cached){ + AppsSAML20Details details = null; + if(cached) { + details = detailsCache.getIfPresent(id); + if(details == null) { + details = getMapper().getAppDetails(id); + detailsCache.put(id, details); + } + }else { + details = getMapper().getAppDetails(id); + } + return details; + } +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsServiceImpl.java new file mode 100644 index 00000000..c2a71800 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsServiceImpl.java @@ -0,0 +1,79 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.dromara.maxkey.entity.apps.Apps; +import org.dromara.maxkey.entity.apps.UserApps; +import org.dromara.maxkey.persistence.mapper.AppsMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +@Repository +public class AppsServiceImpl extends JpaServiceImpl{ + //maxkey-mgt + public static final String MGT_APP_ID = "622076759805923328"; + + public static final String DETAIL_SUFFIX = "_detail"; + + protected static final Cache detailsCacheStore = + Caffeine.newBuilder() + .expireAfterWrite(30, TimeUnit.MINUTES) + .build(); + + public boolean insertApp(Apps app) { + return ((AppsMapper)super.getMapper()).insertApp(app)>0; + }; + public boolean updateApp(Apps app) { + return ((AppsMapper)super.getMapper()).updateApp(app)>0; + }; + + public boolean updateExtendAttr(Apps app) { + return ((AppsMapper)super.getMapper()).updateExtendAttr(app)>0; + } + + public List queryMyApps(UserApps userApplications){ + return getMapper().queryMyApps(userApplications); + } + + //cache for running + public void put(String appId, Apps appDetails) { + detailsCacheStore.put(appId + DETAIL_SUFFIX, appDetails); + } + + public Apps get(String appId, boolean cached) { + appId = appId.equalsIgnoreCase("maxkey_mgt") ? MGT_APP_ID : appId; + Apps appDetails = null; + if(cached) { + appDetails = detailsCacheStore.getIfPresent(appId + DETAIL_SUFFIX); + if(appDetails == null) { + appDetails = this.get(appId); + detailsCacheStore.put(appId, appDetails); + } + }else { + appDetails = this.get(appId); + } + return appDetails; + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsTokenBasedDetailsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsTokenBasedDetailsServiceImpl.java new file mode 100644 index 00000000..78a2c058 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/AppsTokenBasedDetailsServiceImpl.java @@ -0,0 +1,52 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.concurrent.TimeUnit; + +import org.dromara.maxkey.entity.apps.AppsTokenBasedDetails; +import org.dromara.maxkey.persistence.mapper.AppsTokenBasedDetailsMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +@Repository +public class AppsTokenBasedDetailsServiceImpl extends JpaServiceImpl{ + + protected static final Cache detailsCache = + Caffeine.newBuilder() + .expireAfterWrite(30, TimeUnit.MINUTES) + .maximumSize(200000) + .build(); + + public AppsTokenBasedDetails getAppDetails(String id , boolean cached) { + AppsTokenBasedDetails details = null; + if(cached) { + details = detailsCache.getIfPresent(id); + if(details == null) { + details = getMapper().getAppDetails(id); + detailsCache.put(id, details); + } + }else { + details = getMapper().getAppDetails(id); + } + return details; + } +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfEmailSendersServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfEmailSendersServiceImpl.java new file mode 100644 index 00000000..e847cf43 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfEmailSendersServiceImpl.java @@ -0,0 +1,30 @@ +/* + * 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.dromara.maxkey.persistence.service.impl; + + +import org.dromara.maxkey.entity.cnf.CnfEmailSenders; +import org.dromara.maxkey.persistence.mapper.CnfEmailSendersMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + + +@Repository +public class CnfEmailSendersServiceImpl extends JpaServiceImpl{ + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfLdapContextServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfLdapContextServiceImpl.java new file mode 100644 index 00000000..3c5ad197 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfLdapContextServiceImpl.java @@ -0,0 +1,29 @@ +/* + * 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.dromara.maxkey.persistence.service.impl; + +import org.dromara.maxkey.entity.cnf.CnfLdapContext; +import org.dromara.maxkey.persistence.mapper.CnfLdapContextMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + + +@Repository +public class CnfLdapContextServiceImpl extends JpaServiceImpl{ + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfPasswordPolicyServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfPasswordPolicyServiceImpl.java new file mode 100644 index 00000000..a4f3cf0b --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfPasswordPolicyServiceImpl.java @@ -0,0 +1,28 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy; +import org.dromara.maxkey.persistence.mapper.CnfPasswordPolicyMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class CnfPasswordPolicyServiceImpl extends JpaServiceImpl{ + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfSmsProviderServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfSmsProviderServiceImpl.java new file mode 100644 index 00000000..a050fea7 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/CnfSmsProviderServiceImpl.java @@ -0,0 +1,29 @@ +/* + * 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.dromara.maxkey.persistence.service.impl; + +import org.dromara.maxkey.entity.cnf.CnfSmsProvider; +import org.dromara.maxkey.persistence.mapper.CnfSmsProviderMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + + +@Repository +public class CnfSmsProviderServiceImpl extends JpaServiceImpl{ + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/ConnectorsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/ConnectorsServiceImpl.java new file mode 100644 index 00000000..2db6069f --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/ConnectorsServiceImpl.java @@ -0,0 +1,28 @@ +/* + * 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.dromara.maxkey.persistence.service.impl; + +import org.dromara.maxkey.entity.Connectors; +import org.dromara.maxkey.persistence.mapper.ConnectorsMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class ConnectorsServiceImpl extends JpaServiceImpl{ + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/FileUploadServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/FileUploadServiceImpl.java new file mode 100644 index 00000000..d1479611 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/FileUploadServiceImpl.java @@ -0,0 +1,28 @@ +/* + * Copyright [2021] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.FileUpload; +import org.dromara.maxkey.persistence.mapper.FileUploadMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class FileUploadServiceImpl extends JpaServiceImpl{ + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/GroupMemberServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/GroupMemberServiceImpl.java new file mode 100644 index 00000000..6d15d7ab --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/GroupMemberServiceImpl.java @@ -0,0 +1,77 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.List; + +import org.dromara.maxkey.entity.idm.GroupMember; +import org.dromara.maxkey.entity.idm.Groups; +import org.dromara.maxkey.entity.idm.UserInfo; +import org.dromara.maxkey.persistence.mapper.GroupMemberMapper; +import org.dromara.mybatis.jpa.entity.JpaPageResults; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; + +@Repository +public class GroupMemberServiceImpl extends JpaServiceImpl{ + static final Logger _logger = LoggerFactory.getLogger(GroupMemberServiceImpl.class); + + public int addDynamicMember(Groups dynamicGroup) { + return getMapper().addDynamicMember(dynamicGroup); + } + + public int deleteDynamicMember(Groups dynamicGroup) { + return getMapper().deleteDynamicMember(dynamicGroup); + } + + public int deleteByGroupId(String groupId) { + return getMapper().deleteByGroupId(groupId); + } + + public List queryMemberByGroupId(String groupId){ + return getMapper().queryMemberByGroupId(groupId); + } + + + public JpaPageResults noMember(GroupMember entity) { + entity.setPageSelectId(entity.generateId()); + entity.setStartRow(calculateStartRow(entity.getPageNumber() ,entity.getPageSize())); + + entity.setPageable(true); + List resultslist = null; + try { + resultslist = getMapper().noMember(entity); + } catch (Exception e) { + _logger.error("queryPageResults Exception " , e); + } + entity.setPageable(false); + Integer totalPage = resultslist.size(); + + Integer totalCount = 0; + if(entity.getPageNumber() == 1 && totalPage < entity.getPageSize()) { + totalCount = totalPage; + }else { + totalCount = parseCount(getMapper().fetchCount(entity)); + } + + return new JpaPageResults(entity.getPageNumber(),entity.getPageSize(),totalPage,totalCount,resultslist); + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/GroupsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/GroupsServiceImpl.java new file mode 100644 index 00000000..738e23bd --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/GroupsServiceImpl.java @@ -0,0 +1,111 @@ +/* + * 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.dromara.maxkey.persistence.service.impl; + +import java.sql.Types; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.dromara.maxkey.constants.ConstsStatus; +import org.dromara.maxkey.entity.Institutions; +import org.dromara.maxkey.entity.idm.Groups; +import org.dromara.maxkey.entity.permissions.Roles; +import org.dromara.maxkey.persistence.mapper.GroupsMapper; +import org.dromara.maxkey.util.StrUtils; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class GroupsServiceImpl extends JpaServiceImpl{ + static final Logger _logger = LoggerFactory.getLogger(GroupsServiceImpl.class); + + @Autowired + GroupMemberServiceImpl groupMemberService; + + @Autowired + InstitutionsServiceImpl institutionsService; + + public List queryDynamicGroups(Groups groups){ + return this.getMapper().queryDynamic(groups); + } + + public boolean deleteById(String groupId) { + this.delete(groupId); + groupMemberService.deleteByGroupId(groupId); + return true; + } + + public List queryByUserId(String userId){ + return this.getMapper().queryByUserId(userId); + } + + public void refreshDynamicGroups(Groups dynamicGroup){ + if(dynamicGroup.getCategory().equals(Roles.Category.DYNAMIC)) { + + if(StringUtils.isNotBlank(dynamicGroup.getOrgIdsList())) { + String []orgIds = dynamicGroup.getOrgIdsList().split(","); + StringBuffer orgIdFilters = new StringBuffer(); + for(String orgId : orgIds) { + if(StringUtils.isNotBlank(orgId)) { + if(orgIdFilters.length() > 0) { + orgIdFilters.append(","); + } + orgIdFilters.append("'").append(orgId).append("'"); + } + } + if(orgIdFilters.length() > 0) { + dynamicGroup.setOrgIdsList(orgIdFilters.toString()); + } + } + + String filters = dynamicGroup.getFilters(); + if(StringUtils.isNotBlank(filters)) { + if(StrUtils.filtersSQLInjection(filters.toLowerCase())) { + _logger.info("filters include SQL Injection Attack Risk."); + return; + } + //replace & with AND, | with OR + filters = filters.replace("&", " AND ").replace("|", " OR "); + + dynamicGroup.setFilters(filters); + } + + groupMemberService.deleteDynamicMember(dynamicGroup); + groupMemberService.addDynamicMember(dynamicGroup); + + } + } + + public void refreshAllDynamicGroups(){ + List instList = + institutionsService.find("where status = ? ", new Object[]{ConstsStatus.ACTIVE}, new int[]{Types.INTEGER}); + for(Institutions inst : instList) { + Groups group = new Groups(); + group.setInstId(inst.getId()); + List groupsList = queryDynamicGroups(group); + for(Groups g : groupsList) { + _logger.debug("role {}" , g); + refreshDynamicGroups(g); + } + } + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistoryConnectorServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistoryConnectorServiceImpl.java new file mode 100644 index 00000000..0e9cbb88 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistoryConnectorServiceImpl.java @@ -0,0 +1,28 @@ +/* + * Copyright [2021] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.history.HistoryConnector; +import org.dromara.maxkey.persistence.mapper.HistoryConnectorMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class HistoryConnectorServiceImpl extends JpaServiceImpl{ + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistoryLoginAppsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistoryLoginAppsServiceImpl.java new file mode 100644 index 00000000..2dfc60df --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistoryLoginAppsServiceImpl.java @@ -0,0 +1,54 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.history.HistoryLoginApps; +import org.dromara.maxkey.persistence.mapper.HistoryLoginAppsMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class HistoryLoginAppsServiceImpl extends JpaServiceImpl{ + + @Override + public boolean insert(HistoryLoginApps loginAppsHistory){ + //new Thread insert login app history + new Thread(new HistoryLoginAppsRunnable(getMapper(),loginAppsHistory)).start(); + return true; + } + + public class HistoryLoginAppsRunnable implements Runnable{ + + HistoryLoginAppsMapper historyLoginAppsMapper; + + HistoryLoginApps loginAppsHistory; + + public HistoryLoginAppsRunnable(HistoryLoginAppsMapper historyLoginAppsMapper, + HistoryLoginApps loginAppsHistory) { + super(); + this.historyLoginAppsMapper = historyLoginAppsMapper; + this.loginAppsHistory = loginAppsHistory; + } + + @Override + public void run() { + historyLoginAppsMapper.insert(loginAppsHistory); + } + + } +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistoryLoginServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistoryLoginServiceImpl.java new file mode 100644 index 00000000..74bd8c29 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistoryLoginServiceImpl.java @@ -0,0 +1,32 @@ +/* + * 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.dromara.maxkey.persistence.service.impl; + +import org.dromara.maxkey.entity.history.HistoryLogin; +import org.dromara.maxkey.persistence.mapper.HistoryLoginMapper; +import org.dromara.mybatis.jpa.entity.JpaPageResults; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class HistoryLoginServiceImpl extends JpaServiceImpl{ + + public JpaPageResults queryOnlineSession(HistoryLogin historyLogin) { + return this.fetchPageResults("queryOnlineSession",historyLogin); + } +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistorySynchronizerServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistorySynchronizerServiceImpl.java new file mode 100644 index 00000000..43ac8f30 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistorySynchronizerServiceImpl.java @@ -0,0 +1,28 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.history.HistorySynchronizer; +import org.dromara.maxkey.persistence.mapper.HistorySynchronizerMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class HistorySynchronizerServiceImpl extends JpaServiceImpl{ + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistorySystemLogsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistorySystemLogsServiceImpl.java new file mode 100644 index 00000000..eba2d501 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/HistorySystemLogsServiceImpl.java @@ -0,0 +1,199 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.Accounts; +import org.dromara.maxkey.entity.ChangePassword; + +import java.util.Date; + +import org.dromara.maxkey.entity.Access; +import org.dromara.maxkey.entity.SocialsProvider; +import org.dromara.maxkey.entity.Synchronizers; +import org.dromara.maxkey.entity.history.HistorySystemLogs; +import org.dromara.maxkey.entity.idm.Organizations; +import org.dromara.maxkey.entity.idm.UserInfo; +import org.dromara.maxkey.entity.permissions.Permission; +import org.dromara.maxkey.entity.permissions.Resources; +import org.dromara.maxkey.entity.permissions.RoleMember; +import org.dromara.maxkey.entity.permissions.Roles; +import org.dromara.maxkey.persistence.mapper.HistorySystemLogsMapper; +import org.dromara.maxkey.util.JsonUtils; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; + +@Repository +public class HistorySystemLogsServiceImpl extends JpaServiceImpl{ + static final Logger _logger = LoggerFactory.getLogger(HistorySystemLogsServiceImpl.class); + + public void insert(String topic,Object entity,String action,String result,UserInfo operator) { + String message = ""; + if(entity != null) { + if(entity instanceof UserInfo userInfo) { + message = buildMsg(userInfo); + }else if(entity instanceof Organizations organization) { + message = buildMsg(organization); + }else if(entity instanceof ChangePassword changePassword) { + message = buildMsg(changePassword); + }else if(entity instanceof Accounts account) { + message = buildMsg(account); + }else if(entity instanceof Roles role) { + message = buildMsg(role); + }else if(entity instanceof RoleMember roleMember) { + message = buildMsg(roleMember); + }else if(entity instanceof Access access) { + message = buildMsg(access); + }else if(entity instanceof Resources resource) { + message = buildMsg(resource); + }else if(entity instanceof Synchronizers synchronizer) { + message = buildMsg(synchronizer); + }else if(entity instanceof SocialsProvider socialsProvider) { + message = buildMsg(socialsProvider); + }else if(entity instanceof Permission permission) { + message = buildMsg(permission); + }else if(entity instanceof String) { + message = entity.toString(); + } + + } + + insert(topic,message,action,result,operator, entity); + } + + public void insert(String topic,String message,String action,String result,UserInfo operator,Object entity) { + HistorySystemLogs systemLog = new HistorySystemLogs(); + systemLog.setId(systemLog.generateId()); + systemLog.setTopic(topic); + systemLog.setMessage(message); + systemLog.setMessageAction(action); + systemLog.setMessageResult(result); + systemLog.setUserId(operator.getId()); + systemLog.setUsername(operator.getUsername()); + systemLog.setDisplayName(operator.getDisplayName()); + systemLog.setInstId(operator.getInstId()); + systemLog.setJsonCotent(JsonUtils.gsonToString(entity)); + systemLog.setExecuteTime(new Date()); + _logger.trace("System Log {}" ,systemLog); + getMapper().insert(systemLog); + } + + public String buildMsg(UserInfo userInfo) { + return new StringBuilder() + .append(userInfo.getDisplayName()) + .append("[") + .append(userInfo.getUsername()) + .append("]") + .toString(); + } + + public String buildMsg(Organizations org) { + return new StringBuilder() + .append(org.getOrgName()) + .append("[") + .append(org.getOrgCode()) + .append("]") + .toString(); + } + + public String buildMsg(Accounts account) { + return new StringBuilder() + .append(account.getRelatedUsername()) + .append("[") + .append(account.getDisplayName()).append(",") + .append(account.getUsername()).append(",") + .append(account.getAppName()) + .append("]") + .toString(); + } + + public String buildMsg(ChangePassword changePassword) { + return new StringBuilder() + .append(changePassword.getDisplayName()) + .append("[") + .append(changePassword.getUsername()) + .append("]") + .toString(); + } + + public String buildMsg(Roles g) { + return new StringBuilder() + .append(g.getRoleName()) + .toString(); + } + + public String buildMsg(RoleMember rm) { + return new StringBuilder() + .append(rm.getRoleName()) + .append("[") + .append(rm.getUsername()).append(",") + .append(rm.getDisplayName()) + .append("]") + .toString(); + } + + public String buildMsg(Access permission) { + return new StringBuilder() + .append(permission.getGroupName()) + .append("[") + .append(permission.getAppName()) + .append("]") + .toString(); + } + + public String buildMsg(Permission privilege) { + return new StringBuilder() + .append(privilege.getGroupId()) + .append("[") + .append(privilege.getResourceId()) + .append("]") + .toString(); + } + + + public String buildMsg(Resources r) { + return new StringBuilder() + .append(r.getResourceName()) + .append("[") + .append(r.getResourceType()) + .append("]") + .toString(); + } + + + public String buildMsg(Synchronizers s) { + return new StringBuilder() + .append(s.getName()) + .append("[") + .append(s.getSourceType()).append(",") + .append(s.getScheduler()).append(",") + .append("]") + .toString(); + } + + public String buildMsg(SocialsProvider s) { + return new StringBuilder() + .append(s.getProviderName()) + .append("[") + .append(s.getProvider()) + .append("]") + .toString(); + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/InstitutionsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/InstitutionsServiceImpl.java new file mode 100644 index 00000000..052a8453 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/InstitutionsServiceImpl.java @@ -0,0 +1,33 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.Institutions; +import org.dromara.maxkey.persistence.mapper.InstitutionsMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + + +@Repository +public class InstitutionsServiceImpl extends JpaServiceImpl{ + + public Institutions findByDomain(String domain) { + return getMapper().findByDomain(domain); + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/OrganizationsCastServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/OrganizationsCastServiceImpl.java new file mode 100644 index 00000000..36b637d5 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/OrganizationsCastServiceImpl.java @@ -0,0 +1,37 @@ +/* + * Copyright [2021] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.OrganizationsCast; +import org.dromara.maxkey.persistence.mapper.OrganizationsCastMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; + + +@Repository +public class OrganizationsCastServiceImpl extends JpaServiceImpl{ + static final Logger _logger = LoggerFactory.getLogger(OrganizationsCastServiceImpl.class); + + + public boolean updateCast(OrganizationsCast organizationsCast) { + return getMapper().updateCast(organizationsCast) > 0; + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/OrganizationsServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/OrganizationsServiceImpl.java new file mode 100644 index 00000000..e669c793 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/OrganizationsServiceImpl.java @@ -0,0 +1,176 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.sql.Types; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.dromara.maxkey.entity.idm.Organizations; +import org.dromara.maxkey.persistence.mapper.OrganizationsMapper; +import org.dromara.maxkey.provision.ProvisionAct; +import org.dromara.maxkey.provision.ProvisionService; +import org.dromara.maxkey.provision.ProvisionTopic; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + + +@Repository +public class OrganizationsServiceImpl extends JpaServiceImpl{ + static final Logger _logger = LoggerFactory.getLogger(OrganizationsServiceImpl.class); + + @Autowired + ProvisionService provisionService; + + @Override + public boolean insert(Organizations organization) { + if(super.insert(organization)){ + provisionService.send( + ProvisionTopic.ORG_TOPIC, organization, ProvisionAct.CREATE); + return true; + } + return false; + } + + @Override + public boolean update(Organizations organization) { + if(super.update(organization)){ + provisionService.send( + ProvisionTopic.ORG_TOPIC, organization, ProvisionAct.UPDATE); + return true; + } + return false; + } + + public void saveOrUpdate(Organizations organization) { + Organizations loadOrg =findOne(" id = ? and instid = ?", + new Object[] { organization.getId(), organization.getInstId() }, + new int[] { Types.VARCHAR, Types.VARCHAR }); + if( loadOrg == null) { + insert(organization); + }else { + organization.setId(organization.getId()); + update(organization); + } + } + public List queryOrgs(Organizations organization){ + return getMapper().queryOrgs(organization); + } + + public boolean delete(Organizations organization) { + if(super.delete(organization.getId())){ + provisionService.send( + ProvisionTopic.ORG_TOPIC, organization, ProvisionAct.DELETE); + return true; + } + return false; + } + + + public void reorgNamePath(String instId) { + _logger.debug("instId {}", instId); + if (StringUtils.isBlank(instId)) { + instId = "1"; + } + + HashMap reorgOrgMap = new HashMap<>(); + List orgList = find(" where instid ='" + instId + "'"); + List originOrgList = new ArrayList<>(); + Organizations rootOrg = null; + for (Organizations org : orgList) { + reorgOrgMap.put(org.getId(), org); + if (isRootOrg(org)) { + rootOrg = org; + } + Organizations cloneOrg = new Organizations(); + BeanUtils.copyProperties(org, cloneOrg); + originOrgList.add(cloneOrg); + } + try { + reorg(reorgOrgMap, orgList, rootOrg); + _logger.debug("reorged ."); + long reorgCount = 0; + for (Organizations originOrg : originOrgList) { + Organizations reorgOrg = reorgOrgMap.get(originOrg.getId()); + _logger.trace("reorged Organization {}", reorgOrg); + if (originOrg.getNamePath() == null || !originOrg.getNamePath().equals(reorgOrg.getNamePath())) { + _logger.debug("update reorgCount {} , Organization {}", ++reorgCount, reorgOrg); + getMapper().updateNamePath(reorgOrg); + } + } + _logger.debug("reorg finished ."); + } catch (Exception e) { + _logger.error("reorgNamePath Exception ", e); + } + } + + boolean isRootOrg(Organizations rootOrg) { + if (rootOrg.getParentId() == null || rootOrg.getParentId().equalsIgnoreCase("-1") + || rootOrg.getParentId().equalsIgnoreCase(rootOrg.getId()) + || rootOrg.getParentId().equalsIgnoreCase(rootOrg.getInstId())) { + return true; + } + return false; + } + + void reorg(HashMap orgMap, List orgList, Organizations rootOrg) { + if (isRootOrg(rootOrg)) { + rootOrg.setCodePath("/" + rootOrg.getId() + "/"); + rootOrg.setNamePath("/" + rootOrg.getOrgName() + "/"); + } else { + Organizations parent = orgMap.get(rootOrg.getParentId()); + rootOrg.setCodePath(parent.getCodePath() + rootOrg.getId() + "/"); + rootOrg.setNamePath(parent.getNamePath() + rootOrg.getOrgName() + "/"); + } + rootOrg.setReorgNamePath(true); + + for (Organizations org : orgList) { + if (org.isReorgNamePath()) + continue; + if (org.getParentId().equalsIgnoreCase(rootOrg.getId())) { + reorg(orgMap, orgList, org); + } + } + } + /** + * 根据数据格式返回数据 + * + * @param cell + * @return + */ + public static String getValue(Cell cell) { + if (cell == null) { + return ""; + } else if (cell.getCellType() == CellType.BOOLEAN) { + return String.valueOf(cell.getBooleanCellValue()); + } else if (cell.getCellType() == CellType.NUMERIC) { + cell.setBlank(); + return String.valueOf(cell.getStringCellValue().trim()); + } else { + return String.valueOf(cell.getStringCellValue().trim()); + } + } +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/PermissionRoleServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/PermissionRoleServiceImpl.java new file mode 100644 index 00000000..c0b40e55 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/PermissionRoleServiceImpl.java @@ -0,0 +1,47 @@ +/* + * 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.persistence.service.impl; + +import java.util.List; + +import org.dromara.maxkey.entity.permissions.PermissionRole; +import org.dromara.maxkey.persistence.mapper.PermissionRoleMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; + +@Repository +public class PermissionRoleServiceImpl extends JpaServiceImpl{ + static final Logger _logger = LoggerFactory.getLogger(PermissionRoleServiceImpl.class); + + + public boolean insertPermissionRoles(List permissionRolesList) { + return getMapper().insertPermissionRoles(permissionRolesList)>0; + } + + public boolean deletePermissionRoles(List permissionRolesList) { + return getMapper().deletePermissionRoles(permissionRolesList)>=0; + } + + public List queryPermissionRoles(PermissionRole permissionRole){ + return getMapper().queryPermissionRoles(permissionRole); + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/PermissionServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/PermissionServiceImpl.java new file mode 100644 index 00000000..9ed22487 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/PermissionServiceImpl.java @@ -0,0 +1,45 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.List; + +import org.dromara.maxkey.entity.permissions.Permission; +import org.dromara.maxkey.persistence.mapper.PermissionMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; + +@Repository +public class PermissionServiceImpl extends JpaServiceImpl{ + static final Logger _logger = LoggerFactory.getLogger(PermissionServiceImpl.class); + + public boolean insertGroupPrivileges(List rolePermissionsList) { + return getMapper().insertGroupPrivileges(rolePermissionsList)>0; + }; + + public boolean deleteGroupPrivileges(List rolePermissionsList) { + return getMapper().deleteGroupPrivileges(rolePermissionsList)>=0; + } + + public List queryGroupPrivileges(Permission rolePermissions){ + return getMapper().queryGroupPrivileges(rolePermissions); + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/RegisterServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/RegisterServiceImpl.java new file mode 100644 index 00000000..e3734a54 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/RegisterServiceImpl.java @@ -0,0 +1,36 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.List; + +import org.dromara.maxkey.entity.Register; +import org.dromara.maxkey.entity.idm.UserInfo; +import org.dromara.maxkey.persistence.mapper.RegisterMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class RegisterServiceImpl extends JpaServiceImpl{ + + public UserInfo findByEmail(String email){ + List listUserInfo=getMapper().findByEmail(email); + return listUserInfo.size()>0?listUserInfo.get(0):null; + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/ReportServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/ReportServiceImpl.java new file mode 100644 index 00000000..6e2142ef --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/ReportServiceImpl.java @@ -0,0 +1,64 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.dromara.maxkey.persistence.mapper.ReportMapper; +import org.dromara.mybatis.jpa.entity.JpaEntity; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class ReportServiceImpl extends JpaServiceImpl{ + + public Integer analysisDay(HashMap reportParameter) { + return getMapper().analysisDay(reportParameter); + }; + + public Integer analysisNewUsers(HashMap reportParameter) { + return getMapper().analysisNewUsers(reportParameter); + }; + + public Integer analysisOnlineUsers(HashMap reportParameter) { + return getMapper().analysisOnlineUsers(reportParameter); + }; + + public Integer analysisActiveUsers(HashMap reportParameter) { + return getMapper().analysisActiveUsers(reportParameter); + }; + + public List> analysisDayHour(HashMap reportParameter){ + return getMapper().analysisDayHour(reportParameter); + } + + public List> analysisMonth(HashMap reportParameter){ + return getMapper().analysisMonth(reportParameter); + } + + + public List> analysisBrowser(HashMap reportParameter){ + return getMapper().analysisBrowser(reportParameter); + } + + public List> analysisApp(HashMap reportParameter){ + return getMapper().analysisApp(reportParameter); + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/ResourcesServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/ResourcesServiceImpl.java new file mode 100644 index 00000000..db7b6679 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/ResourcesServiceImpl.java @@ -0,0 +1,33 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.util.List; + +import org.dromara.maxkey.entity.permissions.Resources; +import org.dromara.maxkey.persistence.mapper.ResourcesMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class ResourcesServiceImpl extends JpaServiceImpl{ + + public List queryResourcesTree(Resources resource){ + return getMapper().fetchPageResults(resource); + } +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/RoleMemberServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/RoleMemberServiceImpl.java new file mode 100644 index 00000000..5455350c --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/RoleMemberServiceImpl.java @@ -0,0 +1,78 @@ +/* + * 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.persistence.service.impl; + +import java.util.List; + +import org.dromara.maxkey.entity.idm.UserInfo; +import org.dromara.maxkey.entity.permissions.RoleMember; +import org.dromara.maxkey.entity.permissions.Roles; +import org.dromara.maxkey.persistence.mapper.RoleMemberMapper; +import org.dromara.mybatis.jpa.entity.JpaPageResults; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; + +@Repository +public class RoleMemberServiceImpl extends JpaServiceImpl{ + static final Logger _logger = LoggerFactory.getLogger(RoleMemberServiceImpl.class); + + public int addDynamicRoleMember(Roles dynamicGroup) { + return getMapper().addDynamicRoleMember(dynamicGroup); + } + + public int deleteDynamicRoleMember(Roles dynamicGroup) { + return getMapper().deleteDynamicRoleMember(dynamicGroup); + } + + public int deleteByRoleId(String groupId) { + return getMapper().deleteByRoleId(groupId); + } + + public List queryMemberByRoleId(String groupId){ + return getMapper().queryMemberByRoleId(groupId); + } + + + public JpaPageResults rolesNoMember(RoleMember entity) { + entity.setPageSelectId(entity.generateId()); + entity.setStartRow(calculateStartRow(entity.getPageNumber() ,entity.getPageSize())); + + entity.setPageable(true); + List resultslist = null; + try { + resultslist = getMapper().rolesNoMember(entity); + } catch (Exception e) { + _logger.error("fetchPageResults Exception " , e); + } + entity.setPageable(false); + Integer totalPage = resultslist.size(); + + Integer totalCount = 0; + if(entity.getPageNumber() == 1 && totalPage < entity.getPageSize()) { + totalCount = totalPage; + }else { + totalCount = parseCount(getMapper().fetchCount(entity)); + } + + return new JpaPageResults(entity.getPageNumber(),entity.getPageSize(),totalPage,totalCount,resultslist); + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/RolesServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/RolesServiceImpl.java new file mode 100644 index 00000000..cd3edf11 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/RolesServiceImpl.java @@ -0,0 +1,115 @@ +/* + * 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.persistence.service.impl; + +import java.sql.Types; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.dromara.maxkey.constants.ConstsStatus; +import org.dromara.maxkey.entity.Institutions; +import org.dromara.maxkey.entity.permissions.Roles; +import org.dromara.maxkey.persistence.mapper.RolesMapper; +import org.dromara.maxkey.util.StrUtils; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class RolesServiceImpl extends JpaServiceImpl { + static final Logger _logger = LoggerFactory.getLogger(RolesServiceImpl.class); + + @Autowired + RoleMemberServiceImpl roleMemberService; + + @Autowired + InstitutionsServiceImpl institutionsService; + + + public List queryDynamicRoles(Roles groups){ + return this.getMapper().queryDynamicRoles(groups); + } + + public boolean deleteById(String groupId) { + this.delete(groupId); + roleMemberService.deleteByRoleId(groupId); + return true; + } + + public List queryRolesByUserId(String userId){ + return this.getMapper().queryRolesByUserId(userId); + } + + public void refreshDynamicRoles(Roles dynamicRole){ + if(dynamicRole.getCategory().equals(Roles.Category.DYNAMIC)) { + + if(StringUtils.isNotBlank(dynamicRole.getOrgIdsList())) { + String []orgIds = dynamicRole.getOrgIdsList().split(","); + StringBuffer orgIdFilters = new StringBuffer(); + for(String orgId : orgIds) { + if(StringUtils.isNotBlank(orgId)) { + if(orgIdFilters.length() > 0) { + orgIdFilters.append(","); + } + orgIdFilters.append("'").append(orgId).append("'"); + } + } + if(orgIdFilters.length() > 0) { + dynamicRole.setOrgIdsList(orgIdFilters.toString()); + } + } + + String filters = dynamicRole.getFilters(); + _logger.debug("filters {}" , filters); + if(StringUtils.isNotBlank(filters)) { + if(StrUtils.filtersSQLInjection(filters.toLowerCase())) { + _logger.info("filters include SQL Injection Attack Risk."); + return; + } + //replace & with AND, | with OR + filters = filters.replace("&", " AND ").replace("\\|", " OR "); + + _logger.debug("set filters {}" , filters); + dynamicRole.setFilters(filters); + } + + roleMemberService.deleteDynamicRoleMember(dynamicRole); + roleMemberService.addDynamicRoleMember(dynamicRole); + + } + } + + public void refreshAllDynamicRoles(){ + List instList = + institutionsService.find("where status = ? ", new Object[]{ConstsStatus.ACTIVE}, new int[]{Types.INTEGER}); + for(Institutions inst : instList) { + Roles role = new Roles(); + role.setInstId(inst.getId()); + List rolesList = queryDynamicRoles(role); + for(Roles r : rolesList) { + _logger.debug("role {}" , r); + refreshDynamicRoles(r); + } + } + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SocialsAssociatesServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SocialsAssociatesServiceImpl.java new file mode 100644 index 00000000..b6daedff --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SocialsAssociatesServiceImpl.java @@ -0,0 +1,36 @@ +/* + * 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.dromara.maxkey.persistence.service.impl; + +import java.util.List; + +import org.dromara.maxkey.entity.SocialsAssociate; +import org.dromara.maxkey.entity.idm.UserInfo; +import org.dromara.maxkey.persistence.mapper.SocialsAssociateMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + + +@Repository +public class SocialsAssociatesServiceImpl extends JpaServiceImpl{ + + public List queryByUser(UserInfo user) { + return getMapper().queryByUser(user); + } + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SocialsProviderServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SocialsProviderServiceImpl.java new file mode 100644 index 00000000..257b9561 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SocialsProviderServiceImpl.java @@ -0,0 +1,31 @@ +/* + * Copyright [2021] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.SocialsProvider; +import org.dromara.maxkey.persistence.mapper.SocialsProviderMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; + +@Repository +public class SocialsProviderServiceImpl extends JpaServiceImpl{ + static final Logger _logger = LoggerFactory.getLogger(SocialsProviderServiceImpl.class); + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SynchroRelatedServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SynchroRelatedServiceImpl.java new file mode 100644 index 00000000..a3011666 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SynchroRelatedServiceImpl.java @@ -0,0 +1,65 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + +import java.sql.Types; +import java.util.Date; +import java.util.List; + +import org.dromara.maxkey.entity.SynchroRelated; +import org.dromara.maxkey.entity.Synchronizers; +import org.dromara.maxkey.entity.idm.Organizations; +import org.dromara.maxkey.persistence.mapper.SynchroRelatedMapper; +import org.dromara.maxkey.util.DateUtils; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Repository; + +@Repository +public class SynchroRelatedServiceImpl extends JpaServiceImpl{ + + public int updateSyncTime(SynchroRelated synchroRelated) { + return getMapper().updateSyncTime(synchroRelated); + } + + public List findOrgs(Synchronizers synchronizer) { + return find( + "instid = ? and syncid = ? and objecttype = ? ", + new Object[] { synchronizer.getInstId() ,synchronizer.getId(),Organizations.CLASS_TYPE}, + new int[] { Types.VARCHAR,Types.VARCHAR,Types.VARCHAR} + ); + } + + public SynchroRelated findByOriginId(Synchronizers synchronizer,String originId,String classType) { + return findOne("instid = ? and syncId = ? and originid = ? and objecttype = ? ", + new Object[] { synchronizer.getInstId(),synchronizer.getId(),originId,classType }, + new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,Types.VARCHAR}); + } + + public void updateSynchroRelated(Synchronizers synchronizer,SynchroRelated synchroRelated,String classType) { + SynchroRelated loadSynchroRelated = + findByOriginId( + synchronizer,synchroRelated.getOriginId(),classType ); + if(loadSynchroRelated == null) { + insert(synchroRelated); + }else { + synchroRelated.setId(loadSynchroRelated.getId()); + synchroRelated.setSyncTime(DateUtils.formatDateTime(new Date())); + updateSyncTime(synchroRelated); + } + } +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SynchronizersServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SynchronizersServiceImpl.java new file mode 100644 index 00000000..6dc47626 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/SynchronizersServiceImpl.java @@ -0,0 +1,31 @@ +/* + * Copyright [2021] [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.persistence.service.impl; + +import org.dromara.maxkey.entity.Synchronizers; +import org.dromara.maxkey.persistence.mapper.SynchronizersMapper; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Repository; + +@Repository +public class SynchronizersServiceImpl extends JpaServiceImpl{ + static final Logger _logger = LoggerFactory.getLogger(SynchronizersServiceImpl.class); + +} diff --git a/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/UserInfoServiceImpl.java b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/UserInfoServiceImpl.java new file mode 100644 index 00000000..5bfb1304 --- /dev/null +++ b/maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/UserInfoServiceImpl.java @@ -0,0 +1,420 @@ +/* + * Copyright [2020] [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.persistence.service.impl; + + +import java.sql.Types; +import java.util.Date; + +import org.apache.commons.lang3.StringUtils; +import org.dromara.maxkey.constants.ConstsStatus; +import org.dromara.maxkey.crypto.password.PasswordReciprocal; +import org.dromara.maxkey.entity.Accounts; +import org.dromara.maxkey.entity.ChangePassword; +import org.dromara.maxkey.entity.idm.UserInfo; +import org.dromara.maxkey.persistence.mapper.UserInfoMapper; +import org.dromara.maxkey.persistence.repository.PasswordPolicyValidator; +import org.dromara.maxkey.persistence.service.AccountsService; +import org.dromara.maxkey.provision.ProvisionAct; +import org.dromara.maxkey.provision.ProvisionService; +import org.dromara.maxkey.provision.ProvisionTopic; +import org.dromara.maxkey.web.WebContext; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Repository; + + +/** + * @author Crystal.Sea + * + */ +@Repository +public class UserInfoServiceImpl extends JpaServiceImpl { + static final Logger _logger = LoggerFactory.getLogger(UserInfoServiceImpl.class); + + @Autowired + private PasswordEncoder passwordEncoder; + + @Autowired + PasswordPolicyValidator passwordPolicyValidator; + + @Autowired + ProvisionService provisionService; + + AccountsService accountsService; + + + @Override + public boolean insert(UserInfo userInfo) { + this.passwordEncoder(userInfo); + if (super.insert(userInfo)) { + if(provisionService.getApplicationConfig().isProvisionSupport()) { + UserInfo loadUserInfo = findUserRelated(userInfo.getId()); + provisionService.send( + ProvisionTopic.USERINFO_TOPIC, + loadUserInfo, + ProvisionAct.CREATE); + } + + return true; + } + + return false; + } + + public boolean insert(UserInfo userInfo,boolean passwordEncoder) { + if(passwordEncoder) { + this.passwordEncoder(userInfo); + } + if (super.insert(userInfo)) { + if(provisionService.getApplicationConfig().isProvisionSupport()) { + UserInfo loadUserInfo = findUserRelated(userInfo.getId()); + provisionService.send( + ProvisionTopic.USERINFO_TOPIC, + loadUserInfo, + ProvisionAct.CREATE); + } + + return true; + } + + return false; + } + + @Override + public boolean update(UserInfo userInfo) { + ChangePassword changePassword = this.passwordEncoder(userInfo); + if (super.update(userInfo)) { + if(provisionService.getApplicationConfig().isProvisionSupport()) { + UserInfo loadUserInfo = findUserRelated(userInfo.getId()); + accountUpdate(loadUserInfo); + provisionService.send( + ProvisionTopic.USERINFO_TOPIC, + loadUserInfo, + ProvisionAct.UPDATE); + } + if(userInfo.getPassword() != null) { + changePasswordProvisioning(changePassword); + } + return true; + } + return false; + } + + public boolean delete(UserInfo userInfo) { + UserInfo loadUserInfo = null; + if(provisionService.getApplicationConfig().isProvisionSupport()) { + loadUserInfo = findUserRelated(userInfo.getId()); + } + + if( super.delete(userInfo.getId())){ + provisionService.send( + ProvisionTopic.USERINFO_TOPIC, + loadUserInfo, + ProvisionAct.DELETE); + accountUpdate(loadUserInfo); + return true; + } + return false; + } + + //更新账号状态 + public void accountUpdate(UserInfo userInfo) { + if(userInfo.getStatus() != ConstsStatus.ACTIVE) { + if(accountsService==null) { + accountsService = + WebContext.getBean("accountsService",AccountsService.class); + } + Accounts queryAcount =new Accounts(); + queryAcount.setUserId(userInfo.getId()); + for (Accounts acount : accountsService.query(queryAcount)) { + acount.setStatus(ConstsStatus.INACTIVE); + accountsService.update(acount); + } + } + } + + public UserInfo findUserRelated(String userId) { + UserInfo loadUserInfo =this.get(userId); + loadUserInfo.setDepts(getMapper().findDeptsByUserId(userId)); + return loadUserInfo; + } + + public boolean updateGridList(String gridList,UserInfo userInfo) { + try { + if (gridList != null && !gridList.equals("")) { + userInfo.setGridList(Integer.parseInt(gridList)); + getMapper().updateGridList(userInfo); + } + }catch(Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + + public void saveOrUpdate(UserInfo userInfo) { + UserInfo loadUserInfo = findOne(" username = ? and instid = ?", + new Object[] { userInfo.getUsername(),userInfo.getInstId() }, + new int[] { Types.VARCHAR,Types.VARCHAR}); + if(loadUserInfo == null) { + insert(userInfo); + }else { + userInfo.setId(loadUserInfo.getId()); + userInfo.setPassword(null); + update(userInfo); + } + } + + public boolean updateProtectedApps(UserInfo userinfo) { + try { + userinfo.setModifiedDate(new Date()); + return getMapper().updateProtectedApps(userinfo) > 0; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + public UserInfo findByUsername(String username) { + return getMapper().findByUsername(username); + } + + public UserInfo findByEmailMobile(String emailMobile) { + return getMapper().findByEmailMobile(emailMobile); + } + + public UserInfo findByAppIdAndUsername(String appId,String username){ + try { + UserInfo userinfo = new UserInfo(); + userinfo.setUsername(username); + return getMapper().findByAppIdAndUsername(userinfo) ; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public ChangePassword passwordEncoder(UserInfo userInfo) { + ChangePassword changePassword = null; + if(StringUtils.isNotBlank(userInfo.getPassword())) { + changePassword = new ChangePassword(userInfo); + passwordEncoder(changePassword); + userInfo.setPassword(changePassword.getPassword()); + userInfo.setDecipherable(changePassword.getDecipherable()); + userInfo.setPasswordLastSetTime(changePassword.getPasswordLastSetTime()); + }else { + userInfo.setPassword(null); + userInfo.setDecipherable(null); + } + return changePassword; + } + + public ChangePassword passwordEncoder(ChangePassword changePassword) { + //密码不为空,则需要进行加密处理 + if(StringUtils.isNotBlank(changePassword.getPassword())) { + String password = passwordEncoder.encode(changePassword.getPassword()); + changePassword.setDecipherable(PasswordReciprocal.getInstance().encode(changePassword.getPassword())); + _logger.debug("decipherable : {}",changePassword.getDecipherable()); + changePassword.setPassword(password); + changePassword.setPasswordLastSetTime(new Date()); + + }else { + changePassword.setPassword(null); + changePassword.setDecipherable(null); + } + return changePassword; + } + + /** + * 认证密码修改 + * @param oldPassword + * @param newPassword + * @param confirmPassword + * @param passwordSetType + * @return + */ + public boolean changePassword( ChangePassword changePassword) { + try { + WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, ""); + UserInfo userInfo = this.findByUsername(changePassword.getUsername()); + if(changePassword.getPassword().equals(changePassword.getConfirmPassword())){ + if(StringUtils.isNotBlank(changePassword.getOldPassword()) && + passwordEncoder.matches(changePassword.getOldPassword(), userInfo.getPassword())){ + if(changePassword(changePassword,true) ){ + return true; + } + return false; + }else { + if(StringUtils.isNotBlank(changePassword.getOldPassword())&& + passwordEncoder.matches(changePassword.getPassword(), userInfo.getPassword())) { + WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, + WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_MATCH")); + }else { + WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, + WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_NOT_MATCH")); + } + } + }else { + WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, + WebContext.getI18nValue("PasswordPolicy.CONFIRMPASSWORD_NOT_MATCH")); + } + } catch (Exception e) { + e.printStackTrace(); + } + + return false; + } + + /** + * 后台密码修改 + * @param changeUserInfo + * @param passwordPolicy + * @return + */ + public boolean changePassword(ChangePassword changePassword,boolean passwordPolicy) { + try { + _logger.debug("decipherable old : {}" , changePassword.getDecipherable()); + _logger.debug("decipherable new : {}" , PasswordReciprocal.getInstance().encode(changePassword.getDecipherable())); + + if (passwordPolicy && !passwordPolicyValidator.validator(changePassword)) { + return false; + } + + changePassword = passwordEncoder(changePassword); + + if (getMapper().changePassword(changePassword) > 0) { + changePasswordProvisioning(changePassword); + return true; + } + return false; + + } catch (Exception e) { + e.printStackTrace(); + } + + return false; + } + + public String randomPassword() { + return passwordPolicyValidator.generateRandomPassword(); + } + + public void changePasswordProvisioning(ChangePassword changePassworded) { + if(changePassworded !=null && StringUtils.isNotBlank(changePassworded.getPassword())) { + UserInfo loadUserInfo = findByUsername(changePassworded.getUsername()); + ChangePassword changePassword = new ChangePassword(loadUserInfo); + provisionService.send(ProvisionTopic.PASSWORD_TOPIC, changePassword, ProvisionAct.PASSWORD); + } + } + + public boolean updateAppLoginPassword(UserInfo userinfo) { + try { + userinfo.setModifiedDate(new Date()); + return getMapper().updateAppLoginPassword(userinfo) > 0; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + + /** + * 锁定用户:islock:1 用户解锁 2 用户锁定 + * @param userInfo + */ + public void updateLocked(UserInfo userInfo) { + try { + if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) { + userInfo.setIsLocked(ConstsStatus.LOCK); + getMapper().updateLocked(userInfo); + } + } catch(Exception e) { + e.printStackTrace(); + } + } + + /** + * 用户登录成功后,重置错误密码次数和解锁用户 + * @param userInfo + */ + public void updateLockout(UserInfo userInfo) { + try { + if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) { + userInfo.setIsLocked(ConstsStatus.START); + userInfo.setBadPasswordCount(0); + getMapper().updateLockout(userInfo); + } + } catch(Exception e) { + e.printStackTrace(); + } + } + + /** + * 更新错误密码次数 + * @param userInfo + */ + public void updateBadPasswordCount(UserInfo userInfo) { + try { + if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) { + int updateBadPWDCount = userInfo.getBadPasswordCount() + 1; + userInfo.setBadPasswordCount(updateBadPWDCount); + getMapper().updateBadPWDCount(userInfo); + } + } catch(Exception e) { + e.printStackTrace(); + } + } + + public boolean updateSharedSecret(UserInfo userInfo){ + return getMapper().updateSharedSecret(userInfo)>0; + } + + public boolean updatePasswordQuestion(UserInfo userInfo){ + return getMapper().updatePasswordQuestion(userInfo)>0; + } + + public boolean updateAuthnType(UserInfo userInfo){ + return getMapper().updateAuthnType(userInfo)>0; + } + + public boolean updateEmail(UserInfo userInfo){ + return getMapper().updateEmail(userInfo)>0; + } + + public boolean updateMobile(UserInfo userInfo){ + return getMapper().updateMobile(userInfo)>0; + } + + public int updateProfile(UserInfo userInfo){ + return getMapper().updateProfile(userInfo); + } + + public boolean updateStatus(UserInfo userInfo) { + return getMapper().updateStatus(userInfo) > 0; + } + + public void setPasswordPolicyValidator(PasswordPolicyValidator passwordPolicyValidator) { + this.passwordPolicyValidator = passwordPolicyValidator; + } + +} diff --git a/maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/dromara/maxkey/synchronizer/service/SyncJobConfigFieldService.java b/maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/dromara/maxkey/synchronizer/service/SyncJobConfigFieldService.java index 136c9349..bf70ae9a 100644 --- a/maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/dromara/maxkey/synchronizer/service/SyncJobConfigFieldService.java +++ b/maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/dromara/maxkey/synchronizer/service/SyncJobConfigFieldService.java @@ -2,42 +2,16 @@ package org.dromara.maxkey.synchronizer.service; import org.dromara.maxkey.entity.SyncJobConfigField; -import org.dromara.maxkey.persistence.mapper.SyncJobConfigFieldMapper; -import org.dromara.mybatis.jpa.JpaService; -import org.springframework.stereotype.Service; - -import java.sql.Types; -import java.util.ArrayList; +import org.dromara.mybatis.jpa.IJpaService; import java.util.List; -@Service -public class SyncJobConfigFieldService extends JpaService { - public SyncJobConfigFieldService() { - super(SyncJobConfigFieldMapper.class); - } - @Override - public SyncJobConfigFieldMapper getMapper() { - return (SyncJobConfigFieldMapper)super.getMapper(); - } +public interface SyncJobConfigFieldService extends IJpaService { - public List findByJobIdAndObjectType(Long jobId, String objectType) { + public List findByJobIdAndObjectType(Long jobId, String objectType) ; - return getMapper().findByJobIdAndObjectType(jobId,objectType); - } + public void deleteFieldMapById(Long id); - public void deleteFieldMapById(Long id){ - ArrayList ids = new ArrayList<>(); - ids.add(String.valueOf(id)); - super.deleteBatch(ids); - } - - public List findByJobId(Long jobId) { - List list = find(" jobid = ?", - new Object[]{jobId}, - new int[]{Types.BIGINT}); - return list; - - } + public List findByJobId(Long jobId) ; } diff --git a/maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/dromara/maxkey/synchronizer/service/impl/SyncJobConfigFieldServiceImpl.java b/maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/dromara/maxkey/synchronizer/service/impl/SyncJobConfigFieldServiceImpl.java new file mode 100644 index 00000000..2fb9b7fa --- /dev/null +++ b/maxkey-synchronizers/maxkey-synchronizer/src/main/java/org/dromara/maxkey/synchronizer/service/impl/SyncJobConfigFieldServiceImpl.java @@ -0,0 +1,37 @@ +package org.dromara.maxkey.synchronizer.service.impl; + +import org.dromara.maxkey.entity.SyncJobConfigField; + +import org.dromara.maxkey.persistence.mapper.SyncJobConfigFieldMapper; +import org.dromara.maxkey.synchronizer.service.SyncJobConfigFieldService; +import org.dromara.mybatis.jpa.service.impl.JpaServiceImpl; +import org.springframework.stereotype.Service; + +import java.sql.Types; +import java.util.ArrayList; +import java.util.List; + +@Service +public class SyncJobConfigFieldServiceImpl extends JpaServiceImpl implements SyncJobConfigFieldService { + + public List findByJobIdAndObjectType(Long jobId, String objectType) { + + return getMapper().findByJobIdAndObjectType(jobId,objectType); + } + + public void deleteFieldMapById(Long id){ + ArrayList ids = new ArrayList<>(); + ids.add(String.valueOf(id)); + super.deleteBatch(ids); + } + + public List findByJobId(Long jobId) { + List list = find(" jobid = ?", + new Object[]{jobId}, + new int[]{Types.BIGINT}); + return list; + + } + + +} diff --git a/setEnvVars.bat b/setEnvVars.bat index f8ad7014..3769e08f 100644 --- a/setEnvVars.bat +++ b/setEnvVars.bat @@ -1,6 +1,6 @@ echo off echo set env -set JAVA_HOME=C:\IDE\jdk-17.0.2.8 +set JAVA_HOME=C:\ide\jdk-17.0.9+9 set GRADLE_HOME=C:\ide\gradle-8.8 set MXK_VERSION=4.1.2