use of com.sun.identity.policy.client.PolicyEvaluatorFactory in project OpenAM by OpenRock.
the class PolicyClientServlet method doGet.
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Get query parameters
String orgname = request.getParameter("orgname");
if ((orgname == null) || (orgname.length() == 0)) {
orgname = "/";
}
String username = request.getParameter("username");
String password = request.getParameter("password");
String servicename = request.getParameter("servicename");
String resource = request.getParameter("resource");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(SampleConstants.HTML_HEADER);
if ((username == null) || (password == null) || (servicename == null) || (resource == null)) {
out.println(displayXML("Usage: " + request.getRequestURL() + "?username=<username>&password=<password>&orgname=<orgname>" + "&servicename=<servicename>&resource=<resource>"));
out.println("</body></html>");
return;
}
try {
PolicyEvaluatorFactory pef = PolicyEvaluatorFactory.getInstance();
PolicyEvaluator pe = pef.getPolicyEvaluator(servicename);
AuthContext lc = authenticate(orgname, username, password, out);
if (lc != null) {
SSOToken token = lc.getSSOToken();
Set actions = new HashSet();
actions.add("GET");
actions.add("POST");
Map env = new HashMap();
Set attrSet = new HashSet();
attrSet.add("mail");
env.put("Get_Response_Attributes", attrSet);
out.println("<h5>USERID: " + username + "<br>");
out.println("ORG: " + orgname + "<br>");
out.println("SERVICE NAME: " + servicename + "<br>");
out.println("RESOURCE: " + resource + "<br>");
out.println("</h5><br>");
out.println("----------getPolicyDecision() Test-----------");
out.println("<br>");
PolicyDecision pd = pe.getPolicyDecision(token, resource, actions, env);
out.println(displayXML(pd.toXML()));
out.println("End of Test.<br>");
}
} catch (Exception e) {
e.printStackTrace(out);
}
out.println("</body></html>");
}
Aggregations