Example usage for org.springframework.security.access AccessDecisionVoter ACCESS_GRANTED

List of usage examples for org.springframework.security.access AccessDecisionVoter ACCESS_GRANTED

Introduction

In this page you can find the example usage for org.springframework.security.access AccessDecisionVoter ACCESS_GRANTED.

Prototype

int ACCESS_GRANTED

To view the source code for org.springframework.security.access AccessDecisionVoter ACCESS_GRANTED.

Click Source Link

Usage

From source file:org.duracloud.account.security.vote.AccountAccessDecisionVoterTest.java

@Test
public void testScopeSelfAcct() throws DBNotFoundException {
    Role userRole = Role.ROLE_ADMIN;
    int expectedDecision = AccessDecisionVoter.ACCESS_GRANTED;
    doTestScopeSelfAcct(userRole, expectedDecision);
}

From source file:org.duracloud.account.security.vote.AccountManagerAccessDecisionVoterTest.java

@Test
public void testVoteScopeAny() throws Exception {
    Role userRole = Role.ROLE_USER;
    int expectedDecision = AccessDecisionVoter.ACCESS_GRANTED;
    doTestScopeAny(userRole, expectedDecision);
}

From source file:be.dnsbelgium.rate.spring.security.LeakyBucketVoterTest.java

@Test
public void testEmptyBucket() {
    LeakyBucketService service = mock(LeakyBucketService.class);
    when(service.add(any(LeakyBucketKey.class), eq(CONFIG_AMOUNT))).thenReturn(true);
    final LeakyBucketVoter voter = new LeakyBucketVoter(service, keyFactory, DEFAULT_AMOUNT);
    final Authentication authentication = mock(Authentication.class);
    final Object securedObject = mock(Object.class);
    assertEquals(AccessDecisionVoter.ACCESS_GRANTED,
            voter.vote(authentication, securedObject, SecurityConfig.createList(LB_CONFIG)));
    verify(service, times(1)).add(any(LeakyBucketKey.class), eq(CONFIG_AMOUNT));
}

From source file:org.duracloud.account.db.util.impl.AccountServiceSecuredImpl.java

private void throwIfAccessDenied(Object... args) {
    String methodName = getCurrentMethodName();

    Set<ConfigAttribute> configAtts = new HashSet<ConfigAttribute>();
    for (Object obj : methodMap.get(methodName)) {
        configAtts.add(new SecurityConfig((String) obj));
    }//from w ww. j  ava2s.  c o  m

    MethodInvocation invocation = new MethodInvocationImpl(this, methodName, args);
    int decision = voter.vote(authentication, invocation, configAtts);
    if (decision != AccessDecisionVoter.ACCESS_GRANTED) {
        throw new AccessDeniedException("Access denied");
    }
}

From source file:grails.plugin.springsecurity.access.vote.AuthenticatedVetoableDecisionManager.java

/**
 * Allow any {@link AuthenticatedVoter} to veto. If any voter denies,
 * throw an exception; if any grant, return <code>true</code>;
 * otherwise return <code>false</code> if all abstain.
 *///w  w  w .  jav  a  2s. co  m
@SuppressWarnings({ "rawtypes", "unchecked" })
protected boolean checkAuthenticatedVoters(final Authentication authentication, final Object object,
        final Collection<ConfigAttribute> configAttributes) {

    boolean grant = false;
    for (AccessDecisionVoter voter : getDecisionVoters()) {
        if (voter instanceof AuthenticatedVoter) {
            int result = voter.vote(authentication, object, configAttributes);
            switch (result) {
            case AccessDecisionVoter.ACCESS_GRANTED:
                grant = true;
                break;
            case AccessDecisionVoter.ACCESS_DENIED:
                deny();
                break;
            default: // abstain
                break;
            }
        }
    }
    return grant;
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.AuthenticatedVetoableDecisionManager.java

/**
 * Allow any {@link AuthenticatedVoter} to veto. If any voter denies,
 * throw an exception; if any grant, return <code>true</code>;
 * otherwise return <code>false</code> if all abstain.
 *//* w  ww .j a  va 2s  .c o  m*/
private boolean checkAuthenticatedVoters(final Authentication authentication, final Object object,
        final Collection<ConfigAttribute> configAttributes) {

    boolean grant = false;
    for (AccessDecisionVoter voter : getDecisionVoters()) {
        if (voter instanceof AuthenticatedVoter) {
            int result = voter.vote(authentication, object, configAttributes);
            switch (result) {
            case AccessDecisionVoter.ACCESS_GRANTED:
                grant = true;
                break;
            case AccessDecisionVoter.ACCESS_DENIED:
                deny();
                break;
            default: // abstain
                break;
            }
        }
    }
    return grant;
}

From source file:org.duracloud.account.security.vote.AccountManagerAccessDecisionVoterTest.java

@Test
public void testScopeSelfAcct() throws DBNotFoundException {
    Role userRole = Role.ROLE_USER;
    int expectedDecision = AccessDecisionVoter.ACCESS_GRANTED;
    doTestScopeSelfAcct(userRole, expectedDecision);
}

From source file:org.duracloud.account.security.vote.UserAccessDecisionVoterTest.java

@Test
public void testScopeSelfAcctPeer() throws DBNotFoundException {
    Role otherUserRole = Role.ROLE_USER;
    int expectedDecision = AccessDecisionVoter.ACCESS_GRANTED;
    doTestScopeSelfAcctPeer(otherUserRole, expectedDecision);
}

From source file:grails.plugin.springsecurity.access.vote.AuthenticatedVetoableDecisionManager.java

/**
 * Check the other (non-{@link AuthenticatedVoter}) voters. If any voter grants,
 * return true. If any voter denies, throw exception. Otherwise return <code>false</code>
 * to indicate that all abstained.//  www.j  a  v  a2 s. c  o m
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected boolean checkOtherVoters(Authentication authentication, Object object,
        Collection<ConfigAttribute> configAttributes) {
    int denyCount = 0;
    for (AccessDecisionVoter voter : getDecisionVoters()) {
        if (voter instanceof AuthenticatedVoter) {
            continue;
        }

        int result = voter.vote(authentication, object, configAttributes);
        switch (result) {
        case AccessDecisionVoter.ACCESS_GRANTED:
            return true;
        case AccessDecisionVoter.ACCESS_DENIED:
            denyCount++;
            break;
        default: // abstain
            break;
        }
    }

    if (denyCount > 0) {
        deny();
    }

    // all abstain
    return false;
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.AuthenticatedVetoableDecisionManager.java

/**
 * Check the other (non-{@link AuthenticatedVoter}) voters. If any voter grants,
 * return true. If any voter denies, throw exception. Otherwise return <code>false</code>
 * to indicate that all abstained./*from  www  . j a  v  a2s. c  o m*/
 */
private boolean checkOtherVoters(Authentication authentication, Object object,
        Collection<ConfigAttribute> configAttributes) {
    int denyCount = 0;
    for (AccessDecisionVoter voter : getDecisionVoters()) {
        if (voter instanceof AuthenticatedVoter) {
            continue;
        }

        int result = voter.vote(authentication, object, configAttributes);
        switch (result) {
        case AccessDecisionVoter.ACCESS_GRANTED:
            return true;
        case AccessDecisionVoter.ACCESS_DENIED:
            denyCount++;
            break;
        default: // abstain
            break;
        }
    }

    if (denyCount > 0) {
        deny();
    }

    // all abstain
    return false;
}