当前位置: 首页>>代码示例>>Java>>正文


Java SecurityConfig类代码示例

本文整理汇总了Java中org.springframework.security.access.SecurityConfig的典型用法代码示例。如果您正苦于以下问题:Java SecurityConfig类的具体用法?Java SecurityConfig怎么用?Java SecurityConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SecurityConfig类属于org.springframework.security.access包,在下文中一共展示了SecurityConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadResourceDefine

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
@PostConstruct
private void loadResourceDefine() {
	//System.err.println(" ---------------MaxSecurityMetadataSource loadResourceDefine--------------- ");
	if (resourceMap == null) {
		resourceMap = new HashMap<String, Collection<ConfigAttribute>>();
		List<Resources> resources = authService.fetchAllResources();
		for (Resources resource : resources) {
			Collection<ConfigAttribute> configAttributes = new ArrayList<ConfigAttribute>();
			Set<Role> roles = resource.getRoles();
			for(Role r : roles) {
				ConfigAttribute configAttribute = new SecurityConfig(r.getRoleKey());
				configAttributes.add(configAttribute);
			}
			resourceMap.put(resource.getResUrl(), configAttributes);
		}
	}
}
 
开发者ID:Fetax,项目名称:Fetax-AI,代码行数:18,代码来源:MainSecurityMetadataSource.java

示例2: decide

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
@Override
public void decide(Authentication authentication, Object object,Collection<ConfigAttribute> configAttributes)
		
		throws AccessDeniedException, InsufficientAuthenticationException {
	
	if(configAttributes == null){
		return	;
	}
	Iterator<ConfigAttribute> ite = configAttributes.iterator();
	while(ite.hasNext()){
		
		ConfigAttribute ca = ite.next();
		
		String needRole = ((SecurityConfig)ca).getAttribute();
		
		for(GrantedAuthority grantedAuthority : authentication.getAuthorities()){
			if(needRole.trim().equals(grantedAuthority.getAuthority().trim())){
				return;
			}
		}
	}
	//û��Ȩ�޷���
	throw new AccessDeniedException("û��Ȩ�޷��ʣ�");

}
 
开发者ID:wanliyang10010,项目名称:Shop,代码行数:26,代码来源:MyAccessDecisionManager.java

示例3: decide

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
/**
 * 自定义访问策略
 * 
 * @param authentication
 *            用户及用户权限信息
 * @param object
 * @param configAttributes
 *            访问资源需要的权限
 * @throws AccessDeniedException
 * @throws InsufficientAuthenticationException
 * @see org.springframework.security.access.AccessDecisionManager#decide(org.springframework.security.core.Authentication,
 *      java.lang.Object, java.util.Collection)
 */
public void decide(Authentication authentication, Object object,
		Collection<ConfigAttribute> configAttributes)
		throws AccessDeniedException, InsufficientAuthenticationException {
	SysUserVO user = (SysUserVO) authentication.getPrincipal();
	logger.info("访问资源的用户为" + user.getUsername());
	// 如果访问资源不需要任何权限则直接通过
	if (configAttributes == null) {
		return;
	}
	Iterator<ConfigAttribute> ite = configAttributes.iterator();
	// 遍历configAttributes看用户是否有访问资源的权限
	while (ite.hasNext()) {
		ConfigAttribute ca = ite.next();
		String needRole = ((SecurityConfig) ca).getAttribute();
		// ga 为用户所被赋予的权限。 needRole 为访问相应的资源应该具有的权限。
		for (GrantedAuthority ga : authentication.getAuthorities()) {
			if (needRole.trim().equals(ga.getAuthority().trim())) {
				return;
			}
		}
	}
	throw new AccessDeniedException("没有权限访问! ");
}
 
开发者ID:linmuxi,项目名称:SpringSecurity,代码行数:37,代码来源:DefaultAccessDecisionManager.java

示例4: addSecurityConfig

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
private void addSecurityConfig(FilterInvocation filterInvocation, Collection<ConfigAttribute> guiConfigAttr,
                   String url, DisplayableValue<String>[] actions) {

     AntPathRequestMatcher matcher = new AntPathRequestMatcher(url);
     if (!matcher.matches(filterInvocation.getRequest()) || actions == null) {
         return;
     }
     
     for (DisplayableValue<String> action : actions) {
         String actionUri = action.getValue();
         if (StringUtils.isBlank(actionUri)) {
             continue;
         }

         //all users has permission to access these resources
         if (action.equals(AuthorizationConstants.AUTZ_UI_PERMIT_ALL_URL)) {
             return;
         }

         SecurityConfig config = new SecurityConfig(actionUri);
if (!guiConfigAttr.contains(config)) {
	guiConfigAttr.add(config);
}
     }
 }
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:26,代码来源:MidPointGuiAuthorizationEvaluator.java

示例5: getAttributes1

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
@Test
public void getAttributes1() {
   SetpointSecuredSecurityMetadataSource mds = (SetpointSecuredSecurityMetadataSource) SetpointSecuredSecurityMetadataSource
         .instance();
   CibetMethodInvocation mi = new CibetMethodInvocation(null, null, null, null, null);
   mi.addRule("Secured", "' ROLE_ADMIN\", 'ROLE_DARM'}");

   Collection<ConfigAttribute> attributes = mds.getAttributes(mi);
   Assert.assertEquals(2, attributes.size());
   Assert.assertEquals(SecurityConfig.class, attributes.iterator().next().getClass());
   Iterator<ConfigAttribute> it = attributes.iterator();
   SecurityConfig sc1 = (SecurityConfig) it.next();
   Assert.assertEquals("ROLE_ADMIN", sc1.getAttribute());
   SecurityConfig sc2 = (SecurityConfig) it.next();
   Assert.assertEquals("ROLE_DARM", sc2.getAttribute());
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:17,代码来源:SetpointSecuredSecurityMetadataSourceTest.java

示例6: getAttributes

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
/**
 * 根据路径获取访问权限的集合接口
 *
 * @param object
 * @return
 * @throws IllegalArgumentException
 */
@Override
public Collection<ConfigAttribute> getAttributes(Object object)
        throws IllegalArgumentException {
    HttpServletRequest request = ((FilterInvocation) object).getHttpRequest();
    List<ConfigAttribute> attrs = new ArrayList<>();
    try {
        List<Permission> permissions = permissionService.findAll();
        for (Permission p : permissions) {
            AntPathRequestMatcher matcher = new AntPathRequestMatcher(p.getUrl());
            if (matcher.matches(request)) {
                attrs.add(new SecurityConfig(p.getCode()));
            }
        }
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

    return attrs;
}
 
开发者ID:microacup,项目名称:microbbs,代码行数:27,代码来源:MyInvocationSecurityMetadataSource.java

示例7: getAllConfigAttributes

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
/**
 * 获取所有角色权限
 * @return
 */
@Override
public Collection<ConfigAttribute> getAllConfigAttributes() {
    //从数据库查出所有角色实体
    List<RoleEntity> roleEntities = roleService.findAll();

    //所有角色权限列表
    List<ConfigAttribute> configAttributes = new ArrayList<>();

    if(roleEntities == null || roleEntities.isEmpty())
        return configAttributes;

    //遍历,把角色权限加进角色权限列表中
    for(RoleEntity re : roleEntities){
        ConfigAttribute ca = new SecurityConfig(re.getName());
        configAttributes.add(ca);
    }

    return configAttributes;
}
 
开发者ID:JasonChanBest,项目名称:prometheus,代码行数:24,代码来源:CustomFilterInvocationSecurityMetadataSource.java

示例8: getFilterSecurityInterceptor

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
/**
 * Gets the filter security interceptor.
 *
 * @return the filter security interceptor
 */
@Bean(name = "fsi")
public FilterSecurityInterceptor getFilterSecurityInterceptor() {
  FilterSecurityInterceptor interceptor = new FilterSecurityInterceptor();
  interceptor.setAuthenticationManager(getProviderManager());
  interceptor.setAccessDecisionManager(getAffirmativeBased());

  LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestMap = new LinkedHashMap<>();
  requestMap.put(new AntPathRequestMatcher("/adm/**"),
      SecurityConfig.createListFromCommaDelimitedString("ROLE_MANAGER,ROLE_MANAGER-GUI"));
  requestMap.put(new AntPathRequestMatcher("/adm/restartvm.ajax"), SecurityConfig
      .createListFromCommaDelimitedString("ROLE_POWERUSERPLUS,ROLE_MANAGER,ROLE_MANAGER-GUI"));
  requestMap.put(new AntPathRequestMatcher("/sql/**"), SecurityConfig
      .createListFromCommaDelimitedString("ROLE_POWERUSERPLUS,ROLE_MANAGER,ROLE_MANAGER-GUI"));
  requestMap.put(new AntPathRequestMatcher("/app/**"),
      SecurityConfig.createListFromCommaDelimitedString(
          "ROLE_POWERUSER,ROLE_POWERUSERPLUS,ROLE_MANAGER,ROLE_MANAGER-GUI"));
  requestMap.put(new AntPathRequestMatcher("/**"),
      SecurityConfig.createListFromCommaDelimitedString(
          "ROLE_PROBEUSER,ROLE_POWERUSER,ROLE_POWERUSERPLUS,ROLE_MANAGER,ROLE_MANAGER-GUI"));

  interceptor
      .setSecurityMetadataSource(new DefaultFilterInvocationSecurityMetadataSource(requestMap));
  return interceptor;
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:30,代码来源:ProbeSecurityConfig.java

示例9: decide

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes)
		throws AccessDeniedException, InsufficientAuthenticationException {
	log.debug("decide calling {},{}", object, configAttributes);
	if (configAttributes == null) {
		return;
	}
	System.out.println("decide " + object.toString()); // object is a URL.
	Iterator<ConfigAttribute> ite = configAttributes.iterator();
	while (ite.hasNext()) {
		ConfigAttribute ca = ite.next();
		String needRole = ((SecurityConfig) ca).getAttribute();
		for (GrantedAuthority ga : authentication.getAuthorities()) {
			if (needRole.equals(ga.getAuthority())) { // ga is user's role.
				return;
			}
		}
	}
	throw new AccessDeniedException("no right");
}
 
开发者ID:8090boy,项目名称:gomall.la,代码行数:20,代码来源:MyAccessDecisionManager.java

示例10: loadRoleByResource

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
public Collection<ConfigAttribute> loadRoleByResource(String url) {
	try {
		String sql = "select ro.name as role,re.res_string as url " + "from ls_role ro join ls_resc_role rr on ro.id=rr.role_id "
				+ "join ls_resource re on re.id=rr.resc_id " + "where re.res_string='" + url + "'";
		List<Map<String, Object>> authList = jdbcTemplate.queryForList(sql);
		Collection<ConfigAttribute> auths = new ArrayList<ConfigAttribute>();

		for (Map<String, Object> map : authList) {
			ConfigAttribute auth = new SecurityConfig(map.get("role").toString());
			auths.add(auth);
		}

		return auths;
	} catch (RuntimeException re) {
		log.error("find roles by url failed " + re);
		throw re;
	}
}
 
开发者ID:8090boy,项目名称:gomall.la,代码行数:19,代码来源:ResourcesDao.java

示例11: loadResourceDefine

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
private void loadResourceDefine() {
	if(resourceMap == null) {
		resourceMap = new HashMap<String, Collection<ConfigAttribute>>();
		List<Permission> resources = this.permissionManager.findAll();
		for (Permission resource : resources) {
			Collection<ConfigAttribute> configAttributes = new ArrayList<ConfigAttribute>();
               //以权限名封装为Spring的security Object
			ConfigAttribute configAttribute = new SecurityConfig(resource.getId());
			configAttributes.add(configAttribute);
			resourceMap.put(resource.getUrl(), configAttributes);
		}
	}
	
	Set<Entry<String, Collection<ConfigAttribute>>> resourceSet = resourceMap.entrySet();
	Iterator<Entry<String, Collection<ConfigAttribute>>> iterator = resourceSet.iterator();
	
}
 
开发者ID:545473750,项目名称:zswxsqxt,代码行数:18,代码来源:MySecurityMetadataSource.java

示例12: loadResourceDefine

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
/**
 * 加载所有资源与权限的关系 
 */
public synchronized void loadResourceDefine() {
	List<Menu> resources = menuMapper.getMenuList();
	if (resourceMap == null) 
		resourceMap = new HashMap<String, Collection<ConfigAttribute>>((int)(resources.size()/0.75F));
	else
		resourceMap.clear();
	for (Menu resource : resources) {
		if("1".equals(resource.getMenulevcod())) continue;
		//获取可以访问这个资源的角色
		List<Role> roleList = roleMapper.getRoleListByAuthority(resource.getMenu_id());
		if(null == roleList || roleList.size() == 0) continue;
		Collection<ConfigAttribute> configAttributes = new ArrayList<ConfigAttribute>();
		for (Role role : roleList) {
			configAttributes.add(new SecurityConfig(role.getRole_name()));
		}
		//授权信息存入内存
		resourceMap.put(MMT.FILTER_ROOT + resource.getMenuurl(), configAttributes);
	}
}
 
开发者ID:cjm0000000,项目名称:mmt,代码行数:23,代码来源:MMTSecurityMetadataSource.java

示例13: execute

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
public void execute(
        DelegatingMethodSecurityMetadataSource delegatingMethodSecurityMetadataSource,
        Map<String, String> resourceMap) {
    Assert.notNull(delegatingMethodSecurityMetadataSource);
    Assert.notNull(resourceMap);

    logger.info("refresh method resource");

    Map<String, List<ConfigAttribute>> methodMap = null;
    methodMap = new LinkedHashMap<String, List<ConfigAttribute>>();

    for (Map.Entry<String, String> entry : resourceMap.entrySet()) {
        methodMap.put(entry.getKey(), SecurityConfig
                .createListFromCommaDelimitedString(entry.getValue()));
    }

    MethodSecurityMetadataSource source = new MapBasedMethodSecurityMetadataSource(
            methodMap);
    List<MethodSecurityMetadataSource> sources = new ArrayList<MethodSecurityMetadataSource>();
    sources.add(source);

    List<MethodSecurityMetadataSource> methodSecurityMetadataSources = delegatingMethodSecurityMetadataSource
            .getMethodSecurityMetadataSources();
    methodSecurityMetadataSources.clear();
    methodSecurityMetadataSources.addAll(sources);

    Map attributeCache = (Map) BeanUtils.safeGetFieldValue(
            delegatingMethodSecurityMetadataSource, "attributeCache");
    attributeCache.clear();
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:31,代码来源:MethodResourcePopulator.java

示例14: refresh

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
public void refresh() {
    if ((delegatingMethodSecurityMetadataSource == null)
            || (methodSourceFetcher == null)) {
        logger.info(
                "delegatingMethodSecurityMetadataSource : {}, methodSourceFetcher : {}",
                delegatingMethodSecurityMetadataSource, methodSourceFetcher);

        return;
    }

    logger.info("execute refresh");

    Map<String, List<ConfigAttribute>> methodMap = null;
    methodMap = new LinkedHashMap<String, List<ConfigAttribute>>();

    Map<String, String> resourceMap = methodSourceFetcher.getSource(null);

    for (Map.Entry<String, String> entry : resourceMap.entrySet()) {
        methodMap.put(entry.getKey(), SecurityConfig
                .createListFromCommaDelimitedString(entry.getValue()));
    }

    MethodSecurityMetadataSource source = new MapBasedMethodSecurityMetadataSource(
            methodMap);
    List<MethodSecurityMetadataSource> sources = new ArrayList<MethodSecurityMetadataSource>();
    sources.add(source);

    List<MethodSecurityMetadataSource> methodSecurityMetadataSources = delegatingMethodSecurityMetadataSource
            .getMethodSecurityMetadataSources();
    methodSecurityMetadataSources.clear();
    methodSecurityMetadataSources.addAll(sources);

    Map attributeCache = (Map) BeanUtils.safeGetFieldValue(
            delegatingMethodSecurityMetadataSource, "attributeCache");
    attributeCache.clear();
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:37,代码来源:MethodSourceBuilder.java

示例15: execute

import org.springframework.security.access.SecurityConfig; //导入依赖的package包/类
public void execute(FilterSecurityInterceptor filterSecurityInterceptor,
        Map<String, String> resourceMap) {
    Assert.notNull(filterSecurityInterceptor);
    Assert.notNull(resourceMap);

    logger.info("refresh url resource");

    LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestMap = null;
    requestMap = new LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>>();

    for (Map.Entry<String, String> entry : resourceMap.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        requestMap.put(new AntPathRequestMatcher(key),
                SecurityConfig.createListFromCommaDelimitedString(value));
    }

    FilterInvocationSecurityMetadataSource source = new DefaultFilterInvocationSecurityMetadataSource(
            requestMap);
    filterSecurityInterceptor.setSecurityMetadataSource(source);
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:22,代码来源:UrlResourcePopulator.java


注:本文中的org.springframework.security.access.SecurityConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。