Overloading Bean Configuration does not work in 5.0.4

90 views
Skip to first unread message

robertoschwald

unread,
May 4, 2017, 11:40:23 AM5/4/17
to CAS Community
I need to overload the ServiceValidateController Bean by my own configuration bean, but it seems Spring Boot is first using my bean, then again the original one and I don't know why.

My bean is called CasOverlayedValidationConfiguration:

@Configuration("casOverlayedValidationConfiguration")
@EnableConfigurationProperties(CasConfigurationProperties.class)
@Order(value = 50000)
public class CasOverlayedValidationConfiguration {

@Autowired
private CasConfigurationProperties casProperties;

@Autowired
@Qualifier("casAttributeEncoder")
private CasAttributeEncoder casAttributeEncoder;

@Autowired
@Qualifier("cas3SuccessView")
private View cas3SuccessView;

@Autowired
@Qualifier("authenticationContextValidator")
private AuthenticationContextValidator authenticationContextValidator;

@Autowired
@Qualifier("defaultAuthenticationSystemSupport")
private AuthenticationSystemSupport authenticationSystemSupport;

@Autowired
@Qualifier("cas20WithoutProxyProtocolValidationSpecification")
private ValidationSpecification cas20WithoutProxyProtocolValidationSpecification;

@Autowired
@Qualifier("cas2ServiceFailureView")
private View cas2ServiceFailureView;

@Autowired
@Qualifier("proxy20Handler")
private ProxyHandler proxy20Handler;

@Autowired
@Qualifier("servicesManager")
private ServicesManager servicesManager;

@Autowired
@Qualifier("centralAuthenticationService")
private CentralAuthenticationService centralAuthenticationService;

@Autowired
@Qualifier("defaultArgumentExtractor")
private ArgumentExtractor argumentExtractor;

@Autowired
@Qualifier("defaultMultifactorTriggerSelectionStrategy")
private MultifactorTriggerSelectionStrategy multifactorTriggerSelectionStrategy;

@Autowired
private View cas3ServiceSuccessView;

@Autowired
private View cas3ServiceJsonView;


/*
 Use cas3ServiceSuccessView to be able to release attributes in CAS 2.0 serviceValidate
 until all CAS Clients are migrated
 */

@Bean
public ServiceValidateController serviceValidateController() {
 
final ServiceValidateController c = new ServiceValidateController();
 c
.setValidationSpecification(this.cas20WithoutProxyProtocolValidationSpecification);
 c
.setSuccessView(cas3ServiceSuccessView);
 c
.setFailureView(cas2ServiceFailureView);
 c
.setProxyHandler(proxy20Handler);
 c
.setAuthenticationSystemSupport(authenticationSystemSupport);
 c
.setServicesManager(servicesManager);
 c
.setCentralAuthenticationService(centralAuthenticationService);
 c
.setArgumentExtractor(argumentExtractor);
 c
.setMultifactorTriggerSelectionStrategy(multifactorTriggerSelectionStrategy);
 c
.setAuthenticationContextValidator(authenticationContextValidator);
 c
.setJsonView(cas3ServiceJsonView);
 c
.setAuthnContextAttribute(casProperties.getAuthn().getMfa().getAuthenticationContextAttribute());
 
return c;
}

}


The logs show this:

1. First, my bean definition overwrites the one from 

2017-05-04 15:53:22,312 INFO [org.apereo.cas.web.CasWebApplication] - <The following profiles are active: native>
2017-05-04 15:53:22,341 INFO [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] - <Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5e25a92e: startup date [Thu May 04 15:53:22 CEST 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@387c703b>
2017-05-04 15:53:23,372 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] -
<Overriding bean definition for bean 'serviceValidateController' with a different definition:
replacing
[Generic bean: class [org.apereo.cas.web.ServiceValidateController];
scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false;
factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null;
defined in URL
[jar:file:/projects/cas5/cas/build/libs/cas.war!/WEB-INF/lib/cas-server-support-validation-5.0.4.jar!/org/apereo/cas/web/ServiceValidateController.class]]

with
[Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3;
dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=casOverlayedValidationConfiguration;
factoryMethodName=serviceValidateController; initMethodName=null; destroyMethodName=(inferred);
defined in class path resource [org/apereo/cas/web/config/CasOverlayedValidationConfiguration.class]]>


This would be fine.
BUT a second later, it again overwrites my bean with the one from "CasValidationConfiguration.class", but as Classpath resource:


2017-05-04 15:53:23,380 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] -
<Overriding bean definition for bean 'serviceValidateController' with a different definition:
replacing [Root bean: class [null];
scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false;
factoryBeanName=CasOverlayedValidationConfiguration; factoryMethodName=serviceValidateController;
initMethodName=null; destroyMethodName=(inferred);
defined in
  class path resource [org/apereo/cas/web/config/CasOverlayedValidationConfiguration.class]]

with
  [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3;
  dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=casValidationConfiguration;
  factoryMethodName=serviceValidateController; initMethodName=null; destroyMethodName=(inferred); 
  defined in class path resource [org/apereo/cas/web/config/CasValidationConfiguration.class]]>


My overlay is based on the gradle overlay template. It doesn't matter if I start the application as a standalone war application using "java -jar cas.war", or in Intellij using a local Tomcat 8 Server.

Any ideas?

Thanks Robert

 

Dmitriy Kopylenko

unread,
May 4, 2017, 11:46:59 AM5/4/17
to cas-...@apereo.org
The reason is that currently serviceValidateController bean in CAS is not @ConditionalOnMissingBean

D.
--
- CAS gitter chatroom: https://gitter.im/apereo/cas
- CAS mailing list guidelines: https://apereo.github.io/cas/Mailing-Lists.html
- CAS documentation website: https://apereo.github.io/cas
- CAS project website: https://github.com/apereo/cas
---
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+u...@apereo.org.
To view this discussion on the web visit https://groups.google.com/a/apereo.org/d/msgid/cas-user/a06acd49-1dd1-4089-8d68-410e0396a6b8%40apereo.org.

Robert Oschwald

unread,
May 4, 2017, 3:17:36 PM5/4/17
to cas-...@apereo.org
:-(

This means I need to overlay the whole CasValidationConfiguration bean.


Dmitriy Kopylenko

unread,
May 4, 2017, 3:20:31 PM5/4/17
to cas-...@apereo.org
Not really. The @Conditional needs to be present in CAS’ bean. Feel free to open up an GH issue.

Robert Ledermüller

unread,
May 5, 2017, 3:39:20 AM5/5/17
to CAS Community
Hi,

If I understand you correctly you just want to provide the CAS 3.0 protocol successView during CAS 2.0 protocol?
If so you might try this configuration [1].

cas.view.cas2.success=protocol/3.0/casServiceValidationSuccess

I think I have tried this and it worked but I might mix this up with something different.

Best
-- Robert

Oschwald Robert

unread,
May 5, 2017, 2:49:31 PM5/5/17
to cas-...@apereo.org
I’ve more bean definitions than this I need to change.
Problem is generally that you can’t redefine beans without the Annotation, but it’s needed in my case, as we have several extensions to the stock CAS server.





--
- CAS gitter chatroom: https://gitter.im/apereo/cas
- CAS mailing list guidelines: https://apereo.github.io/cas/Mailing-Lists.html
- CAS documentation website: https://apereo.github.io/cas
- CAS project website: https://github.com/apereo/cas
---
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+u...@apereo.org.

Oschwald Robert

unread,
May 5, 2017, 2:49:32 PM5/5/17
to cas-...@apereo.org
This config property only sets the template name, but still the Cas20ResponseView bean is used which does not release attributes.
Therefore, I still need to redefine the serviceValidateController bean to use the Cas30ResponseView.

Robert


Am 05.05.2017 um 09:39 schrieb Robert Ledermüller <robert.le...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages