0

I have an xml configuration of spring as below:

<bean id="processor"
    class="org.springframework.security.saml.processor.SAMLProcessorImpl">
    <constructor-arg>
        <list>
            <ref bean="redirectBinding" />
            <ref bean="postBinding" />
            <ref bean="artifactBinding" />
            <ref bean="soapBinding" />
            <ref bean="paosBinding" />
        </list>
    </constructor-arg>
</bean>

I also have another Java Configuration of Spring as below:

@ImportResource({ "classpath:security/samlMetadata.xml" })
@Configuration
public class SecConfig{

@Autowired
private SAMLProcessorImpl processor;

@Bean(name ="webSSOProfileConsumer")
public WebSSOProfileConsumer webSSOProfileConsumer(){
    WebSSOProfileConsumerImpl webSSOProfileConsumerImpl = new WebSSOProfileConsumerImpl();
    try {
        webSSOProfileConsumerImpl.setProcessor(processor);
        webSSOProfileConsumerImpl.afterPropertiesSet();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    return webSSOProfileConsumerImpl;
}

}

I get the processor bean as null, please help me if I am missing some basic thing while autowiring.

EDIT

Here is the relevant part of web.xml The only thing I am skipping is welcome-file-list

<context-param>
    <param-name>contextClass</param-name>
    <param-value>
        org.springframework.web.context.support.AnnotationConfigWebApplicationContext
    </param-value>
</context-param>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>com.config.WebConfig
    </param-value>
</context-param>
<context-param>
    <param-name>spring.profiles.active</param-name>
    <param-value>production</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>security</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>security</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>
<filter>
    <filter-name>filterChainProxy</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>filterChainProxy</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

EDIT2

@Configuration
@ImportResource({ "classpath:security/samlMetadata.xml" })
@Import({SecureConfig.class})
@Profile("production")
@ComponentScan(basePackages = "com.config")
public class WebConfig extends WebMvcConfigurationSupport {

@Bean(name = "viewResolver")
public InternalResourceViewResolver viewResolver() throws Exception {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/jsp/");
    viewResolver.setSuffix(".jsp");

    return viewResolver;
}

} 

I am sorry I didn't add this class earlier.

dharam
  • 7,882
  • 15
  • 65
  • 93
  • Your configuration looks ok. I'm assuming your `SecConfig` class is related to your web part configuration of your app. Can you post the `web.xml` as well? – Andrei Stefan Jun 15 '14 at 05:40
  • Thanks for looking in to this. I really appreciate this. I have added the web.xml – dharam Jun 15 '14 at 06:58
  • No `contextConfigLocation` for your `security` servlet definition? – Andrei Stefan Jun 15 '14 at 07:44
  • No. I thought as I am importing it using @ImportResource in my SecureConfig, I expected it to get applied automatically. Am I wrong? – dharam Jun 15 '14 at 07:47
  • I'm not seeing how you tell Spring about SecConfig. I see WebConfig in web.xml, but I see nothing about SecConfig. – Andrei Stefan Jun 15 '14 at 09:29
  • Added the code in EDIT2 – dharam Jun 15 '14 at 10:56
  • I'm assuming `SecureConfig` is just a typo in your `@Import` or the class name you posted is just a typo (`SecConfig`). Other than that, I think it should work. What kind of class is `WebSSOProfileConsumerImpl `, I see you are calling `afterPropertiesSet()`? Apart from `WebSSOProfileConsumer` what other interfaces does it implement (or classes that it extends)? And where do you check for that bean if it's null or not? – Andrei Stefan Jun 15 '14 at 12:07
  • I am not checking for any null thing. Moreover, the bean implements org.springframework.security.saml.websso.WebSSOProfileConsumer and extends org.springframework.security.saml.websso.AbstractProfileBase thats it. I tried everything except checking a null. :) – dharam Jun 15 '14 at 12:40

0 Answers0