0
votes

I am configuring a Mule application (running on API Gateway 2.1), and running into some issues when configuring spring security.

Here is the security config:

<spring:beans>
    <ss:authentication-manager alias="authenticationManager">
        <ss:authentication-provider >
            <ss:user-service id="userService" properties="classpath:users.properties">
            <!-- **** This works, but the properties file above ^ doesn't ****
                <ss:user name="user" password="password" authorities="ROLE_ADMIN"/> 
                <ss:user name="anon" password="anon" authorities="ROLE_ANON" /> 
            -->
            </ss:user-service>
        </ss:authentication-provider>
    </ss:authentication-manager>
</spring:beans>

<mule-ss:security-manager name="security-manager"
    doc:name="Spring Security Provider">
    <mule-ss:delegate-security-provider
        name="memory-provider" delegate-ref="authenticationManager" />
</mule-ss:security-manager>

users.properties is on my classpath and contains the following:

user=userpassword,ROLE_USER,enabled
admin=admin,ROLE_USER,ROLE_ADMIN,enabled
chris=chrispassword,ROLE_USER,enabled  

What I find confusing is that when I use the embedded users (see commented section in Mule flow above), and remove the properties=classpath:users.properties, everything runs fine. But when I try to use users.properties, I get the exception below. I know that users.properties is being found on the classpath. Have I misconfigured users.properties? If this is a more general configuration problem why doesn't it always fail?

I'm getting the following exception (top part of the stack trace):

org.mule.module.launcher.DeploymentInitException: NullPointerException: at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:197) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.artifact.ArtifactWrapper$2.execute(ArtifactWrapper.java:62) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.artifact.ArtifactWrapper.executeWithinArtifactClassLoader(ArtifactWrapper.java:129) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.artifact.ArtifactWrapper.init(ArtifactWrapper.java:57) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:25) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.DefaultArchiveDeployer.guardedDeploy(DefaultArchiveDeployer.java:310) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.DefaultArchiveDeployer.deployArtifact(DefaultArchiveDeployer.java:330) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:155) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:256) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:78) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.DeploymentDirectoryWatcher.deployPackedApps(DeploymentDirectoryWatcher.java:275) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.DeploymentDirectoryWatcher.start(DeploymentDirectoryWatcher.java:150) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.MuleDeploymentService.start(MuleDeploymentService.java:100) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.module.launcher.MuleContainer.start(MuleContainer.java:170) ~[mule-module-launcher-3.7.2.jar:3.7.2] at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:21) ~[tooling-support-1.0.0.jar:?] Caused by: org.mule.api.config.ConfigurationException: Error creating bean with name '_muleSecurityManager': Cannot create inner bean '(inner bean)#157a5cdc' of type [org.mule.module.spring.security.S pringProviderAdapter] while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#157 a5cdc': Cannot resolve reference to bean 'authenticationManager' while setting bean property 'delegate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bea n with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting construct or argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationP rovider#0': Cannot resolve reference to bean 'userService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security. provisioning.InMemoryUserDetailsManager]: Constructor threw exception; nested exception is java.lang.NullPointerException (org.mule.api.lifecycle.InitialisationException) (org.mule.api.config.Configur ationException) at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:49) ~[mule-core-3.7.2.jar:3.7.2] at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.7.2.jar:3.7.2] at org.mule.context.DefaultMuleContextFactory$1.configure(DefaultMuleContextFactory.java:89) ~[mule-core-3.7.2.jar:3.7.2] at org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:222) ~[mule-core-3.7.2.jar:3.7.2] at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:81) ~[mule-core-3.7.2.jar:3.7.2] at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:188) ~[mule-module-launcher-3.7.2.jar:3.7.2] ... 14 more Caused by: org.mule.api.config.ConfigurationException: Error creating bean with name '_muleSecurityManager': Cannot create inner bean '(inner bean)#157a5cdc' of type [org.mule.module.spring.security.S pringProviderAdapter] while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#157 a5cdc': Cannot resolve reference to bean 'authenticationManager' while setting bean property 'delegate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bea n with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting construct or argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationP rovider#0': Cannot resolve reference to bean 'userService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security. provisioning.InMemoryUserDetailsManager]: Constructor threw exception; nested exception is java.lang.NullPointerException (org.mule.api.lifecycle.InitialisationException)

1

1 Answers

1
votes

I tried this and found that if you call the properties file anything else, say myusers.properties then it works. It looks like there's some other users.properties on the class path added by one of the mule dependencies that has an incorrect format for SS and therefore throws the horrible error. So just rename the file to something else.