Package org.aopalliance.intercept

Examples of org.aopalliance.intercept.MethodInvocation


    //~ Methods ========================================================================================================

    public final Collection<ConfigAttribute> getAttributes(Object object) {
        if (object instanceof MethodInvocation) {
            MethodInvocation mi = (MethodInvocation) object;
            Object target = mi.getThis();
            Class<?> targetClass = null;

            if (target != null) {
                targetClass = target instanceof Class<?> ? (Class<?>)target : AopProxyUtils.ultimateTargetClass(target);
            }
            Collection<ConfigAttribute> attrs = getAttributes(mi.getMethod(), targetClass);
            if(attrs != null && !attrs.isEmpty()) {
                return attrs;
            }
            if(target != null && !(target instanceof Class<?>)) {
                attrs = getAttributes(mi.getMethod(), target.getClass());
            }
            return attrs;
        }

        throw new IllegalArgumentException("Object must be a non-null MethodInvocation");
View Full Code Here


    }

    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);
    }
View Full Code Here

    private PreInvocationAuthorizationAdviceVoter am =
        new PreInvocationAuthorizationAdviceVoter(new ExpressionBasedPreInvocationAdvice());

    @Test
    public void hasRoleExpressionAllowsUserWithRole() throws Exception {
        MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray());
        assertEquals(AccessDecisionVoter.ACCESS_GRANTED, am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute(null, null, "hasRole('blah')"))));
    }
View Full Code Here

    @Test
    public void hasRoleExpressionDeniesUserWithoutRole() throws Exception {
        List<ConfigAttribute> cad = new ArrayList<ConfigAttribute>(1);
        cad.add(new PreInvocationExpressionAttribute(null, null, "hasRole('joedoesnt')"));
        MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray());
        assertEquals(AccessDecisionVoter.ACCESS_DENIED, am.vote(joe, mi, cad));
    }
View Full Code Here

        assertEquals(AccessDecisionVoter.ACCESS_DENIED, am.vote(joe, mi, cad));
    }

    @Test
    public void matchingArgAgainstAuthenticationNameIsSuccessful() throws Exception {
        MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAString(), "joe");
        assertEquals(AccessDecisionVoter.ACCESS_GRANTED,
                am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute(null, null, "(#argument == principal) and (principal == 'joe')"))));
    }
View Full Code Here

    }

    @Test
    public void accessIsGrantedIfNoPreAuthorizeAttributeIsUsed() throws Exception {
        Collection arg = createCollectionArg("joe", "bob", "sam");
        MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), arg);
        assertEquals(AccessDecisionVoter.ACCESS_GRANTED,
                am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'jim')", "collection", null))));
        // All objects should have been removed, because the expression is always false
        assertEquals(0, arg.size());
    }
View Full Code Here

    }

    @Test
    public void collectionPreFilteringIsSuccessful() throws Exception {
        List arg = createCollectionArg("joe", "bob", "sam");
        MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), arg);
        am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe' or filterObject == 'sam')", "collection", "permitAll")));
        assertEquals("joe and sam should still be in the list", 2, arg.size());
        assertEquals("joe", arg.get(0));
        assertEquals("sam", arg.get(1));
    }
View Full Code Here

        assertEquals("sam", arg.get(1));
    }

    @Test(expected=IllegalArgumentException.class)
    public void arraysCannotBePrefiltered() throws Exception {
        MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray(), createArrayArg("sam","joe"));
        am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'jim')", "someArray", null)));
    }
View Full Code Here

        am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'jim')", "someArray", null)));
    }

    @Test(expected=IllegalArgumentException.class)
    public void incorrectFilterTargetNameIsRejected() throws Exception {
        MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), createCollectionArg("joe", "bob"));
        am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe')", "collcetion", null)));
    }
View Full Code Here

        am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe')", "collcetion", null)));
    }

    @Test(expected=IllegalArgumentException.class)
    public void nullNamedFilterTargetIsRejected() throws Exception {
        MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), new Object[] {null});
        am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe')", "collection", null)));
    }
View Full Code Here

TOP

Related Classes of org.aopalliance.intercept.MethodInvocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.