Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Duplicate Filter registration for 'springSecurityFilterChain' - jboss7.x

I'm trying to implemenmt Spring security with Oauth2 for Rest API.
well I have successfully implemented this. and everything was working fine.
but then I put 'jboss-deployement-structure.xml' in WEB-INF folder
and suddenly Im getting this Exception: Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Duplicate Filter registration for 'springSecurityFilterChain'.
I have done some debugging and found out that 'onStartup()' method of 'AbstractSecurityWebApplicationInitializer' is getting executed twice (after I added 'jboss-deployement-structure.xml')
so this is attempting to add same filter twice. and hence the exception
but I dont know why this is happening and how to solve this.
please help
My web.xml:
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value> /WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
My mvc-dispatcher-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.clickawaiter" />
<bean id="customerPortalController"
class="com.clickawaiter.customerportal.controller.CustomerPortalController">
<property name="merchantServiceImpl" ref="merchantServiceImpl"></property>
</bean>
<bean id="merchantServiceImpl"
class="com.clickawaiter.customerportal.serviceimpl.MerchantServiceImpl"></bean>
<bean id="userService" class="com.clickawaiter.security.UserService">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/datasources/CAW_DS" /> <!-- value="java:CAW_DS" -->
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
My WEbAPplicationInitializer:
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer{
}

Related

How can I configure glassfish-resource.xml and web.xml for my payara web app?

I have following:
web.xml:
<web-app...>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>datasource.mceAPPDb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
</web-app>
glassfish-resource.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool name="app_emailverification"
res-type="javax.sql.DataSource"
datasource-classname="oracle.jdbc.pool.OracleDataSource"
pool-resize-quantity="2"
max-pool-size="32"
steady-pool-size="8">
<property name="URL" value="jdbc:oracle:thin:#localhost:1522:MCE0_D1"/>
<property name="user" value="app_emailverification"/>
<property name="datasourceName" value="OracleDataSource"/>
<property name="serverName" value="localhost"/>
<property name="password" value="app_emailverification"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="datasource.mceAPPDb" object-type="user" pool-name="app_emailverification">
<description>Test DataSource jdbc/testDS for Connection Pool jdbc/testConnPool</description>
</jdbc-resource>
</resources>
and persistence.xml:
<persistence-unit name="mceapp-app-database-model"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>datasource.mceAPPDb</jta-data-source>
...
</persistence-unit>
</persistence>
But when i try to deploy the war in payara server gui....i get an error :
SEVERE: java.lang.RuntimeException: Invalid resource :datasource.mceAPPDb
Whats wrong woth this setup ????

Apache Ignite configuration error

We have build a 4 node Apache Ignite Cluster and able to do connect and perform the basic operation like creating a Cache from a Java program.
But it fails to connect to the Ignite cluster when I did the MySQL integration.
Following is the error message.
Exception in thread "main" class org.apache.ignite.IgniteException: Resource field is not assignable from the resource: class org.springframework.jdbc.datasource.DriverManagerDataSource
at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:906)
at org.apache.ignite.Ignition.start(Ignition.java:350)
at PersonExample.PersonStoreExample.main(PersonStoreExample.java:16)
Caused by: class org.apache.ignite.IgniteCheckedException: Resource field is not assignable from the resource: class org.springframework.jdbc.datasource.DriverManagerDataSource
at org.apache.ignite.internal.processors.resource.GridResourceUtils.inject(GridResourceUtils.java:50)
at org.apache.ignite.internal.processors.resource.GridResourceSpringBeanInjector.inject(GridResourceSpringBeanInjector.java:67)
at org.apache.ignite.internal.processors.resource.GridResourceIoc.injectInternal(GridResourceIoc.java:172)
at org.apache.ignite.internal.processors.resource.GridResourceIoc.inject(GridResourceIoc.java:97)
at org.apache.ignite.internal.processors.resource.GridResourceProcessor.injectGeneric(GridResourceProcessor.java:257)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepare(GridCacheProcessor.java:539)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepare(GridCacheProcessor.java:528)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.createCache(GridCacheProcessor.java:1270)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.onKernalStart(GridCacheProcessor.java:784)
at org.apache.ignite.internal.IgniteKernal.start(IgniteKernal.java:926)
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start0(IgnitionEx.java:1736)
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1589)
at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:1042)
at org.apache.ignite.internal.IgnitionEx.startConfigurations(IgnitionEx.java:964)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:850)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:749)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:619)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:589)
at org.apache.ignite.Ignition.start(Ignition.java:347)
... 1 more
Following is the Ignite Config file:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--
Alter configuration below as needed.
-->
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" name="dataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://<<mysqk_host>>:3306/sample_db" />
<property name="username" value="root" />
<property name="password" value="hadoop" />
</bean>
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="personCache" />
<property name="readThrough" value="true" />
<property name="writeThrough" value="true" />
<property name="cacheStoreFactory">
<bean class="javax.cache.configuration.FactoryBuilder" factory-method="factoryOf">
<constructor-arg value="PersonExample.PersonStore" />
</bean>
</property>
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
<property name="keyType" value="java.lang.Long" />
<property name="valueType" value="PersonExample.Person" />
<property name="fields">
<map>
<entry key="id" value="java.lang.Long" />
<entry key="name" value="java.lang.String" />
<entry key="orgId" value="java.lang.Long" />
<entry key="salary" value="java.lang.Integer" />
</map>
</property>
</bean>
</list>
</property>
</bean>
</list>
</property>
<!-- <property name="peerClassLoadingEnabled" value="true"></property> -->
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder">
<property name="zkConnectionString" value=“<<zk_host>>:2181" />
</bean>
</property>
</bean>
</property>
</bean>
How to resolve this error?
Error has been resolved with the following changes:
Added the latest MySQL JDBC jar in ignite Libs directory
Ensured Cluster config file and Client config files are same (Earlier client config file contained few additional configurations in cache configuration).
Added the Person class (Which is a MySQL table POJO, that will be stored in Ignite cache).

How to Setup SSL for Camel Route using the embedded Active MQ Broker in a service mix?

I am trying to use blueprint XML for the setup
My Blueprint XML looks like this
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="file:activemq/input"/>
<to uri="file:activemq/output"/>
<setBody>
<simple>
FileMovedEvent(file: ${file:name}, timestamp: ${date:now:hh:MM:ss.SSS})
</simple>
</setBody>
<to uri="activemqs:queue:Main.Queue.Vibhav"/>
</route>
</camelContext>
<bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQSslConnectionFactory">
<property name="brokerURL" value="ssl://localhost:61616" />
<property name="keyStore" value="file:C:/Users/xxx/Desktop/apache-servicemix-4.5.3/etc/myclient.ks"/>
<property name="keyStorePassword" value="test123"/>
<property name="trustStore" value = "file:C:/Users/xxx/Desktop/apache-servicemix-4.5.3/etc/myclient.ts"/>
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="maxConnections" value="8" />
<property name="connectionFactory" ref="activemqConnectionFactory" />
</bean>
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="transacted" value="false"/>
<property name="concurrentConsumers" value="10"/>
</bean>
<bean id="activemqs" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig"/>
</bean>
</blueprint>
Note: In the broker I have already added the ssl context and the ssl connectors, also the plugin which has ssl certificate with the jaas realm.
I fixed this issue by setting the trust store password in the connection factory properties.

javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials] while authenticating via LDAP in spring security3

I am trying to authenticating user via LDAP and authorizing via Database.LDAP directory contains user with corresponding group and I want to fetch this group at the time of successful authentication and fetch ROLE with corresponding group from database after authentication.
My spring security config file is below.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<bean id="authenticationEntryPoint"
class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
<property name="loginFormUrl" value="/login.htm" />
</bean>
<bean class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler" />
<security:http security="none" pattern="/login.htm"/>
<security:http security="none" pattern="/js/**"/>
<security:http security="none" pattern="/images/**"/>
<security:http security="none" pattern="/css/**"/>
<security:http security="none" pattern="/ckeditor/**"/>
<security:http security="none" pattern="/dhtmlgrid/**"/>
<security:http security="none" pattern="/xmleditor/**"/>
<security:http auto-config="false" entry-point-ref="authenticationEntryPoint" disable-url-rewriting="true" use-expressions="true">
<security:session-management>
<security:concurrency-control error-if-maximum-exceeded="true" max-sessions="1"/>
</security:session-management>
<security:custom-filter position="FORM_LOGIN_FILTER"
ref="cdlAuthenticationProcessingFilter" />
<security:intercept-url pattern="/displayAdminPage.htm" access="hasRole('admin')" />
<security:intercept-url pattern="/**" access="isFullyAuthenticated()" />
<security:access-denied-handler ref="accessDeniedHandler" />
<security:logout logout-success-url="/login.htm" logout-url="/logout"/>
</security:http>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="customLdapAuthenticationProvider"/>
<security:authentication-provider user-service-ref="cdlUserDetailService">
</security:authentication-provider>
</security:authentication-manager>
<bean id="customLdapAuthenticationProvider" class="com.qait.cdl.authentication.customfilter.CustomLdapAuthenticationProvider">
<constructor-arg ref="ldapBindAuthenticator"/>
<constructor-arg ref="ldapAuthoritiesPopulator"/>
</bean>
<bean id="ldapBindAuthenticator"
class="org.springframework.security.ldap.authentication.BindAuthenticator">
<constructor-arg ref="ldapContextSource" />
<property name="userDnPatterns"><list><value>uid={0},cn=users</value></list></property>
</bean>
<bean id="ldapAuthoritiesPopulator" class="com.qait.cdl.authentication.customfilter.CdlUserAuthoritiesPopulator">
</bean>
<bean id="ldapContextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="ldap://172.16.1.121:389/dc=nodomain"/>
<property name="userDn" value="cn=users,dc=nodomain"/>
<property name="password" value="ldap_admin"/>
</bean>
<bean id="cdlUserDetailService" class="com.qait.cdl.authentication.service.impl.UserDetailsServiceImpl">
<property name="userDao" ref="userDao"/>
</bean>
<bean id="cdlAuthenticationProcessingFilter"
class="com.qait.cdl.authentication.customfilter.CustomAuthenticationProcessingFilter">
<property name="authenticationManager" ref="authenticationManager" />
<property name="userDao" ref="userDao"/>
</bean>
<bean id="accessDeniedHandler"
class="org.springframework.security.web.access.AccessDeniedHandlerImpl">
<property name="errorPage" value="/WEB-INF/jsp/access-denied/content.jsp"/>
</bean>
</beans>
while debugging whole application I got null value of DirContext in AbstractContextSource that is called by BindAuthenticator.
My LDAP directory structure is below:
dn: uid=user1,cn=users,dc=nodomain
uid: user1
userPassword:user1
I've been struggling with this error from past 2 days.Any help will be appreciated.If you want any extra info, than tell me.May be, my LDAP directory structure is wrong.where I am wrong, I don't know?

Spring WS Configuration Wsdl11DestinationProvider Error

The error is happening when trying to define the wsdl endpoint. The stacktrace is stating that it doesn't exist, however, I can navigate to the url. It is https, and I have the cert stored in my cacerts + root keystore?? Help??
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!--bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" /-->
<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
<bean id="abstractClient" abstract="true">
<constructor-arg ref="messageFactory" />
<property name="destinationProvider">
<bean class="org.springframework.ws.client.support.destination.Wsdl11DestinationProvider">
<property name="wsdl" value="https://ws.firstdataglobalgateway.com:443/fdggwsapi/services/order.wsdl"/>
</bean>
</property>
</bean>
<bean id="contextApplicationContextProvider" class="com.intellavia.provider.ApplicationContextProvider"></bean>
<bean id="marshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller" />
<bean id="httpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams">
<property name="authenticationPreemptive" value="true" />
<property name="connectionManagerClass" value="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager" />
</bean>
<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
<constructor-arg ref="httpClientParams" />
</bean>
<bean id="credentials" class="org.apache.commons.httpclient.UsernamePasswordCredentials">
<constructor-arg value="*********" />
<constructor-arg value="*********" />
</bean>
<bean id="messageSender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
<constructor-arg ref="httpClient"></constructor-arg>
<property name="credentials" ref="credentials" />
</bean>
<bean id="fdggwsapiorder" parent="abstractClient" class="com.api.client.order">
<property name="marshaller" ref="marshaller" />
<property name="unmarshaller" ref="marshaller" />
<property name="messageSender" ref="messageSender" />
</bean>
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.ws.client.support.destination.Wsdl11DestinationProvider#7424ce' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'wsdl' threw exception; nested exception is java.lang.IllegalArgumentException: URL [https://ws.firstdataglobalgateway.com:443/fdggwsapi/services/order.wsdl] does not exist
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:219)
... 26 more
The server I was trying to retrieve the wsdl from was expecting a key and password combination . The JVM also required that the SSL cert be stored in the cacerts file as a trusted entity. I was setting the keystore property programmatically, however this request was being processed before the switch.