Hi Ami,

Following sinppet demonstrate the proper way to access an assertion in a
policy.

policy.getAlternatives() will return a iterator from which you can get a
list of assertions of an alternative.

Since your policy contains only one alternative it iterator will return only
one list. ( in othe words you can call iterator.next() only once).  That
list will contain only a single assertion which you wanted to have access.

sample code:

String targetPolicy =
            "<wsp:Policy xmlns:wsp=\"
http://schemas.xmlsoap.org/ws/2004/09/policy\"; xmlns:sp=\"
http://schemas.xmlsoap.org/ws/2005/07/securitypolicy\";>" +
                "<wsp:ExactlyOne> " +
                    "<wsp:All>" +
                        "<sp:Basic256Rsa15 />" +
                    "</wsp:All>" +
                "</wsp:ExactlyOne>" +
            "</wsp:Policy>";

        ByteArrayInputStream bais = new ByteArrayInputStream(
targetPolicy.getBytes());
        Policy policy = PolicyEngine.getPolicy(bais);

        Iterator alternatives = policy.getAlternatives();
        List assertionList = (List) alternatives.next();
        System.out.println(assertionList.get(0));

HTH

Best,
Sanka

On 8/9/07, Ami Desai <[EMAIL PROTECTED]> wrote:
>
> Respected Sir,
>
>   I have queries related to WS-Policy. I am using Apache Neethi-2.0.1 for
> implementing WS-Policy. I write my policy file in xml. Now i wnat to get
> assertion from that file. For that I am using getAssertions() method of All
> class.
>   My java code is
>
>   ---------------------------------------------------------------------------
> PolicyEngine pe1=new PolicyEngine();
>   List l1,l2;
> Object o2=new Object();
>        FileInputStream fis = new FileInputStream("C:\\neethi-
> 2.0.1-bin\\policyex12.xml");
>    l2=(pe1.getPolicy(fis)).getAssertions();
>    o2=l2.get(0);
>   System.out.println(o2);
>
>   -------------------------------------------------------------------------
>   My policy file is
>
>   -------------------------------------------------------------------------
>   <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy";
> xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
>   <wsp:ExactlyOne> <wsp:All><sp:Basic256Rsa15 /></wsp:All>
>   </wsp:ExactlyOne>
>   </wsp:Policy>
>
>   --------------------------------------------------------------------------
>   And I get output as
>   [EMAIL PROTECTED]
>
>   I think i cannot get exact assertion. I think @b09e89 is my assertion
> and beause it is contained in Object, When I ty to convert them into string
> I get garbage value. So For getting assertion into string what should I have
> to do?
>
>   Is my approach right or wrong? Is there any other mehtod available for
> doing same thing?
>
>   Please slove this queries.
>
>   Thanks
>
>   With Regards,
>   Amee Desai
>
>
>
> ---------------------------------
> 5, 50, 500, 5000 - Store unlimited mails in your inbox. Click here.




-- 
Sanka Samaranayake
WSO2 Inc.

http://www.bloglines.com/blog/sanka
http://www.wso2.org/

Reply via email to