You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rampart-dev@ws.apache.org by Sanjay Vivek <Sa...@newcastle.ac.uk> on 2008/02/29 14:06:26 UTC
Error when obtaining UsernameToken information from a different class.
Hi all,
I've a policy based service that returns the UsernameToken information
of the authenticated user. However, I wish to obtain the UsenameToken
information from a separate class as shown below:
public class PolicyEchoService {
public String echo() {
AuthUser authuser = new AuthUser();
String user = authuser.getAuth();
return("The authenticated user was" + user);
}
}//end of PolicyEchoService
Where the AuthUser.java:
public class AuthUser {
public String getAuth() {
//user variable
String user=null;
MessageContext msgCtx =
MessageContext.getCurrentMessageContext();
Vector results = null;
if ((results = (Vector) msgCtx
.getProperty(WSHandlerConstants.RECV_RESULTS)) == null)
{
System.out.println("No security results!!");
throw new RuntimeException("No security results!!");
} else {
System.out.println("Number of results: " + results.size());
for (int i = 0; i < results.size(); i++) {
WSHandlerResult rResult = (WSHandlerResult)
results.get(i);
Vector wsSecEngineResults = rResult.getResults();
for (int j = 0; j < wsSecEngineResults.size(); j++) {
WSSecurityEngineResult wser =
(WSSecurityEngineResult) wsSecEngineResults.get(j);
if (wser.getAction() == WSConstants.UT
&& wser.getPrincipal() != null) {
//Extract the principal
WSUsernameTokenPrincipal principal =
(WSUsernameTokenPrincipal)wser.getPrincipal();
//Get user/pass
user = principal.getName();
}
}
}
return user;
}
}//end of getAuth
}// end of AuthUser
So basically my PolicyEchoService.aar is:
+META-INF
-services.xml
+policy
- PolicyEchoService.class
- AuthUser.class
- PWHandler.class
However, when I try to call the service with my client, I get the
following exceptions:
Exception in thread "main" org.apache.axis2.AxisFault: Message Receiver
not found for AxisOperation: echo
at
org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java
:486)
at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(Out
InAxisOperation.java:343)
at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOper
ation.java:389)
at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInA
xisOperation.java:211)
at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163
)
at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:528
)
at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:508
)
at
org.apache.rampart.altpolicy.CommandLineClient.main(CommandLineClient.ja
va:66)
What am I doing wrong? Any pointers will be very helpful. I've also
provided my client below. Cheers.
public class Client {
private static EndpointReference targetEPR =
new EndpointReference(
"http://pod.ncl.ac.uk:8083/axis2/services/AltPolicyService");
private static String confPath = "C:\\rampart\\policy";
public static void main(String[] args) throws Exception {
ConfigurationContext ctx =
ConfigurationContextFactory.
createConfigurationContextFromFileSystem(confPath,null);
ServiceClient client = new ServiceClient(ctx, null);
Options options = new Options();
options.setAction("urn:echo");
options.setTo(targetEPR);
options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
loadPolicy( confPath + "/conf/policy.xml"));
//this username is authenticated against the PWHandlerClient
class
options.setUserName("sanjay");
client.setOptions(options);
client.engageModule("addressing");
client.engageModule("rampart");
OMElement result = client.sendReceive(getPayload());
String response = result.getFirstElement().getText();
System.out.println(response);
}
private static Policy loadPolicy(String xmlPath) throws Exception {
StAXOMBuilder builder = new StAXOMBuilder(xmlPath);
return PolicyEngine.getPolicy(builder.getDocumentElement());
}
private static OMElement getPayload() {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace ns =
factory.createOMNamespace("http://policy.rampart.apache.org","ns1");
OMElement elem = factory.createOMElement("echo", ns);
return elem;
}
}
Regards
--------------
Sanjay Vivek
Web Analyst
Middleware Team
ISS
University of Newcastle Upon Tyne