com.hazelcast.core.MultiMap Java Examples

The following examples show how to use com.hazelcast.core.MultiMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AclResourceServiceImpl.java    From jvue-admin with MIT License 6 votes vote down vote up
@Override
public String getName(Integer id) {
    MultiMap<Integer, AclResource> resourcesMap =
            hazelcastInstance.getMultiMap("acl-resource");
    
    Integer classId = id - id % 100;
    Collection<AclResource> apiResources = resourcesMap.get(classId);
    for (AclResource ar: apiResources) {
        if (Objects.equals(ar.getId(), id)) {
            return ar.getName();
        }
    }
    
    logger.warn("Cant find the api-name for id {}", id);
    
    return "";
}
 
Example #2
Source File: JvueApiController.java    From jvue-admin with MIT License 5 votes vote down vote up
@GetMapping("resources")
@ApiOperation(value = "资源")
@AclResc(id = 11)
public BaseModel<List<AclResource>> getResources() {
    MultiMap<Integer, AclResource> resourcesMap = hazelcastInstance.getMultiMap("acl-resource");
    
    Collection<AclResource> list = resourcesMap.values();
    return new BaseModel<List<AclResource>>().setData(new ArrayList<>(list));
}
 
Example #3
Source File: WebConfigurerTest.java    From flair-engine with Apache License 2.0 4 votes vote down vote up
@Override
public <K, V> MultiMap<K, V> getMultiMap(String s) {
    return null;
}
 
Example #4
Source File: RoleAccessDecisionManager.java    From jvue-admin with MIT License 4 votes vote down vote up
@Override
    public void decide(Authentication authentication, Object arg1, Collection<ConfigAttribute> arg2)
            throws AccessDeniedException, InsufficientAuthenticationException {
        // TODO Auto-generated method stub
        logger.debug("arg0 {}, arg1 {}, arg2 {}", authentication, arg1, arg2);
        // 逻辑
        if (arg1 instanceof FilterInvocation) {
            // HTTP filter object
            FilterInvocation filterInvocation = (FilterInvocation) arg1;
            
//            // 1.判断是否为超级管理员,是的话直接放行
//            if (authentication.getPrincipal() instanceof JwtUserDetails) {
//                JwtUserDetails jwtUser = (JwtUserDetails) authentication.getPrincipal();
//                if (jwtUser.getSuperUser() == JvueDataStatus.SUPER_USER_TRUE) {
//                    // 放行
//                    logger.debug("SUPER_USER_TRUE");
//                    return ;
//                }
//            }
            
            // 1.判断URL对应的权限定义
            MultiMap<Integer, AclResource> resourcesMap =
                    hazelcastInstance.getMultiMap("acl-resource");
            // >> arg1 FilterInvocation: URL: /module?page=0&pageSize=10
            // >> 如果不需要登录的话,直接放行
            String requestUrl = filterInvocation.getRequestUrl();
            String requestMethod = filterInvocation.getRequest().getMethod();
            
            Integer apiCode = null;
            logger.debug("访问接口:{} {}", requestUrl, requestMethod);
            
            for (AclResource ar: resourcesMap.values()) {
                if (ar.getType() == AclResource.Type.METHOD) {
                    //pathHelper.
                    boolean isUrl = false;
                    boolean isMethod = false;
                    
                    logger.trace("判断接口:{} {} {}, {}", ar.getCode(), ar.getName(), ar.getPath(), ar.getPattern());

                    for (String path : ar.getPattern()) {
                        isUrl = pathMatcher.match(path, requestUrl);
                        if (isUrl) {
                            break;
                        }
                    }
                    if (isUrl) {
                        if (ar.getMethod() != null) {
                            for (String method: ar.getMethod()) {
                                if (Objects.equals(method, requestMethod)){
                                    isMethod = true;
                                    break;
                                }
                            }
                        } else {
                            isMethod = true;
                        }
                    }
                    
                    if (isUrl && isMethod) {
                        // 已匹配
                        apiCode = ar.getId();
                        logger.debug("已匹配接口:{} > {} {}", requestUrl, ar.getCode(), ar.getName());
                        break;
                    }
                }
            }
            
            if (apiCode != null ) {
                // 取对应的角色权限
                List<Integer> roles = jvueRoleService.getRolesByApi(apiCode);
                
                if (!roles.isEmpty()) {
                    // 2.判断是否为超级管理员,是的话直接放行
                    if (authentication.getPrincipal() instanceof JwtUserDetails) {
                        JwtUserDetails jwtUser = (JwtUserDetails) authentication.getPrincipal();
                        Collection<Integer> intersection =
                                CollectionUtils.intersection(roles, jwtUser.getRoles());
                        if (intersection.isEmpty()) {
                            // 没有匹配到角色
                            throw new AccessDeniedException("no role");
                        }

                    }
                }
            }
            
            // 处理 apiCode与角色匹配
            
            // 3.获取用户的角色,通过比对角色授予的API接口ID和AclResource里定义的ID,有匹配则放行
            
            // 4.上述以外,禁止调用
            // TODO throw new AccessDeniedException("no role");
        }
    }
 
Example #5
Source File: AclResourceServiceImpl.java    From jvue-admin with MIT License 4 votes vote down vote up
@Override
public List<AclResource> getAll() {
  MultiMap<Integer, AclResource> resourcesMap =
          hazelcastInstance.getMultiMap("acl-resource");
  return Lists.newArrayList(resourcesMap.values());
}