How to set up deployerConfigContext.xml to add attributes to cas? - cas

I used CAS server 4.0 and cas-overlay-server-demo. the return value of my server is as following:
<cas:serviceResponse xmlns:cas="xxx">
<cas:authenticationSuccess>
<cas:user>try</cas:user>
</cas:authenticationSuccess>
</cas:serviceResponse>
I want to add <cas:attributes> to this return result. I have following code in deployerConfigContext.xml:
primaryAuthenticationHandler:
<bean id="primaryAuthenticationHandler" class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler">
<property name="users">
<map>
<entry key="test" value="1234"/>
</map>
</property>
</bean>
primaryPrincipalResolver:
<bean id="primaryPrincipalResolver"
class="org.jasig.cas.authentication.principal.PersonDirectoryPrincipalResolver" >
<property name="attributeRepository" ref="attributeRepository" />
</bean>
attributeRepository:
<bean id="attributeRepository" class="org.jasig.services.persondir.support.StubPersonAttributeDao"
p:backingMap-ref="attrRepoBackingMap" />
<util:map id="attrRepoBackingMap">
<entry key="uid" value="uid" />
<entry key="prénom" value="eduPersonAffiliation" />
<entry key="groupMembership" value="groupMembership" />
</util:map>
I think I have add the the code right. StubPersonAttributeDao will help me to add attributes: uid and prénom and groupMembership. BUT, I still do not get any attibutes. Is there anything wrong in the code?

You probably need to authorize your application in CAS service registry to release attributes. By default, nothing is allowed. See http://apereo.github.io/cas/4.0.x/integration/Attribute-Release.html

Related

Publishing JMS message on Solace Topic

I am facing issue while publishing JMS message on Solace server topic.
Actually we are successfully able to send message using jmsTemplate.send() method.
But unable to see the message count on solace client GUI.
Below is my solace configuration.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:messaging.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<!-- Solace Broker Configuration Details -->
<bean id="solaceJndiTemplate" class="org.springframework.jndi.JndiTemplate"
lazy-init="default" autowire="default">
<property name="environment">
<map>
<entry key="java.naming.provider.url" value="${solace.url}" />
<entry key="java.naming.factory.initial"
value="com.solacesystems.jndi.SolJNDIInitialContextFactory" />
<entry key="java.naming.security.principal" value="${solace.userName}" />
<entry key="java.naming.security.credentials" value="${solace.passWord}" />
</map>
</property>
</bean>
<bean id="solaceConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"
lazy-init="default" autowire="default">
<property name="jndiTemplate" ref="solaceJndiTemplate" />
<property name="jndiName" value="${solace.jndiName}" />
</bean>
<!-- <bean id="solaceCachedConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="solaceConnectionFactory" />
<property name="sessionCacheSize" value="10" />
</bean> -->
<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="solaceJndiTemplate" />
<property name="jndiName" value="${solace.topic}" />
</bean>
<!-- <bean id="topicDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="solaceJndiTemplate" />
<property name="jndiName" value="${solace.topic}" />
</bean> -->
<bean id="solaceQueueJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="solaceConnectionFactory" />
<property name="defaultDestination" ref="destination" />
<property name="deliveryPersistent" value="false" />
<property name="explicitQosEnabled" value="true" />
<property name="pubSubDomain" value="false"/>
</bean>
<bean id="solaceTopicJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="solaceConnectionFactory" />
<property name="defaultDestination" ref="destination" />
<property name="deliveryPersistent" value="false" />
<property name="explicitQosEnabled" value="true" />
<property name="pubSubDomain" value="true"/>
</bean>
<bean id="solaceQueueBroker" class="com.isc.common.messaging.SolaceUtilityHelper">
<property name="jmsTemplate" ref="solaceQueueJmsTemplate" />
</bean>
<bean id="solaceTopicBroker" class="com.isc.common.messaging.SolaceUtilityHelper">
<property name="jmsTemplate" ref="solaceTopicJmsTemplate" />
</bean>
<bean id="messageBroker" class="com.isc.common.messaging.SolaceUtilityHelper">
<property name="activeBroker" value="${active.broker}" />
</bean>
<!-- <bean id="messageConsumer" class="com.isc.common.messaging.MessageConsumer">
</bean>
<bean id="jmsContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="solaceCachedConnectionFactory" />
<property name="destination" ref="destination" />
<property name="messageListener" ref="messageConsumer" />
</bean> -->
</beans>
please can any one suggest me solution for this.
Thanks in advance.
Saurabh Mahajan
Based on your comments, it would appear that you are publishing to a topic, but there are no endpoints configured to spool the message.
You can refer to at Adding Topic Subscriptions to Queues for details on how to configure an queue to spool messages that are published to a topic.
To confirm, you can verify whether messages are listed under the "No Subscription Match Logs". In SolAdmin, you can view them by heading to "Logging & Diagnostics" and selecting the "No Subscription Match Logs". The corresponding CLI command for this is show log no-subscription-match
Also, the statistics of your application connection would also display the number of messages received and sent, with any discard reasons. This can be viewed by heading to the "Clients" tab, and selecting the "Client" view. Then, double click on your client and head to "Statistics". Alternatively, the CLI command for this is show client <your-client-name> message-vpn <your-vpn-name> stats

springBatch Itemwriter mysql to CSV with headers & inserting new line

I want to write data to CSV file & have successfully written that but now I want to insert header & break line where ever needed.
Below is the code fro my itemWriter...
<property name="resource" value="file:csv/examResult.txt" />
<property name="lineAggregator">
<!-- An Aggregator which converts an object into delimited list of strings -->
<bean
class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
<property name="delimiter" value="|" />
<property name="fieldExtractor">
<!-- Extractor which returns the value of beans property through reflection -->
<bean
class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<property name="names" value="studentName, percentage, dob" />
</bean>
</property>
</bean>
</property>
</bean>

Camel-jackson vs 2.9.0 ignore unknown properties during unmarshal

<dataFormats>
 <json id="json" library="Jackson"
unmarshalTypeName="com.foo.MyPojo" disableFeatures="FAIL_ON_UNKNOWN_PROPERTIES"/>
</dataFormats>
I want to disbleFeature Fail on unknown property of jackson but I think it is available only in camel vs2.15.0 and greater.
How can i implement following using spring dsl:
dataFormat.getObjectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,false);
I'm not sure, or may be did not understand you right. But try this thing:
<bean id="format" class="org.apache.camel.component.jackson.JacksonDataFormat"/>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="format"/>
<property name="targetMethod" value="disableFeature"/>
<property name="arguments">
<list>
<value type="com.fasterxml.jackson.databind.DeserializationFeature">FAIL_ON_UNKNOWN_PROPERTIES</value>
</list>
</property>
</bean>
With JSON:
Use JsonIgnoreProperties with attribute "value". For instance:
#JsonIgnoreProperties(ignoreUnknown = true, value={"dataIgnored"})
When BeanDeserializerBuild is instanced, use those attributes.

Duplicate record errors in Hibernate Search backed by Infinispan in an EC2 cluster

We have an application that works in an EC2 cluster (2 nodes currently for testing). For searching domain models we use Hibernate Search, and since the application runs on a cluster we use Infinispan as the Lucene Directory. To survive restarts we use a JDBC cache store on MySQL, both nodes accessing the same MySQL tables. To account for adding and removing nodes, we use the "jgroups" backend for Hibernate Search worker configuration.
Our problem is about duplicate records exceptions we receive when we try to rebuild the whole entity index. We get errors with similar stacktraces as this:
ERROR [AsyncStoreProcessor-LuceneIndexesData-0] [2016-06-21 17:01:59] org.infinispan.persistence.jdbc.stringbased.JdbcStringBasedStore - ISPN008024: Error while storing string key to database; key: '_d.fdt|0|1048576|com.model.SomeModel'
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '_d.fdt|0|1048576|com.model.SomeModel' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1399)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:857)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2460)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2377)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2361)
at com.zaxxer.hikari.proxy.PreparedStatementJavassistProxy.executeUpdate(PreparedStatementJavassistProxy.java)
at org.infinispan.persistence.jdbc.stringbased.JdbcStringBasedStore.write(JdbcStringBasedStore.java:174)
at org.infinispan.persistence.async.AsyncCacheWriter.applyModificationsSync(AsyncCacheWriter.java:158)
at org.infinispan.persistence.async.AsyncCacheWriter$AsyncStoreProcessor.retryWork(AsyncCacheWriter.java:330)
at org.infinispan.persistence.async.AsyncCacheWriter$AsyncStoreProcessor.run(AsyncCacheWriter.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
When we check the DB, there is an entry with this ID. When we try it with a single node there are no errors. So our guess is both nodes are trying to write the cache entry to DB. What may be causing this problem? AFAIK the jgroups backend should be preventing it.
We use hibernate 4.3.9.Final, hibernate-search 5.2.1.Final, infinispan 7.2.5.Final and jgroups 3.6.8.Final. Infinispan configuration is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns="urn:infinispan:config:7.2"
xmlns:jdbc="urn:infinispan:config:store:jdbc:7.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
urn:infinispan:config:7.2 http://www.infinispan.org/schemas/infinispan-config-7.2.xsd
urn:infinispan:config:store:jdbc:7.2 http://www.infinispan.org/schemas/infinispan-cachestore-jdbc-config-7.2.xsd">
<jgroups>
<stack-file name="tcp" path="default-configs/default-jgroups-tcp.xml"/>
<stack-file name="ec2" path="search/infinispan-jgroups-ec2.xml"/>
</jgroups>
<cache-container name="HibernateSearch" default-cache="default" statistics="false" shutdown-hook="DONT_REGISTER">
<transport stack="${infinispan.transport:tcp}"/>
<!-- Duplicate domains are allowed so that multiple deployments with default configuration
of Hibernate Search applications work - if possible it would be better to use JNDI to share
the CacheManager across applications -->
<jmx duplicate-domains="true"/>
<!-- *************************************** -->
<!-- Cache to store Lucene's file metadata -->
<!-- *************************************** -->
<replicated-cache name="LuceneIndexesMetadata" mode="SYNC" remote-timeout="25000">
<transaction mode="NONE"/>
<state-transfer enabled="true" timeout="480000" await-initial-transfer="true"/>
<indexing index="NONE"/>
<locking striping="false" acquire-timeout="10000" concurrency-level="500" write-skew="false"/>
<eviction max-entries="-1" strategy="NONE"/>
<expiration max-idle="-1"/>
<persistence passivation="false">
<jdbc:string-keyed-jdbc-store preload="true" fetch-state="true" read-only="false" purge="false">
<jdbc:data-source jndi-url="java:comp/env/jdbc/..."/>
<jdbc:string-keyed-table drop-on-exit="false" create-on-start="true" prefix="ISPN_STRING_TABLE">
<jdbc:id-column name="ID" type="VARCHAR(255)"/>
<jdbc:data-column name="METADATA" type="BLOB"/>
<jdbc:timestamp-column name="TIMESTAMP" type="BIGINT"/>
</jdbc:string-keyed-table>
<property name="key2StringMapper">org.infinispan.lucene.LuceneKey2StringMapper</property>
<write-behind/>
</jdbc:string-keyed-jdbc-store>
</persistence>
</replicated-cache>
<!-- **************************** -->
<!-- Cache to store Lucene data -->
<!-- **************************** -->
<distributed-cache name="LuceneIndexesData" mode="SYNC" remote-timeout="25000">
<transaction mode="NONE"/>
<state-transfer enabled="true" timeout="480000" await-initial-transfer="true"/>
<indexing index="NONE"/>
<locking striping="false" acquire-timeout="10000" concurrency-level="500" write-skew="false"/>
<eviction max-entries="-1" strategy="NONE"/>
<expiration max-idle="-1"/>
<persistence passivation="false">
<jdbc:string-keyed-jdbc-store preload="true" fetch-state="true" read-only="false" purge="false">
<jdbc:data-source jndi-url="java:comp/env/jdbc/..."/>
<jdbc:string-keyed-table drop-on-exit="false" create-on-start="true" prefix="ISPN_STRING_TABLE">
<jdbc:id-column name="ID" type="VARCHAR(255)"/>
<jdbc:data-column name="DATA" type="MEDIUMBLOB"/>
<jdbc:timestamp-column name="TIMESTAMP" type="BIGINT"/>
</jdbc:string-keyed-table>
<property name="key2StringMapper">org.infinispan.lucene.LuceneKey2StringMapper</property>
<write-behind/>
</jdbc:string-keyed-jdbc-store>
</persistence>
</distributed-cache>
<!-- ***************************** -->
<!-- Cache to store Lucene locks -->
<!-- ***************************** -->
<replicated-cache name="LuceneIndexesLocking" mode="SYNC" remote-timeout="25000">
<transaction mode="NONE"/>
<state-transfer enabled="true" timeout="480000" await-initial-transfer="true"/>
<indexing index="NONE"/>
<locking striping="false" acquire-timeout="10000" concurrency-level="500" write-skew="false"/>
<eviction max-entries="-1" strategy="NONE"/>
<expiration max-idle="-1"/>
</replicated-cache>
</cache-container>
</infinispan>
Respective Hibernate configuration is as follows (which is done via Spring):
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="..."/>
<property name="packagesToScan" value="com...."/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false"/>
<property name="showSql" value="false"/>
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="database" value="MYSQL"/>
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.default_batch_fetch_size" value="50"/>
<entry key="hibernate.multiTenancy" value="SCHEMA"/>
<entry key="hibernate.multi_tenant_connection_provider" value-ref="connectionProvider"/>
<entry key="hibernate.tenant_identifier_resolver" value-ref="tenantIdentifierResolver"/>
<entry key="hibernate.cache.use_second_level_cache" value="true"/>
<entry key="hibernate.cache.region.factory_class" value="com.hazelcast.hibernate.HazelcastCacheRegionFactory"/>
<entry key="hibernate.cache.hazelcast.use_native_client" value="true"/>
<entry key="hibernate.cache.hazelcast.native_client_address" value="127.0.0.1"/>
<entry key="hibernate.cache.hazelcast.native_client_group" value="dev"/>
<entry key="hibernate.cache.hazelcast.native_client_password" value="dev-pass"/>
<entry key="hibernate.connection.characterEncoding" value="UTF-8"/>
<entry key="hibernate.connection.useUnicode" value="true"/>
<entry key="hibernate.search.default.directory_provider" value="infinispan"/>
<entry key="hibernate.search.default.locking_cachename" value="LuceneIndexesLocking"/>
<entry key="hibernate.search.default.data_cachename" value="LuceneIndexesData"/>
<entry key="hibernate.search.default.metadata_cachename" value="LuceneIndexesMetadata"/>
<entry key="hibernate.search.default.chunk_size" value="1048576"/>
<entry key="hibernate.search.infinispan.configuration_resourcename" value="search/hibernatesearch-infinispan.xml"/>
<entry key="hibernate.search.default.worker.backend" value="jgroups"/>
<entry key="hibernate.search.services.jgroups.configurationFile" value="search/infinispan-jgroups-ec2.xml"/>
</map>
</property>
</bean>
You are correct on the purpose of the JGroups Backend and your configuration of Hibernate looks like correct.
The problem is on the configuration of the CacheStore component in Infinispan, these have a "shared" attribute, whose default is false.
<jdbc:string-keyed-jdbc-store
preload="true"
fetch-state="true"
read-only="false"
purge="false"
shared="true" <!-- FIX
As you suspected, each Infinispan node was going to re-write the same entry on "each" CacheStore instance, as it didn't guess that each of your nodes are actually connecting to the same database.
Setting the shared attribute to true should ensure that Infinispan's core will coordinate among nodes so that one (and only one) node will write the entry.

Spring WS - JMS backed endpoint - When endpoint not found

I have a Spring WS Endpoint which gets the payload from a JMS Queue. I use annotation based routing on my endpoint [based on payload root].
If for whatever reason, the routing doesn't happen [due to a typo etc], I only see a warning that there is "No Endpoint Found for Request SAAJSoapMessage". The main issue here is the message is lost! In my case, I would like an exception to be raised and fore the message to go to a Dead Letter Queue. The reliability is super critical here. What's the best way to achieve this. Here is my config:
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616?jms.redeliveryPolicy.maximumRedeliveries=5" />
</bean>
<bean id="cachingConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<constructor-arg ref="connectionFactory" />
</bean>
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
<bean
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="cachingConnectionFactory" />
<property name="destinationName" value="profiler.request.queue" />
<property name="sessionTransacted" value="true"></property>
<property name="transactionManager" ref="local.transactionManager" />
<property name="messageListener">
<bean
class="org.springframework.ws.transport.jms.WebServiceMessageListener">
<property name="messageFactory" ref="messageFactory" />
<property name="messageReceiver" ref="messageDispatcher" />
</bean>
</property>
</bean>
<bean id="local.transactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
<!-- can also refer to amq.connectionFactory -->
<property name="connectionFactory" ref="cachingConnectionFactory" />
</bean>
<bean id="myRequestQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="my.request.queue" />
</bean>
<bean id="messageDispatcher"
class="org.springframework.ws.soap.server.SoapMessageDispatcher">
<property name="endpointExceptionResolvers">
<list>
<bean class="util.EndpointExResolver"></bean>
</list>
</property>
</bean>