0

When I try run this script to secure my web services on Grails / CXF client I get

"Cannot invoke method getInInterceptors() on null object" on secureServiceFactory

Does secureServiceFactory need to be set somewhere else?

Any ideas:

Code :

class BootStrap {

def secureServiceFactory

def init = { servletContext ->

    Map<String, Object> inProps = [:]
    inProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    inProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    Map<QName, Validator> validatorMap = new HashMap<QName, Validator>();
    validatorMap.put(WSSecurityEngine.USERNAME_TOKEN, new UsernameTokenValidator() {

        @Override
        protected void verifyPlaintextPassword(org.apache.ws.security.message.token.UsernameToken usernameToken, org.apache.ws.security.handler.RequestData data)
            throws org.apache.ws.security.WSSecurityException {
            if(data.username == "wsuser" && usernameToken.password == "secret") {
      println "username and password are correct!"
  } else {
      println "username and password are NOT correct..."
                throw new WSSecurityException("user and/or password mismatch")
            }
        }
    });
    inProps.put(WSS4JInInterceptor.VALIDATOR_MAP, validatorMap);
    secureServiceFactory.getInInterceptors().add(new WSS4JInInterceptor(inProps))
}
dmahapatro
  • 49,365
  • 7
  • 88
  • 117
  • 1
    You might want to include your resources.groovy or state what plugin you believe gives you injection of secureServiceFactory. – billjamesdev Aug 25 '13 at 21:30
  • I was just following this example : http://www.christianoestreich.com/2012/04/grails-cxf-interceptor-injection/ So my resources.groovy is still empty. – user2672286 Aug 26 '13 at 07:08
  • 1
    Read the article again. The cxf plugin wires up service factories that will match **the name of your exposed service such as `secureService` with bean named `secureServiceFactory`**. Do you have a service named `secureService`? – dmahapatro Aug 26 '13 at 15:00

1 Answers1

0

Not sure this is a total answer, but, I receive the same errors and I understand that the cxf plugin is meant to wire up service factories that will match the name of your exposed service. I have verified that out of the box, running the grails-cxf plugin using grails run-app the application works. however, by executing grails war on the project creates a war that when deployed to tc server [vfabric-tc-server-developer-2.9.4.RELEASE] tomcat 7 [tomcat-7.0.47.A.RELEASE], this error occurs.

It is also useful to note that out of the box, as the plugin author has noted in other references [http://www.christianoestreich.com/2012/04/grails-cxf-interceptor-injection/] the generated war won't work unless you change test('org.apache.ws.security:wss4j:1.6.7') to compile('org.apache.ws.security:wss4j:1.6.7') and I note that I was unable to make that work, I had to use compile('org.apache.ws.security:wss4j:1.6.9')

Unfortunately, after surpassing this, I run into a third error when deploying the war that doesn't occur in grails run-app:

22-Aug-2014 11:46:05.062 SEVERE [tomcat-http--1] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet CxfServlet
 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:641)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1159)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:282)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:273)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:979)
    at org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:75)

I'll continue looking at it, but perhaps this war isn't meant to really deploy, but is more meant just for development of the plugin itself. however, if that is the case, it would still be better to work in TC because then we can leverage the code in our own projects with confidence.

Brent Fisher
  • 132
  • 3
  • 12