RolesService.java 3.2 KB
Newer Older
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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.
 */
 

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
18
package org.maxkey.persistence.service;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
19 20 21 22

import java.util.List;

import org.apache.mybatis.jpa.persistence.JpaBaseService;
M
modify  
MaxKey 已提交
23
import org.maxkey.entity.RolePrivileges;
M
MaxKey 已提交
24
import org.maxkey.entity.Roles;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
25
import org.maxkey.persistence.mapper.RolesMapper;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
26 27 28
import org.maxkey.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
29 30
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
M
MaxKey 已提交
31
import org.springframework.stereotype.Repository;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
32

M
MaxKey 已提交
33
@Repository
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
34
public class RolesService  extends JpaBaseService<Roles>{
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
35 36
    final static Logger _logger = LoggerFactory.getLogger(RolesService.class);
    
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
37 38 39 40
    @Autowired
    @Qualifier("roleMemberService")
    RoleMemberService roleMemberService;
    
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
41 42 43 44 45 46 47 48 49 50 51 52
	public RolesService() {
		super(RolesMapper.class);
	}

	/* (non-Javadoc)
	 * @see com.connsec.db.service.BaseService#getMapper()
	 */
	@Override
	public RolesMapper getMapper() {
		return (RolesMapper)super.getMapper();
	}
	
M
modify  
MaxKey 已提交
53 54
	public boolean insertRolePrivileges(List<RolePrivileges> rolePermissionsList) {
	    return getMapper().insertRolePrivileges(rolePermissionsList)>0;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
55 56
	};
    
M
modify  
MaxKey 已提交
57 58
	public boolean deleteRolePrivileges(List<RolePrivileges> rolePermissionsList) {
	     return getMapper().deleteRolePrivileges(rolePermissionsList)>=0;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
59 60
	 }
	
M
modify  
MaxKey 已提交
61 62
    public List<RolePrivileges> queryRolePrivileges(RolePrivileges rolePermissions){
        return getMapper().queryRolePrivileges(rolePermissions);
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
63
    }
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    
    public List<Roles> queryDynamicRoles(Roles dynamicRole){
        return this.getMapper().queryDynamicRoles(dynamicRole);
    }
    
    public boolean deleteById(String roleId) {
        this.remove(roleId);
        roleMemberService.deleteByRoleId(roleId);
        return true;
    }
    
    public void refreshDynamicRoles(Roles dynamicRole){
        if(dynamicRole.getDynamic().equals("1")) {
            if(dynamicRole.getOrgIdsList()!=null && !dynamicRole.getOrgIdsList().equals("")) {
                dynamicRole.setOrgIdsList("'"+dynamicRole.getOrgIdsList().replace(",", "','")+"'");
            }
            
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
81 82 83 84 85 86 87 88 89 90 91
            String filters = dynamicRole.getFilters();
            if(StringUtils.filtersSQLInjection(filters.toLowerCase())) {  
                _logger.info("filters include SQL Injection Attack Risk.");
                return;
            }
            
            filters = filters.replace("&", " AND ");
            filters = filters.replace("|", " OR ");
            
            dynamicRole.setFilters(filters);
            
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
92 93 94 95
            roleMemberService.deleteDynamicRoleMember(dynamicRole);
            roleMemberService.addDynamicRoleMember(dynamicRole);
        }
    }
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
96
}