Advanced WSSecurityAction with two signature - java

I need to provide a timeStamp and two signature action with different features,
when we put two signature it understand only first
how we could handle it in cxf?

we should provide custom action
http://cxf.apache.org/docs/ws-security.html
<constructor-arg>
<map>
<entry key="action" value="Timestamp Signature 12345"/>
<entry key="wss4j.action.map">
<map key-type="java.lang.Integer" value-type="java.lang.Object">
<entry key="12345" value-ref="customSignature"/>
</map>
</entry>
and we should create a class
CustomSignatureAction extends SignatureAction {
and override features which different with fist signature

Related

How do you know the actually value for a property set by a map of beans on java?

Ive found this configuration on a applicationContext xml and I still dont understand it (even if I found info about it, is not clear) could someone give me an idea of how java chooses the right bean for its property? I did not find this bean in other file of the project context, seems like is "magic"
<bean id="mailCreator" class="com.project.ConfigurableXferEmailCreator">
<property name="mailCreatorMap">
<util:map id="mailCreatorMap" key-type="java.lang.String"
value-type="com.project.BaseMailCreator">
<entry>
<key>
<util:constant static-field="com.project.creatorType.TYPE1"/>
</key>
<bean class="com.project.creator1" parent="baseCreator">
<property name="service" ref="someService1" />
</bean>
</entry>
<entry>
<key>
<util:constant static-field="com.project.creatorType.TYPE2"/>
</key>
<bean class="com.project.creator1" parent="baseCreator">
<property name="service" ref="someService2" />
</bean>
</entry>
.... and so on
I really have no idea how java recognizes which one will use, I just know it uses the right service but I dont see where is being specifically set, could someone give me a hand?
I checked couple of sites like this but still no idea , does it call all services??
http://www.java2s.com/Tutorials/Java/Spring/0140__Spring_Map_Properties.htm
Your question:
"how java chooses the right bean for its property"
I assume you mean for example this line:
<property name="service" ref="someService1" />
if you do not see another XML bean element that defines "someService1"
fr example:
<bean id="someService1" class="com.project.SomeService1Impl">
Then it exists in the Java Code
try to find an annotation like below
#Service("someService1")
public class SomeService1Impl {
...
How?:
Spring loads "someService1" in the Spring Context on initialization , so the XML can reference it.

Display contents of XML (property mapping) in a JSP page

I have a Property Mapping (colorMap.xml):
<bean id="B_colorMapping" class="com.project.color.colorMap">
<property name="map">
<map>
<entry key="1" value="blue" />
<entry key="2" value="blue-green" />
<entry key-ref="10" value-ref="B_colorMapping" />
</map>
</property>
</bean>
<bean id="R_colorMapping" class="com.project.color.colorMap">
<property name="map">
<map>
<entry key="1" value="red" />
<entry key="2" value="red-yellow" />
<entry key-ref="10" value-ref="R_colorMapping" />
</map>
</property>
</bean>
And the com.project.color.colorMap codes look like this:
public class colorMap {
private Map<Object, Object> map;
public Map<Object, Object> getMap() {
return map;
}
public void setMap(Map<Object, Object> Cmap) {
map = Cmap;
}
}
Right now, what is happening, I manually update the colorMap.xml by adding entries and values. What I'm planning to do is to create a JSP page to handle the adding of the values in my xml.
for now, I want to display the values of my xml on the JSP page.
For example: (on the JSP page...)
B_colorMapping:
Color Key: 1 Value: blue
Color Key: 2 Value: blue-green
R_colorMapping:
Color Key:1 Value: red
Color Key:2 Value: red-yellow
Can someone offer a help or tip on how to do this? THis is spring MVC (Object, Map, ModelAndView).
I'm stuck on this one.

Server inbound redirection can't find a next Restlet

I'm trying to add a simple redirect into a web application built in Restlets, and it's proving non-trivial. The task is a simple one: I want to actually redirect all missing files from a web application to the same static file.
I'm using org.restlet.routing.Redirector with the following values (I'm using Spring injection):
<bean name="router" class="org.restlet.ext.spring.SpringRouter">
<constructor-arg ref="trackerComponentChildContext" />
<property name="attachments">
<map>
<entry key="/api" value-ref="apiRouter" />
<entry key="/statics" value-ref="staticsDirectory" />
<entry key="/" value-ref="staticsRedirector" />
</map>
</property>
</bean>
<bean id="staticsRedirector" class="ca.uhnresearch.pughlab.tracker.restlets.CustomRedirector">
<constructor-arg ref="trackerComponentChildContext" />
<constructor-arg value="{o}/statics/index.html" />
<constructor-arg value="7" />
</bean>
I can play with the file hierarchy relatively simply, but I just want to send anything that doesn't match either /api or /statics to /statics/index.html within the same application.
Restlet is almost getting it, and it does seem now to pick up the reference to the correct file, it just doesn't quite serve it.
I've put a working copy of the whole thing (including Thierry's suggestions below) at: https://github.com/morungos/restlet-spring-static-files. What I'd like to happen is something like the equivalent sequential attempts below:
curl http://localhost:8080/statics/**/* to hit the corresponding /statics/**/*
curl http://localhost:8080 to hit the main /statics/index.html
curl http://localhost:8080/**/* to hit the main /statics/index.html
I made some tests regarding your issue and I can't figure out how to have your message :-(. Perhaps it's because I haven't the whole code.
In fact, I saw a problem at the level of the SpringRouter itself. I would like to attach the redirector with an attachDefault and not an attach("/", ...) / attach("", ...). The method setDefaultAttachment actually does an attach("", ...).
So I made work something with the following updates:
Create a custom SpringRouter
public class CustomSpringRouter extends SpringRouter {
public void setDefaultAttachment(Object route) {
if (route instanceof Redirector) {
this.attachDefault((Restlet) route);
} else {
super.setDefaultAttachment(route);
}
}
}
Create a custom Redirector. I got the context from the component instead of a child context.
public class CustomRedirector extends Redirector {
public CustomRedirector(Component component, String targetPattern, int mode) {
super(component.getContext(), targetPattern, mode);
}
}
I then use the following Spring 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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="myComponent" class="org.restlet.ext.spring.SpringComponent">
<property name="defaultTarget" ref="router" />
</bean>
<bean name="router" class="test.CustomSpringRouter">
<property name="attachments">
<map>
<entry key="/api" value-ref="apiRouter" />
<entry key="/statics" value-ref="staticsDirectory" />
</map>
</property>
<property name="defaultAttachment" ref="staticsRedirector" />
</bean>
<bean id="staticsRedirector" class="test.CustomRedirector">
<constructor-arg ref="myComponent" />
<constructor-arg value="{o}/statics/index.html" />
<constructor-arg value="7" />
</bean>
<bean name="apiRouter" class="org.restlet.ext.spring.SpringRouter">
(...)
</bean>
(...)
</beans>
Hope it helps you,
Thierry

How to merge multiple maps into one in Spring

I have several maps defined in my context file. Is there a way to combine those maps into one map that contains all of their entries, without writing Java code (and without using nested maps)? I'm looking for the equivalent of Map m = new HashMap(); m.putAll(carMap); m.putAll(bikeMap);
Seems like there should be a way to do this in Spring context file, but the Spring 3.0 reference doc section on util:map doesn't cover this use case.
<!-- I want to create a map with id "vehicles" that contains all entries of the other maps -->
<util:map id="cars">
<entry key="groceryGetter" value-ref="impreza"/>
</util:map>
<util:map id="bicycles">
<entry key="commuterBike" value-ref="schwinn"/>
</util:map>
Using collection merging concept in Spring, multiple beans like these can be merged incrementally. I used this in my project to merge lists , but can be extended to merge maps as well.
E.g.
<bean id="commonMap"
class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map>
<entry key="1" value="one"/>
<entry key="2" value="two"/>
</map>
</property>
</bean>
<bean id="firstMap"
parent="commonMap"
class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map merge="true">
<entry key="3" value="three"/>
<entry key="4" value="four"/>
</map>
</property>
</bean>
The association of the second map definition with the first one is done through the parent attribute on the <bean> node and the entries in the first map are merged with those in the second using the merge attribute on the <map> node.
I bet there is no direct support for this feature in Spring.
However, writing a factory bean to use in Spring is not that difficult (haven't tried to compile that)
public class MapMerger <K,V> implements FactoryBean {
private Map<K,V> result = new HashMap<K,V>();
#Override
public Object getObject() {
return result;
}
#Override
public boolean isSingleton(){
return true;
}
#Override
public Class getObjectType(){
return Map.class;
}
public void setSourceMaps(List<Map<K,V>> maps) {
for (Map<K,V> m : maps) {
this.result.putAll(m);
}
}
}
In spring config, just do something like:
<bean id="yourResultMap" class="foo.MapMerger">
<property name="sourceMaps">
<util:list>
<ref bean="carMap" />
<ref bean="bikeMap" />
<ref bean="motorBikeMap" />
</util:list>
</property>
</bean>

Castor custom collection field handler

I'd like to unmarshal the following xml to a MultiKeyMap:
<map>
<entry key1="foo" key2="foo">
<value property="val"/>
</entry>
<entry key1="bar" key2="bar">
<value property="val"/>
</entry>
</map>
I took a look through the Castor API and saw that there's a CollectionFieldHandler class, but I can't find any documentation on where I would need to register a custom collection handler.
First of all, collection isn't a map.
You can implement and register your own handler.
See http://www.castor.org/xml-fieldhandlers.html

Categories

Resources