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);
}
};
}
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());
}
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());
}
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 };
}
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;
}
Aggregations