Hi Fernando,

I previously also tried to execute some JavaScript after user login 
successful and before redirected back to service, and I successfully 
created an example.

However, I didn't need to know whether it is Facebook, Google, or Email, 
unlike your requirement. I just need to execute some JS for all users.

I will give you my example, but you might want to research more on how to 
determine the Delegate Authentication client (i.e. whether is FB, Google or 

So, the following is what I changed (CAS 5.3.0) *[It is still a demo 
testing code, I am not responsible if there is any security / performance 

*1. ExampleCasWebflowContextConfiguration*

public class ExampleCasWebflowContextConfiguration{
FlowBuilderServices builder;
    FlowDefinitionRegistry loginFlowRegistry;

    FlowDefinitionRegistry logoutFlowRegistry;
    private CasConfigurationProperties casProperties;    

    private ApplicationContext applicationContext;

    public CasWebflowConfigurer defaultWebflowConfigurer() {
        final ExampleDefaultWebflowConfigurer c = new 
ExampleDefaultWebflowConfigurer (builder, loginFlowRegistry, 
applicationContext, casProperties);
        return c;

    public Action redirectToServiceAction() {
        return new ExampleRedirectToServiceAction(responseBuilderLocator);

*2. ExampleDefaultWebflowConfigurer*
public class ExampleDefaultWebflowConfigurer extends 
public ExampleDefaultWebflowConfigurer(FlowBuilderServices 
FlowDefinitionRegistry flowDefinitionRegistry, ApplicationContext 
CasConfigurationProperties casProperties) {
super(flowBuilderServices, flowDefinitionRegistry, applicationContext, 

     * Create redirect end state.
     * @param flow the flow
    protected void createRedirectEndState(final Flow flow) {
        createEndState(flow, CasWebflowConstants.STATE_ID_REDIRECT_VIEW, 
        //createEndState(flow, CasWebflowConstants.STATE_ID_REDIRECT_VIEW, 
"requestScope.url", true);

3. *ExampleRedirectToServiceAction*

public class ExampleRedirectToServiceAction extends RedirectToServiceAction 
public ExampleRedirectToServiceAction(ResponseBuilderLocator 
responseBuilderLocator) {

    protected Event finalizeResponseEvent(final RequestContext 
requestContext, final WebApplicationService service,
                                          final Response response) {
         String client = ........; //Here you need to research on how you 
can receive the client (e.g. Google Facebook)

        requestContext.getRequestScope().put("client", client);
    Event defaultFinalizeResponseEvent = 
super.finalizeResponseEvent(requestContext, service, response);
    return defaultFinalizeResponseEvent;


*4. src/main/resources/templates/casGenericRedirectView.html*


var url = /*[[${url}]]*/ null; //This is the url to return to the user 
after login success
var client = /*[[${client}]]*/ null; //This is your client

//You do your javascript execution here......

location.replace(url); // proceed to redirect user to service
// you might also want to redirect user when JavaScript is not enable, you 
will need to research more on that and put in this file as well

*5. src/main/resoruces/META-INF/spring.factories*

With this change, you will be able to execute JavaScript after user login 
success and before they are redirected to their service.

- Andy

On Friday, 10 August 2018 04:06:27 UTC+8, Fernando Gomez wrote:
> Thanks Ray, I'm interested in having javascript executed in the user's 
> browser that collects data about the service
> El jueves, 9 de agosto de 2018, 14:36:54 (UTC-3), Fernando Gomez escribió:
>> Hello, I have the following problem, in my implementation of CAS SSO, I 
>> can login for: Facebook, Google and Email, I need to do is that when the 
>> login is successful in any of the entry methods, I can run a script, i.e. 
>> If I login with Facebook and is a successful, I must then execute a script 
>> that takes statistics through Facebook, the same for google and the same 
>> with Email, my question is how can I, know when the login is successful, to 
>> do a condition that allows me to execute my script?

- 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 cas-user+unsubscr...@apereo.org.
To view this discussion on the web visit 

Reply via email to