本文整理匯總了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;
}