Search in sources :

Example 1 with JoinPoint

use of org.aspectj.lang.JoinPoint in project cas by apereo.

the class CasCoreAuditConfiguration method nullableReturnValueResourceResolver.

@Bean
public AuditResourceResolver nullableReturnValueResourceResolver() {
    return new AuditResourceResolver() {

        @Override
        public String[] resolveFrom(final JoinPoint joinPoint, final Object o) {
            if (o == null) {
                return new String[0];
            }
            if (o instanceof Event) {
                final Event event = Event.class.cast(o);
                final String sourceName = event.getSource().getClass().getSimpleName();
                final String result = new ToStringBuilder(event, ToStringStyle.NO_CLASS_NAME_STYLE).append("event", event.getId()).append("timestamp", new Date(event.getTimestamp())).append("source", sourceName).toString();
                return new String[] { result };
            }
            return returnValueResourceResolver().resolveFrom(joinPoint, o);
        }

        @Override
        public String[] resolveFrom(final JoinPoint joinPoint, final Exception e) {
            return returnValueResourceResolver().resolveFrom(joinPoint, e);
        }
    };
}
Also used : ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) AuditResourceResolver(org.apereo.inspektr.audit.spi.AuditResourceResolver) Event(org.springframework.webflow.execution.Event) Date(java.util.Date) JoinPoint(org.aspectj.lang.JoinPoint) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with JoinPoint

use of org.aspectj.lang.JoinPoint in project cas by apereo.

the class TicketOrCredentialPrincipalResolverTests method verifyResolverTicketGrantingTicket.

@Test
public void verifyResolverTicketGrantingTicket() throws Exception {
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), c);
    final TicketGrantingTicket ticketId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final ServiceTicket st = getCentralAuthenticationService().grantServiceTicket(ticketId.getId(), CoreAuthenticationTestUtils.getService(), ctx);
    final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
    final JoinPoint jp = mock(JoinPoint.class);
    when(jp.getArgs()).thenReturn(new Object[] { ticketId.getId() });
    final String result = res.resolveFrom(jp, null);
    assertNotNull(result);
    assertEquals(result, c.getId());
}
Also used : Credential(org.apereo.cas.authentication.Credential) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.junit.Test)

Example 3 with JoinPoint

use of org.aspectj.lang.JoinPoint in project cas by apereo.

the class TicketOrCredentialPrincipalResolverTests method verifyResolverCredential.

@Test
public void verifyResolverCredential() {
    final TicketOrCredentialPrincipalResolver res = new TicketOrCredentialPrincipalResolver(getCentralAuthenticationService());
    final JoinPoint jp = mock(JoinPoint.class);
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    when(jp.getArgs()).thenReturn(new Object[] { c });
    final String result = res.resolveFrom(jp, null);
    assertNotNull(result);
    assertEquals(result, c.toString());
}
Also used : Credential(org.apereo.cas.authentication.Credential) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.junit.Test)

Example 4 with JoinPoint

use of org.aspectj.lang.JoinPoint in project cas by apereo.

the class ServiceManagementResourceResolver method findService.

/**
     * Find service.
     *
     * @param joinPoint the join point
     * @return the string[]
     */
private static String[] findService(final JoinPoint joinPoint) {
    final JoinPoint j = AopUtils.unWrapJoinPoint(joinPoint);
    final Long id = (Long) j.getArgs()[0];
    if (id == null) {
        return new String[] { StringUtils.EMPTY };
    }
    return new String[] { "id=" + id };
}
Also used : JoinPoint(org.aspectj.lang.JoinPoint)

Example 5 with JoinPoint

use of org.aspectj.lang.JoinPoint in project spring-framework by spring-projects.

the class AbstractAspectJAdvice method argBinding.

/**
	 * Take the arguments at the method execution join point and output a set of arguments
	 * to the advice method
	 * @param jp the current JoinPoint
	 * @param jpMatch the join point match that matched this execution join point
	 * @param returnValue the return value from the method execution (may be null)
	 * @param ex the exception thrown by the method execution (may be null)
	 * @return the empty array if there are no arguments
	 */
protected Object[] argBinding(JoinPoint jp, JoinPointMatch jpMatch, Object returnValue, Throwable ex) {
    calculateArgumentBindings();
    // AMC start
    Object[] adviceInvocationArgs = new Object[this.parameterTypes.length];
    int numBound = 0;
    if (this.joinPointArgumentIndex != -1) {
        adviceInvocationArgs[this.joinPointArgumentIndex] = jp;
        numBound++;
    } else if (this.joinPointStaticPartArgumentIndex != -1) {
        adviceInvocationArgs[this.joinPointStaticPartArgumentIndex] = jp.getStaticPart();
        numBound++;
    }
    if (!CollectionUtils.isEmpty(this.argumentBindings)) {
        // binding from pointcut match
        if (jpMatch != null) {
            PointcutParameter[] parameterBindings = jpMatch.getParameterBindings();
            for (PointcutParameter parameter : parameterBindings) {
                String name = parameter.getName();
                Integer index = this.argumentBindings.get(name);
                adviceInvocationArgs[index] = parameter.getBinding();
                numBound++;
            }
        }
        // binding from returning clause
        if (this.returningName != null) {
            Integer index = this.argumentBindings.get(this.returningName);
            adviceInvocationArgs[index] = returnValue;
            numBound++;
        }
        // binding from thrown exception
        if (this.throwingName != null) {
            Integer index = this.argumentBindings.get(this.throwingName);
            adviceInvocationArgs[index] = ex;
            numBound++;
        }
    }
    if (numBound != this.parameterTypes.length) {
        throw new IllegalStateException("Required to bind " + this.parameterTypes.length + " arguments, but only bound " + numBound + " (JoinPointMatch " + (jpMatch == null ? "was NOT" : "WAS") + " bound in invocation)");
    }
    return adviceInvocationArgs;
}
Also used : PointcutParameter(org.aspectj.weaver.tools.PointcutParameter) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Aggregations

JoinPoint (org.aspectj.lang.JoinPoint)59 MethodSignature (org.aspectj.lang.reflect.MethodSignature)31 Method (java.lang.reflect.Method)30 Test (org.junit.Test)29 AccessDeniedException (org.springframework.security.access.AccessDeniedException)26 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)25 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)25 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)22 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)21 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)14 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)11 Before (org.aspectj.lang.annotation.Before)5 CodeSignature (org.aspectj.lang.reflect.CodeSignature)4 Annotation (java.lang.annotation.Annotation)3 ArrayList (java.util.ArrayList)3 IView (com.yydcdut.note.views.IView)2 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2