Hello everyone,

I am trying to customize CAS client IP address obtaining process, for 
example, try get IP
address from custom HTTP header "X-IP", if not found then try 
"X-Forwarded-For", finally
use underlying TCP/IP connection address (aka. request.getRemoteAddr()).

I extended ClientInfo class to acheive the target I talked above, next step 
is to set instance
of CustomizedClientInfo to ClientInfoHolder in the filter. I found the 
FilterRegistrationBean
of ClientInfoThreadLocalFilter in 
org.apereo.cas.audit.spi.config.CasCoreAuditConfiguration,
but there is no ConditionalOnMissingBean annotation on it, thus I cannot 
prevent it from
registering the ClientInfoThreadLocalFilter.

Now I am thinking about another way to solve the problem. I want to hijack 
the doFilter method
of ClientInfoThreadLocalFilter in AOP, like this:

@Aspect
public class ClientInfoThreadLocalFilterAspect {
    @Around("execution(* 
org.apereo.inspektr.common.web.ClientInfoThreadLocalFilter.doFilter(..))")
    public Object hijackClientInfoGeneration(ProceedingJoinPoint joinPoint) 
throws Throwable {
        final Object[] args = joinPoint.getArgs();
        Assert.isTrue(args.length == 3, "");

        final ServletRequest request = (ServletRequest) args[0];
        final ServletResponse response = (ServletResponse) args[1];
        final FilterChain filterChain = (FilterChain) args[2];

        try {
            final ClientInfo clientInfo = new 
CustomizedClientInfo((HttpServletRequest) request);
            ClientInfoHolder.setClientInfo(clientInfo);
            filterChain.doFilter(request, response);
        } finally {
            ClientInfoHolder.clear();
        }

        return null;
    }
}

And I instantiate it in my configuration class:

@EnableAspectJAutoProxy
@Configuration
public class CustomizedCasAuditConfiguration implements 
AuditTrailExecutionPlanConfigurer {
    @Bean
    public ClientInfoThreadLocalFilterAspect 
clientInfoThreadLocalFilterAspect() {
        return new ClientInfoThreadLocalFilterAspect();
    }
}

I am sure this configuration class is used by spring, because I have 
another bean in this 
class which works normally. Then Set a breakpoint in the first line of 
hijackClientInfoGeneration 
and run in debug mode, send a request, but nothing happened. I have tried 
to add  spring-boot-starter-aop 
in build.gradle but nothing different happens.

Is there any trick I forgot when using AOP in cas-overlay?

By the way, I want to submit a patch to make this filter easier to 
cusomtize, will that be accept
by the maintainer?

James

-- 
- Website: https://apereo.github.io/cas
- Gitter Chatroom: https://gitter.im/apereo/cas
- List Guidelines: https://goo.gl/1VRrw7
- Contributions: https://goo.gl/mh7qDG
--- 
You received this message because you are subscribed to the Google Groups "CAS 
Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/a/apereo.org/d/msgid/cas-user/86d589b6-2aab-49b9-b6ed-28062d8be010n%40apereo.org.

Reply via email to