axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amila Suriarachchi <amilasuriarach...@gmail.com>
Subject Re: how to skip a Phase?
Date Tue, 01 Sep 2009 04:48:56 GMT
should be ok

msgContext.setProperty(MessageContext.REMOTE_ADDR, request.getRemoteAddr());

it gets the remoteAddress of the httpServletRequest object.

thanks,
Amila.

On Tue, Sep 1, 2009 at 12:56 AM, Alexis Midon <midon@intalio.com> wrote:

> Hi Deepal and Amila,
> thank you guys for your answers. I concede that my use case might sound
> strange and out of the standard path.
> Anyway I implemented the following handler witch seems to work fine so far.
> I post it here for the records and to ask confirmation from you that the
> property MessageContext.REMOTE_ADDR is the right property to check.
>
> Thanks again for your help,
>
> Alexis
>
>
> public class NoSecurityForLocalhostHandler extends AbstractHandler {
>
>     private static final Log log =
> LogFactory.getLog(NoSecurityForLocalhostHandler.class);
>
>     List ips = new ArrayList();
>
>     public NoSecurityForLocalhostHandler() throws SocketException {
>         Enumeration<NetworkInterface> e1 =
> NetworkInterface.getNetworkInterfaces();
>         while (e1.hasMoreElements()) {
>             NetworkInterface ni = e1.nextElement();
>             Enumeration<InetAddress> e2 = ni.getInetAddresses();
>             while (e2.hasMoreElements()) {
>                 InetAddress ia = e2.nextElement();
>                 ips.add(ia.getHostAddress());
>             }
>         }
>     }
>
>     public InvocationResponse invoke(MessageContext msgContext) throws
> AxisFault {
>         log.debug("Check if Security phase should be skipped");
>         String remoteAddr = (String)
> msgContext.getProperty(MessageContext.REMOTE_ADDR);
>         if (remoteAddr == null) {
>             log.debug("No REMOTE_ADDR in message context");
>         } else {
>             log.debug("REMOTE_ADDR is " + remoteAddr);
>             if (ips.contains(remoteAddr)) {
>                 log.debug("Remote address matches a local address. The
> Security phase will be removed (if any)");
>                 for (int i = 0; i < msgContext.getExecutionChain().size();
> i++) {
>                     Phase phase = (Phase)
> msgContext.getExecutionChain().get(i);
>                     if ("Security".equalsIgnoreCase(phase.getName())) {
>                         msgContext.getExecutionChain().remove(phase);
>                         log.debug("Security phase actually removed");
>                         break;
>                     }
>                 }
>             } else {
>                 log.debug("Remote address is not local");
>             }
>         }
>         return InvocationResponse.CONTINUE;
>     }
> }
>
>
>
> On Tue, Aug 25, 2009 at 9:45 PM, Amila Suriarachchi <
> amilasuriarachchi@gmail.com> wrote:
>
>>
>>
>> On Tue, Aug 25, 2009 at 11:24 PM, Alexis Midon <midon@intalio.com> wrote:
>>
>>> Hey there,
>>>
>>> I'm trying to dynamically skip a phase. Let me explain.
>>> Let's say I have defined the following phases as InFlow: Transport,
>>> Security, Dispatch, OperationInPhase. I want to skip the Security phase in
>>> some cases, in other words I want the phase order to become [Transport,
>>> Dispatch, OperationInPhase].
>>>
>>> I've tried to insert my decision test (skip Security or not?) into the
>>> method Phase#checkPreconditions of a new Phase subclass, but it wouldn't
>>> work. Actually if an AxisFault is thrown in Phase#checkPreconditions, all
>>> the following phases are skipped. Cf. AxisEngine#invoke.
>>>
>>> My next idea was to override Phase#invoke, insert my test and eventually
>>> delegate to the super method implementation. Unfortunately, Phase#invoke is
>>> marked as final. :(
>>>
>>> Then I tried to decorate a Phase in an handler implementation, but this
>>> is a dead end as well because a Phase instance is required by
>>> AxisConfigBuilder#getPhase.
>>>
>>> At this point, I ran out of ideas. That's why my asking for your help
>>> guys. I hope you will have a solution for my use case.
>>
>>
>> What is the problem of the security phase? I think you try to solve the
>> problem in wrong way.
>> Although security phase invoked for all the messages, it does not do any
>> thing if your service has not engaged security.
>>
>> One trick would be to add a new handler to Transport Phase and increase
>> the currentHanderIndex value of the message context.
>>
>> thanks,
>> Amila.
>>
>>>
>>>
>>> Thanks in advance.
>>>
>>> Alexis
>>>
>>>
>>
>>
>> --
>> Amila Suriarachchi
>> WSO2 Inc.
>> blog: http://amilachinthaka.blogspot.com/
>>
>
>


-- 
Amila Suriarachchi
WSO2 Inc.
blog: http://amilachinthaka.blogspot.com/

Mime
View raw message