Search in sources :

Example 76 with MethodInvocation

use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.

the class AbstractAclVoterTests method correctArgumentIsSelectedFromMultipleArgs.

@Test
public void correctArgumentIsSelectedFromMultipleArgs() throws Exception {
    voter.setProcessDomainObjectClass(String.class);
    MethodInvocation mi = MethodInvocationUtils.create(new TestClass(), "methodTakingAListAndAString", new ArrayList<Object>(), "The Argument");
    assertThat(voter.getDomainObjectInstance(mi)).isEqualTo("The Argument");
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.Test)

Example 77 with MethodInvocation

use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.

the class MethodInvocationUtilsTests method createFromClassReturnsMethodWithNoArgInfoForMethodWithNoArgs.

@Test
public void createFromClassReturnsMethodWithNoArgInfoForMethodWithNoArgs() {
    new MethodInvocationUtils();
    MethodInvocation mi = MethodInvocationUtils.createFromClass(String.class, "length");
    assertThat(mi).isNotNull();
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation)

Example 78 with MethodInvocation

use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.

the class MethodInvocationUtilsTests method createFromClassReturnsMethodIfArgInfoOmittedAndMethodNameIsUnique.

@Test
public void createFromClassReturnsMethodIfArgInfoOmittedAndMethodNameIsUnique() {
    MethodInvocation mi = MethodInvocationUtils.createFromClass(BusinessServiceImpl.class, "methodReturningAnArray");
    assertThat(mi).isNotNull();
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation)

Example 79 with MethodInvocation

use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.

the class ContextPropagatingRemoteInvocationTests method getRemoteInvocation.

private ContextPropagatingRemoteInvocation getRemoteInvocation() throws Exception {
    Class<TargetObject> clazz = TargetObject.class;
    Method method = clazz.getMethod("makeLowerCase", new Class[] { String.class });
    MethodInvocation mi = new SimpleMethodInvocation(new TargetObject(), method, "SOME_STRING");
    ContextPropagatingRemoteInvocationFactory factory = new ContextPropagatingRemoteInvocationFactory();
    return (ContextPropagatingRemoteInvocation) factory.createRemoteInvocation(mi);
}
Also used : SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Method(java.lang.reflect.Method) TargetObject(org.springframework.security.TargetObject)

Example 80 with MethodInvocation

use of org.aopalliance.intercept.MethodInvocation in project midpoint by Evolveum.

the class SecurityEnforcerImpl method decide.

/**
	 * Spring security method. It is practically applicable only for simple cases.
	 */
@Override
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
    if (object instanceof MethodInvocation) {
        MethodInvocation methodInvocation = (MethodInvocation) object;
    // TODO
    } else if (object instanceof FilterInvocation) {
        FilterInvocation filterInvocation = (FilterInvocation) object;
    // TODO
    } else {
        SecurityUtil.logSecurityDeny(object, ": Unknown type of secure object");
        throw new IllegalArgumentException("Unknown type of secure object");
    }
    Object principalObject = authentication.getPrincipal();
    if (!(principalObject instanceof MidPointPrincipal)) {
        if (authentication.getPrincipal() instanceof String && "anonymousUser".equals(principalObject)) {
            SecurityUtil.logSecurityDeny(object, ": Not logged in");
            throw new InsufficientAuthenticationException("Not logged in.");
        }
        throw new IllegalArgumentException("Expected that spring security principal will be of type " + MidPointPrincipal.class.getName() + " but it was " + principalObject.getClass());
    }
    Collection<String> configActions = SecurityUtil.getActions(configAttributes);
    for (String configAction : configActions) {
        boolean isAuthorized;
        try {
            isAuthorized = isAuthorized(configAction, null, null, null, null, null);
        } catch (SchemaException e) {
            throw new SystemException(e.getMessage(), e);
        }
        if (isAuthorized) {
            return;
        }
    }
    SecurityUtil.logSecurityDeny(object, ": Not authorized", null, configActions);
    // Better message is logged.
    throw new AccessDeniedException("Not authorized");
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) SystemException(com.evolveum.midpoint.util.exception.SystemException) MethodInvocation(org.aopalliance.intercept.MethodInvocation) FilterInvocation(org.springframework.security.web.FilterInvocation) InsufficientAuthenticationException(org.springframework.security.authentication.InsufficientAuthenticationException)

Aggregations

MethodInvocation (org.aopalliance.intercept.MethodInvocation)84 Test (org.junit.Test)59 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)22 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)15 ITestBean (org.springframework.tests.sample.beans.ITestBean)13 Method (java.lang.reflect.Method)11 Log (org.apache.commons.logging.Log)9 EvaluationContext (org.springframework.expression.EvaluationContext)9 Expression (org.springframework.expression.Expression)9 PreInvocationExpressionAttribute (org.springframework.security.access.expression.method.PreInvocationExpressionAttribute)9 Authentication (org.springframework.security.core.Authentication)9 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)9 TestBean (org.springframework.tests.sample.beans.TestBean)9 IOException (java.io.IOException)8 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)7 FileNotFoundException (java.io.FileNotFoundException)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)5 AccessibleObject (java.lang.reflect.AccessibleObject)4 ConnectException (java.rmi.ConnectException)4 RemoteException (java.rmi.RemoteException)4