Hi, I am trying to implement custom cas logout. I have implemented custom cas login which works perfectly fine.
I have created a a class which implements LogoutManager and another one which implements LogoutHandler. I created a third class to register my custom logout handler which implements LogoutExecutionPlanConfigurer In this configuration class I have following code which is causing problem. @Bean SingleLogoutServiceLogoutUrlBuilder singleLogoutServiceLogoutUrlBuilder(){ return new DefaultSingleLogoutServiceLogoutUrlBuilder(urlValidator()); } @Bean UrlValidator urlValidator() { return new UrlValidator(){ @Override public boolean isValid(String s) { return org.apache.commons.validator.routines.UrlValidator.getInstance().isValid(s); } @Override public boolean isValidDomain(String s) { return DomainValidator.getInstance().isValid(s); } }; } I am getting below error 2018-05-23 14:59:06,489 WARN [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] - <Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'casReportsConfiguration': Unsatisfied dependency expressed through field 'cas3ServiceSuccessView'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'casValidationConfiguration': Unsatisfied dependency expressed through field 'centralAuthenticationService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'casCoreConfiguration': Unsatisfied dependency expressed through field 'logoutManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logoutManager' defined in class path resource [com/openbet/cas/logout/config/OpenbetLogoutManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.openbet.cas.logout.OBLogoutManagerImpl]: Factory method 'logoutManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'realLogoutManager' defined in class path resource [com/openbet/cas/logout/config/OpenbetLogoutManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.logout.LogoutManager]: Factory method 'realLogoutManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'singleLogoutServiceMessageHandler' defined in class path resource [com/openbet/cas/logout/config/OpenbetLogoutManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.logout.SingleLogoutServiceMessageHandler]: Factory method 'singleLogoutServiceMessageHandler' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'singleLogoutServiceLogoutUrlBuilder' defined in class path resource [com/openbet/cas/logout/config/OpenbetLogoutManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.logout.SingleLogoutServiceLogoutUrlBuilder]: Factory method 'singleLogoutServiceLogoutUrlBuilder' threw exception; nested exception is java.lang.ClassCastException: org.apereo.cas.web.SimpleUrlValidatorFactoryBean$$EnhancerBySpringCGLIB$$ba7be36f cannot be cast to org.apereo.cas.web.UrlValidator> May 23, 2018 2:59:06 PM org.apache.catalina.core.ContainerBase addChildInternal SEVERE: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/cas]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1140) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1874) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748) Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'casReportsConfiguration': Unsatisfied dependency expressed through field 'cas3ServiceSuccessView'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'casValidationConfiguration': Unsatisfied dependency expressed through field 'centralAuthenticationService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'casCoreConfiguration': Unsatisfied dependency expressed through field 'logoutManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logoutManager' defined in class path resource [com/openbet/cas/logout/config/OpenbetLogoutManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.openbet.cas.logout.OBLogoutManagerImpl]: Factory method 'logoutManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'realLogoutManager' defined in class path resource [com/openbet/cas/logout/config/OpenbetLogoutManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.logout.LogoutManager]: Factory method 'realLogoutManager' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'singleLogoutServiceMessageHandler' defined in class path resource [com/openbet/cas/logout/config/OpenbetLogoutManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.logout.SingleLogoutServiceMessageHandler]: Factory method 'singleLogoutServiceMessageHandler' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'singleLogoutServiceLogoutUrlBuilder' defined in class path resource [com/openbet/cas/logout/config/OpenbetLogoutManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.logout.SingleLogoutServiceLogoutUrlBuilder]: Factory method 'singleLogoutServiceLogoutUrlBuilder' threw exception; nested exception is java.lang.ClassCastException: org.apereo.cas.web.SimpleUrlValidatorFactoryBean$$EnhancerBySpringCGLIB$$ba7be36f cannot be cast to org.apereo.cas.web.UrlValidator at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1177) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1071) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154) at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134) at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87) at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5229) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 10 more The problem is I am not referring to the SimpleUrlValidatorFactoryBean method at all. I am not sure how to fix this cast exception. I have attached the relevant code in files. Any help would be appresiated. If there is other way to achive this pelase let me know. -- - 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 https://groups.google.com/a/apereo.org/d/msgid/cas-user/7d306068-3057-4749-be76-356379a72b5b%40apereo.org.
package com.openbet.cas.logout.config; import com.openbet.cas.logout.CustomLogoutHandler; import com.openbet.cas.logout.CustomLogoutManagerImpl; import org.apache.commons.validator.routines.DomainValidator; import org.apereo.cas.authentication.AuthenticationServiceSelectionPlan; import org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan; import org.apereo.cas.configuration.CasConfigurationProperties; import org.apereo.cas.logout.*; import org.apereo.cas.services.ServicesManager; import org.apereo.cas.util.http.HttpClient; import org.apereo.cas.util.http.SimpleHttpClientFactoryBean; import org.apereo.cas.web.UrlValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration("CustomLogoutManagerConfiguration") @EnableConfigurationProperties(CasConfigurationProperties.class) public class CustomLogoutManagerConfiguration implements LogoutExecutionPlanConfigurer { private static final Logger LOGGER = LoggerFactory.getLogger(CustomLogoutManagerConfiguration.class); @Override public void configureLogoutExecutionPlan(LogoutExecutionPlan plan) { plan.registerLogoutHandler(CustomLogoutHandler()); } @Bean public LogoutHandler CustomLogoutHandler() { CustomLogoutHandler handler = null; handler = new CustomLogoutHandler(logoutManager()); LOGGER.info("Openbet custom logout configuration"); return handler; } @Bean CustomLogoutManagerImpl logoutManager(){ return new CustomLogoutManagerImpl(realLogoutManager()); } @Bean LogoutManager realLogoutManager(){ return new DefaultLogoutManager(logoutMessageCreator(), singleLogoutServiceMessageHandler(),false, logoutExecutionPlan()); } @Bean LogoutMessageCreator logoutMessageCreator() { return new LogoutMessageCreator() { @Override public String create(LogoutRequest logoutRequest) { return "Logout Successful"; } }; } @Bean SingleLogoutServiceMessageHandler singleLogoutServiceMessageHandler() { return new DefaultSingleLogoutServiceMessageHandler(httpClient(), logoutMessageCreator(), servicesManager, singleLogoutServiceLogoutUrlBuilder(),true, authenticationServiceSelectionPlan()); } @Bean LogoutExecutionPlan logoutExecutionPlan(){ return new DefaultLogoutExecutionPlan(); } @Bean HttpClient httpClient(){ return new SimpleHttpClientFactoryBean().getObject(); } @Autowired @Qualifier("servicesManager") private ServicesManager servicesManager; @Bean SingleLogoutServiceLogoutUrlBuilder singleLogoutServiceLogoutUrlBuilder(){ return new DefaultSingleLogoutServiceLogoutUrlBuilder(urlValidator()); } @Bean UrlValidator urlValidator() { return new UrlValidator(){ @Override public boolean isValid(String s) { return org.apache.commons.validator.routines.UrlValidator.getInstance().isValid(s); } @Override public boolean isValidDomain(String s) { return DomainValidator.getInstance().isValid(s); } }; // new SimpleUrlValidator(org.apache.commons.validator.routines.UrlValidator.getInstance(), DomainValidator.getInstance()); // return new SimpleUrlValidator.getInstance(); } @Bean AuthenticationServiceSelectionPlan authenticationServiceSelectionPlan(){ return new DefaultAuthenticationServiceSelectionPlan(); } }
package com.openbet.cas.logout; import org.apereo.cas.logout.LogoutHandler; import org.apereo.cas.ticket.TicketGrantingTicket; public class CustomLogoutHandler implements LogoutHandler { final private CustomLogoutManagerImpl theRealLogoutManager; public CustomLogoutHandler(CustomLogoutManagerImpl logoutManager) { this.theRealLogoutManager = logoutManager; } @Override public int getOrder(){ return 1; } @Override public void handle(TicketGrantingTicket ticketGrantingTicket) { theRealLogoutManager.performLogout(ticketGrantingTicket); } }
package com.openbet.cas.logout; import org.apereo.cas.authentication.principal.Principal; import org.apereo.cas.logout.LogoutManager; import org.apereo.cas.logout.LogoutRequest; import org.apereo.cas.ticket.TicketGrantingTicket; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; public class CustomLogoutManagerImpl implements LogoutManager { /** The logger. */ private static final Logger LOGGER = LoggerFactory.getLogger(CustomLogoutManagerImpl.class); /** the Real Thing (TM) */ final private LogoutManager theRealLogoutManager; public CustomLogoutManagerImpl(LogoutManager theRealLogoutManager) { this.theRealLogoutManager = theRealLogoutManager; } @Override public List<LogoutRequest> performLogout(TicketGrantingTicket ticket) { Principal p = ticket.getAuthentication().getPrincipal(); //Do my own stuff here //Mark the user as logged out from the database. return theRealLogoutManager.performLogout(ticket); } @Override public String createFrontChannelLogoutMessage(LogoutRequest logoutRequest) { LOGGER.info("### createFrontChannelLogoutMessage"); // TODO Auto-generated method stub return theRealLogoutManager.createFrontChannelLogoutMessage(logoutRequest); } }