Search in sources :

Example 1 with PolicyEvaluatorFactory

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>");
}
Also used : PolicyDecision(com.sun.identity.policy.PolicyDecision) SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) HashSet(java.util.HashSet) PolicyEvaluator(com.sun.identity.policy.client.PolicyEvaluator) HashMap(java.util.HashMap) AuthContext(com.sun.identity.authentication.AuthContext) HashMap(java.util.HashMap) Map(java.util.Map) PolicyEvaluatorFactory(com.sun.identity.policy.client.PolicyEvaluatorFactory) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) HashSet(java.util.HashSet)

Aggregations

SSOToken (com.iplanet.sso.SSOToken)1 AuthContext (com.sun.identity.authentication.AuthContext)1 PolicyDecision (com.sun.identity.policy.PolicyDecision)1 PolicyEvaluator (com.sun.identity.policy.client.PolicyEvaluator)1 PolicyEvaluatorFactory (com.sun.identity.policy.client.PolicyEvaluatorFactory)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ServletException (javax.servlet.ServletException)1