You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Ola_S <ol...@gmail.com> on 2008/12/17 15:23:45 UTC

Change user password for cxfbc:provider

Hi. 

I have a <cxfbc:provider> set up nicely. With user and password
configuration in busCfg  XML-file. This works like a charm, but now I want
to dynamically set the user and password. 

Can I set this programatically in some way. 

/O
-- 
View this message in context: http://www.nabble.com/Change-user-password-for-cxfbc%3Aprovider-tp21054069p21054069.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Change user password for cxfbc:provider

Posted by Ola_S <ol...@gmail.com>.
Hi again. 

Sorry to be such pain. But the solution doesn´t work. 

I did:
 
public UserInterceptor() { 
        super(Phase.PRE_STREAM); 
    } 

    public void handleMessage(Message message){ 
	 
	if(message.get(Message.INVOCATION_CONTEXT)==null){ 
	    
	            Map<String, Object> context = new HashMap<String, Object>(); 
	            Map<String, Object> reqContext = new HashMap<String, Object>(); 
	            
	            reqContext.put(BindingProvider.USERNAME_PROPERTY, "user1"); 
	            reqContext.put(BindingProvider.PASSWORD_PROPERTY,"passwd1");    
	            context.put("RequestContext", reqContext); 
	            message.put(Message.INVOCATION_CONTEXT, context);
	         } 
	} 

He still posts the password set in the busCfg xml as defined in xbean. . 

If I remove the busCfg from the xbean. I get an "cannot retry due to server
authentication, in streaming mode" and he does not send any user info in the
message. 


My xbean.xml

<cxfbc:provider wsdl="classpath:service.wsdl" useJBIWrapper="false"
		locationURI="${cxf.wsdl.url}" service="we:PersonnelTransfer"
		endpoint="PersonnelTransferPort" interfaceName="we:PersonnelTransfer"
		mtomEnabled ="true" busCfg="auth.xml">
 		      
		<cxfbc:inInterceptors>
			<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
		</cxfbc:inInterceptors>
		<cxfbc:outInterceptors>
			<bean class="com.we.weik.pq.interceptor.UserInterceptor" />
			<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
		</cxfbc:outInterceptors>
		<cxfbc:inFaultInterceptors>
			<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
		</cxfbc:inFaultInterceptors>
		<cxfbc:outFaultInterceptors>
			<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
		</cxfbc:outFaultInterceptors>
	</cxfbc:provider>


//O






Freeman Fang wrote:
> 
> Hi,
> You need write an interceptor yourself, let's the interceptor name is 
> UsernameAndPasswordInterceptor, the phase should be quiet early, 
> PRE_STREAM should be fine
> And if the RequestContext doesn't exist in the message just create one 
> and set it in the message
> public class UsernameAndPasswordInterceptor extends 
> AbstractPhaseInterceptor<Message> {
> 
>     public UsernameAndPasswordInterceptor() {
>         super(Phase.PRE_STREAM);
>     }
> 
>     public void handleMessage(Message message) {              
>             //for your real code you need try to retrieve context and 
> reqContext first, if they are null, they create and set it in
>              Map<String, Object> context = new HashMap<String, Object>();
>             Map<String, Object> reqContext = new HashMap<String,
> Object>();
>             reqContext.put(BindingProvider.USERNAME_PROPERTY, 
> "yourusername");
>             reqContext.put(BindingProvider.PASSWORD_PROPERTY, 
> "yourpswd");    }
>             context.put("RequestContext", reqContext);
>             message.put(Message.INVOCATION_CONTEXT, context);
> }
> 
> And you also need add this interceptor to your cxf bc provider 
> outInterceptor configure
>                <cxfbc:outInterceptors>
>                     <bean 
> class="yourpackagename.UsernameAndPasswordInterceptor"/>
>                 </cxfbc:outInterceptors>
> 
> Freeman
> 
> Ola_S wrote:
>> Hi. 
>>
>> Thank you for the reply. But I seem to be stuck. 
>> Could you please explain further. I am quite new to CXF and Servicemix. 
>>
>> What type of interceptor should I use, and in what phase?
>> I can´t get the INVOCATION_CONTEXT when i try your solution. 
>>
>> I also tried to get a hold of the httpConduit in the message, when
>> fiddeling
>> with the SoapInterceptors, but failed miserably..
>>
>> /O
>>
>>
>>
>>
>> Freeman Fang wrote:
>>   
>>> Hi,
>>> Yeah, you can do it by  adding an interceptor for your cxf bc provider 
>>> outgoing interceptor chain
>>>
>>>
>>>       Map<String, Object> reqCtx = 
>>> org.apache.cxf.helpers.CastUtils.cast((Map<?, 
>>> ?>)message.get(Message.INVOCATION_CONTEXT));
>>>       reqCtx = org.apache.cxf.helpers.CastUtils.cast((Map<?, 
>>> ?>)reqCtx.get("RequestContext"));
>>>       reqCtx.put(BindingProvider.USERNAME_PROPERTY, "yourusername");
>>>       reqCtx.put(BindingProvider.PASSWORD_PROPERTY, "yourpswd");
>>>
>>> Freeman
>>> Ola_S wrote:
>>>     
>>>> Hi. 
>>>>
>>>> I have a <cxfbc:provider> set up nicely. With user and password
>>>> configuration in busCfg  XML-file. This works like a charm, but now I
>>>> want
>>>> to dynamically set the user and password. 
>>>>
>>>> Can I set this programatically in some way. 
>>>>
>>>> /O
>>>>   
>>>>       
>>>
>>>     
>>
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Change-user-password-for-cxfbc%3Aprovider-tp21054069p21128137.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Change user password for cxfbc:provider

Posted by Freeman Fang <fr...@gmail.com>.
Hi,
You need write an interceptor yourself, let's the interceptor name is 
UsernameAndPasswordInterceptor, the phase should be quiet early, 
PRE_STREAM should be fine
And if the RequestContext doesn't exist in the message just create one 
and set it in the message
public class UsernameAndPasswordInterceptor extends 
AbstractPhaseInterceptor<Message> {

    public UsernameAndPasswordInterceptor() {
        super(Phase.PRE_STREAM);
    }

    public void handleMessage(Message message) {              
            //for your real code you need try to retrieve context and 
reqContext first, if they are null, they create and set it in
             Map<String, Object> context = new HashMap<String, Object>();
            Map<String, Object> reqContext = new HashMap<String, Object>();
            reqContext.put(BindingProvider.USERNAME_PROPERTY, 
"yourusername");
            reqContext.put(BindingProvider.PASSWORD_PROPERTY, 
"yourpswd");    }
            context.put("RequestContext", reqContext);
            message.put(Message.INVOCATION_CONTEXT, context);
}

And you also need add this interceptor to your cxf bc provider 
outInterceptor configure
               <cxfbc:outInterceptors>
                    <bean 
class="yourpackagename.UsernameAndPasswordInterceptor"/>
                </cxfbc:outInterceptors>

Freeman

Ola_S wrote:
> Hi. 
>
> Thank you for the reply. But I seem to be stuck. 
> Could you please explain further. I am quite new to CXF and Servicemix. 
>
> What type of interceptor should I use, and in what phase?
> I can´t get the INVOCATION_CONTEXT when i try your solution. 
>
> I also tried to get a hold of the httpConduit in the message, when fiddeling
> with the SoapInterceptors, but failed miserably..
>
> /O
>
>
>
>
> Freeman Fang wrote:
>   
>> Hi,
>> Yeah, you can do it by  adding an interceptor for your cxf bc provider 
>> outgoing interceptor chain
>>
>>
>>       Map<String, Object> reqCtx = 
>> org.apache.cxf.helpers.CastUtils.cast((Map<?, 
>> ?>)message.get(Message.INVOCATION_CONTEXT));
>>       reqCtx = org.apache.cxf.helpers.CastUtils.cast((Map<?, 
>> ?>)reqCtx.get("RequestContext"));
>>       reqCtx.put(BindingProvider.USERNAME_PROPERTY, "yourusername");
>>       reqCtx.put(BindingProvider.PASSWORD_PROPERTY, "yourpswd");
>>
>> Freeman
>> Ola_S wrote:
>>     
>>> Hi. 
>>>
>>> I have a <cxfbc:provider> set up nicely. With user and password
>>> configuration in busCfg  XML-file. This works like a charm, but now I
>>> want
>>> to dynamically set the user and password. 
>>>
>>> Can I set this programatically in some way. 
>>>
>>> /O
>>>   
>>>       
>>
>>     
>
>   


Re: Change user password for cxfbc:provider

Posted by Ola_S <ol...@gmail.com>.
Hi. 

Thank you for the reply. But I seem to be stuck. 
Could you please explain further. I am quite new to CXF and Servicemix. 

What type of interceptor should I use, and in what phase?
I can´t get the INVOCATION_CONTEXT when i try your solution. 

I also tried to get a hold of the httpConduit in the message, when fiddeling
with the SoapInterceptors, but failed miserably..

/O




Freeman Fang wrote:
> 
> Hi,
> Yeah, you can do it by  adding an interceptor for your cxf bc provider 
> outgoing interceptor chain
> 
> 
>       Map<String, Object> reqCtx = 
> org.apache.cxf.helpers.CastUtils.cast((Map<?, 
> ?>)message.get(Message.INVOCATION_CONTEXT));
>       reqCtx = org.apache.cxf.helpers.CastUtils.cast((Map<?, 
> ?>)reqCtx.get("RequestContext"));
>       reqCtx.put(BindingProvider.USERNAME_PROPERTY, "yourusername");
>       reqCtx.put(BindingProvider.PASSWORD_PROPERTY, "yourpswd");
> 
> Freeman
> Ola_S wrote:
>> Hi. 
>>
>> I have a <cxfbc:provider> set up nicely. With user and password
>> configuration in busCfg  XML-file. This works like a charm, but now I
>> want
>> to dynamically set the user and password. 
>>
>> Can I set this programatically in some way. 
>>
>> /O
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Change-user-password-for-cxfbc%3Aprovider-tp21054069p21092354.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Change user password for cxfbc:provider

Posted by Freeman Fang <fr...@gmail.com>.
Hi,
Yeah, you can do it by  adding an interceptor for your cxf bc provider 
outgoing interceptor chain


      Map<String, Object> reqCtx = 
org.apache.cxf.helpers.CastUtils.cast((Map<?, 
?>)message.get(Message.INVOCATION_CONTEXT));
      reqCtx = org.apache.cxf.helpers.CastUtils.cast((Map<?, 
?>)reqCtx.get("RequestContext"));
      reqCtx.put(BindingProvider.USERNAME_PROPERTY, "yourusername");
      reqCtx.put(BindingProvider.PASSWORD_PROPERTY, "yourpswd");

Freeman
Ola_S wrote:
> Hi. 
>
> I have a <cxfbc:provider> set up nicely. With user and password
> configuration in busCfg  XML-file. This works like a charm, but now I want
> to dynamically set the user and password. 
>
> Can I set this programatically in some way. 
>
> /O
>