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
email).
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
issue]*:
===================================================================================================================================
*1. ExampleCasWebflowContextConfiguration*
@Configuration("exampleCasWebflowContextConfiguration")
@EnableConfigurationProperties(CasConfigurationProperties.class)
public class ExampleCasWebflowContextConfiguration{
@Autowired
FlowBuilderServices builder;
@Autowired
FlowDefinitionRegistry loginFlowRegistry;
@Autowired
FlowDefinitionRegistry logoutFlowRegistry;
@Autowired
private CasConfigurationProperties casProperties;
@Autowired
private ApplicationContext applicationContext;
@Bean
public CasWebflowConfigurer defaultWebflowConfigurer() {
final ExampleDefaultWebflowConfigurer c = new
ExampleDefaultWebflowConfigurer (builder, loginFlowRegistry,
applicationContext, casProperties);
c.setLogoutFlowDefinitionRegistry(logoutFlowRegistry);
c.initialize();
return c;
}
@Bean
@RefreshScope
public Action redirectToServiceAction() {
return new ExampleRedirectToServiceAction(responseBuilderLocator);
}
}
===================================================================================================================================
*2. ExampleDefaultWebflowConfigurer*
public class ExampleDefaultWebflowConfigurer extends
DefaultLoginWebflowConfigurer{
public ExampleDefaultWebflowConfigurer(FlowBuilderServices
flowBuilderServices,
FlowDefinitionRegistry flowDefinitionRegistry, ApplicationContext
applicationContext,
CasConfigurationProperties casProperties) {
super(flowBuilderServices, flowDefinitionRegistry, applicationContext,
casProperties);
}
/**
* Create redirect end state.
*
* @param flow the flow
*/
@Override
protected void createRedirectEndState(final Flow flow) {
createEndState(flow, CasWebflowConstants.STATE_ID_REDIRECT_VIEW,
"casGenericRedirectView");
//createEndState(flow, CasWebflowConstants.STATE_ID_REDIRECT_VIEW,
"requestScope.url", true);
}
}
===================================================================================================================================
3. *ExampleRedirectToServiceAction*
public class ExampleRedirectToServiceAction extends RedirectToServiceAction
{
public ExampleRedirectToServiceAction(ResponseBuilderLocator
responseBuilderLocator) {
super(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*
<html>
<head>
<script>
/*<![CDATA[*/
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
</script>
</head>
===================================================================================================================================
*5. src/main/resoruces/META-INF/spring.factories*
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.example.www.ExampleCasWebflowContextConfiguration
===================================================================================================================================
With this change, you will be able to execute JavaScript after user login
success and before they are redirected to their service.
Cheers!
- 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/a/apereo.org/d/msgid/cas-user/84ad5ad2-2d8a-4979-b8ea-89465f72dfbf%40apereo.org.