All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.base4j.mvc.auth.CustomInvocationSecurityMetadataSourceService Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package com.base4j.mvc.auth;

import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;

import java.util.Collection;

//@Service
public class CustomInvocationSecurityMetadataSourceService implements FilterInvocationSecurityMetadataSource {
    @Override
    public Collection getAttributes(Object object) throws IllegalArgumentException {
        return null;
    }

    @Override
    public Collection getAllConfigAttributes() {
        return null;
    }

    @Override
    public boolean supports(Class clazz) {
        return false;
    }

//    private static Map> resourceMap = null;
//
//    @Override
//    public Collection getAttributes(Object object) throws IllegalArgumentException {
//        System.out.println("nwuidhwuiehdfu");
//        // object 是一个URL,被用户请求的url。
//        FilterInvocation filterInvocation = (FilterInvocation) object;
//        if (resourceMap == null) {
//            loadResourceDefine();
//        }
//        Iterator ite = resourceMap.keySet().iterator();
//        while (ite.hasNext()) {
//            String resURL = ite.next();
//            RequestMatcher requestMatcher = new AntPathRequestMatcher(resURL);
//            if (requestMatcher.matches(filterInvocation.getHttpRequest())) {
//                return resourceMap.get(resURL);
//            }
//        }
//
//        return null;
//    }
//
//    @Override
//    public Collection getAllConfigAttributes() {
//        return new ArrayList();
//    }
//
//    @Override
//    public boolean supports(Class clazz) {
//        return true;
//    }
//
//    /**
//     * 在Web服务器启动时,提取系统中的所有权限
//     */
//    @PostConstruct
//    private void loadResourceDefine() {
//        List> list = sRoleVODao.findAll();
//        List query = new ArrayList();
//        if (list != null && list.size() > 0) {
//            for (Map sr : list) {
//                //String name = sr.get("name")
//                Object value = sr.get("name");
//                String name = String.valueOf(value);
//                query.add(name);
//            }
//        }
//        resourceMap = new HashMap>();
//        for (String auth : query) {
//            ConfigAttribute ca = new SecurityConfig(auth);
//            //List> query1 = sResourceVODao.findByRoleName(auth);
//            List query1 = new ArrayList();
//            List> list1 = sResourceVODao.findByRoleName(auth);
//            if (list1 != null && list1.size() > 0) {
//                for (Map map : list1) {
//                    Object value = map.get("resource_string");
//                    String url = String.valueOf(value);
//                    query1.add(url);
//                }
//            }
//            for (String res : query1) {
//                String url = res;
//                if (resourceMap.containsKey(url)) {
//
//                    Collection value = resourceMap.get(url);
//                    value.add(ca);
//                    resourceMap.put(url, value);
//                } else {
//                    Collection atts = new ArrayList();
//                    atts.add(ca);
//                    resourceMap.put(url, atts);
//                }
//            }
//        }
//    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy