本文整理汇总了Java中org.springframework.security.access.ConfigAttribute.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigAttribute.getAttribute方法的具体用法?Java ConfigAttribute.getAttribute怎么用?Java ConfigAttribute.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.access.ConfigAttribute
的用法示例。
在下文中一共展示了ConfigAttribute.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decide
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
@Override
public void decide(Authentication authentication, Object o, Collection<ConfigAttribute> collection)
throws AccessDeniedException, InsufficientAuthenticationException {
if (collection == null) {
return;
}
String needRole;
//遍历需要的角色,如果一样,则通过
CustomerUserDetail userDetail = (CustomerUserDetail) authentication.getPrincipal();
List<Role> userRoleList = securityService.getUserRoleList(userDetail.getUsername(), userDetail.getAccountType());
for (ConfigAttribute configAttribute : collection) {
needRole = configAttribute.getAttribute();
for (Role role : userRoleList) {
if (needRole.equals(role.getRoleCode())) {
return;
}
}
}
throw new AccessDeniedException("Cannot Access!");
}
示例2: decide
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes)
throws AccessDeniedException, InsufficientAuthenticationException {
//System.err.println(" ---------------MaxAccessDecisionManager decide--------------- ");
if(configAttributes == null) {
return;
}
//所请求的资源拥有的权限(一个资源对多个权限)
Iterator<ConfigAttribute> iterator = configAttributes.iterator();
while(iterator.hasNext()) {
ConfigAttribute configAttribute = iterator.next();
//访问所请求资源所需要的权限
String needPermission = configAttribute.getAttribute();
//System.out.println("NEED-> "+needPermission);
//用户所拥有的权限authentication
for(GrantedAuthority ga : authentication.getAuthorities()) {
//System.out.println("USER-> "+ga.getAuthority());
if(needPermission.equals(ga.getAuthority())) {
//System.out.println("pass");
return;
}
}
}
//没有权限
throw new AccessDeniedException("Access Denide!");
}
示例3: decide
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if(null== configAttributes || configAttributes.size() <=0) {
return;
}
ConfigAttribute c;
String needRole;
for(Iterator<ConfigAttribute> iter = configAttributes.iterator(); iter.hasNext(); ) {
c = iter.next();
needRole = c.getAttribute();
for(GrantedAuthority ga : authentication.getAuthorities()) {
if(needRole.trim().equals(ga.getAuthority())) {
return;
}
}
}
throw new AccessDeniedException("no right");
}
示例4: decide
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if(null== configAttributes || configAttributes.size() <=0) {
return;
}
ConfigAttribute c;
String needRole;
for(Iterator<ConfigAttribute> iter = configAttributes.iterator(); iter.hasNext(); ) {
c = iter.next();
needRole = c.getAttribute();
for(GrantedAuthority ga : authentication.getAuthorities()) {
if(needRole.trim().equals(ga.getAuthority())) {
return;
}
}
}
throw new AccessDeniedException("no right");
}
示例5: decide
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
@Override
public void decide(Authentication authentication, Object o, Collection<ConfigAttribute> collection)
throws AccessDeniedException, InsufficientAuthenticationException {
if (collection == null) {
return;
}
String needRole;
//遍历需要的角色,如果一样,则通过,避免角色信息变了,从数据库取
CustomerUserDetail userDetail = (CustomerUserDetail) authentication.getPrincipal();
List<Role> roleList = securityService.getUserRoleList(userDetail.getUsername(), userDetail.getAccountType());
for (ConfigAttribute configAttribute : collection) {
needRole = configAttribute.getAttribute();
for (Role aRoleList : roleList) {
if (aRoleList != null && needRole.equals(aRoleList.getRoleCode())) {
return;
}
}
}
throw new AccessDeniedException("Cannot Access!");
}
示例6: decide
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if (configAttributes == null) {
return;
}
for (ConfigAttribute ca : configAttributes) {
String needRole = ca.getAttribute();
//ga 为用户所被赋予的权限。 needRole 为访问相应的资源应该具有的权限。
for (GrantedAuthority ga : authentication.getAuthorities()) {
if (needRole.trim().equals(ga.getAuthority().trim())) {
return;
}
}
}
throw new AccessDeniedException("没有权限进行操作!");
}
示例7: decide
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
/**
* @param authentication
* @param object
* @param configAttributes
* @throws org.springframework.security.access.AccessDeniedException
* @throws org.springframework.security.authentication.InsufficientAuthenticationException
*/
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) {
if (null == configAttributes || configAttributes.size() <= 0) {
return;
}
for (ConfigAttribute attr : configAttributes) {
String attribute = attr.getAttribute();
for (GrantedAuthority ga : authentication.getAuthorities()) {
if (attribute.equals(ga.getAuthority())) {
return;
}
}
}
throw new AccessDeniedException("no right");
}
示例8: decide
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
if (configAttributes == null) {
return;
}
Iterator<ConfigAttribute> iterator = configAttributes.iterator();
while (iterator.hasNext()) {
ConfigAttribute configAttribute = iterator.next();
String needPermission = configAttribute.getAttribute();
for (GrantedAuthority grantedAuthority : authentication.getAuthorities()) {
if (needPermission.equals(grantedAuthority.getAuthority())) {
return;
}
}
}
throw new AccessDeniedException("权限不足!");
}
示例9: decide
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
@Override
public void decide(Authentication authentication, Object object,
Collection<ConfigAttribute> configAttributes)
throws AccessDeniedException, InsufficientAuthenticationException {
if (configAttributes == null)
return;
// 所请求的资源拥有的权限(一个资源对多个权限)
Iterator<ConfigAttribute> iterator = configAttributes.iterator();
while (iterator.hasNext()) {
ConfigAttribute configAttribute = iterator.next();
// 访问所请求资源所需要的权限
String needPermission = configAttribute.getAttribute();
// 用户所拥有的权限authentication
for (GrantedAuthority ga : authentication.getAuthorities())
if (needPermission.equals(ga.getAuthority()))
return;
}
// 没有权限
throw new AccessDeniedException("拒绝访问。");
}
示例10: supports
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
@Override
public boolean supports( ConfigAttribute configAttribute )
{
boolean result = configAttribute.getAttribute() != null
&& configAttribute.getAttribute().startsWith( attributePrefix );
LOG.debug( "Supports configAttribute: " + configAttribute + ", " + result + " (" + getClass().getSimpleName()
+ ")" );
return result;
}
示例11: decide
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes)
throws AccessDeniedException, InsufficientAuthenticationException {
if(configAttributes == null) {
return;
}
//所请求的资源拥有的权限(一个资源对多个权限)
Iterator<ConfigAttribute> iterator = configAttributes.iterator();
while(iterator.hasNext()) {
ConfigAttribute configAttribute = iterator.next();
//访问所请求资源所需要的权限
String needPermission = configAttribute.getAttribute();
//用户所拥有的权限authentication
for(GrantedAuthority ga : authentication.getAuthorities()) {
if(needPermission.equals(ga.getAuthority())) {
LoginInfo loginUser = UserContextHolder.getUser();
Permission per = permissionManager.getById(needPermission);
loginUser.setPermission(per.getApplication().getName()+"-"+per.getName()+per.getUrl());
UserContextHolder.setUser(loginUser);
//添加日志
// Log log = new Log();
// log.setDf("0");
// log.setIp(loginUser.getIp());
// log.setPermission(per.getApplication().getName()+"-"+per.getName()+per.getUrl());
// log.setTs(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
// log.setType("APP_LOG001");
// log.setUsername(loginUser.getUserName());
// logManager.save(log);
return;
}
}
}
//没有权限
throw new AccessDeniedException(" 没有权限访问! ");
}
示例12: supports
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
public boolean supports(ConfigAttribute attribute) {
if (denyAccess.equals(attribute.getAttribute()) || (attribute.getAttribute() != null)
&& attribute.getAttribute().startsWith(scopePrefix)) {
return true;
}
else {
return false;
}
}
示例13: vote
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
@Override
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
int amount = this.defaultAmount;
if (attributes != null) {
for (ConfigAttribute attribute : attributes) {
if (attribute.getAttribute() != null && attribute.getAttribute().startsWith(PREFIX + SEPARATOR)) {
String amountAttributeValue = StringUtils.splitByWholeSeparatorPreserveAllTokens(attribute.getAttribute(), SEPARATOR)[1];
try {
// should be minimum zero
amount = Math.max(0, Integer.parseInt(amountAttributeValue));
} catch (NumberFormatException nfe) {
LOGGER.debug(String.format("%s is NaN. Defaulting to %s for amount.", amountAttributeValue, defaultAmount), nfe);
}
}
}
}
if (amount == 0) {
return ACCESS_GRANTED;
}
int result = ACCESS_DENIED;
T key = keyFactory.create(SecurityContextHolder.getContext());
try {
if (leakyBucketService.add(key, amount)) {
result = ACCESS_GRANTED;
}
} catch (IllegalArgumentException iae) {
// this should never occur since amount is minimum zero (Math.max)
LOGGER.error(String.format("Illegal amount of tokens added to bucket: %s", amount),iae);
throw iae;
}
if (result == ACCESS_DENIED) {
throw new RDAPErrorException(TOO_MANY_REQUESTS_HTTP_CODE, "Too many requests");
}
return result;
}
示例14: getAttributeValue
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
public String getAttributeValue(ConfigAttribute attribute) {
if (attribute instanceof WebExpressionConfigAttribute) {
return ((WebExpressionConfigAttribute) attribute).getAuthorizeExpression().getExpressionString();
} else {
return attribute.getAttribute();
}
}
示例15: supports
import org.springframework.security.access.ConfigAttribute; //导入方法依赖的package包/类
public boolean supports(ConfigAttribute attribute) {
return attribute.getAttribute() != null;
}