source: fedd/abac-src/ttg/demo/src/DiscoveryServlet.java @ b770aa0

axis_examplecompt_changesinfo-opsversion-2.00version-3.01version-3.02
Last change on this file since b770aa0 was 8780cbec, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

ABAC sources from Cobham

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import java.io.*;
2import java.util.*;
3import javax.servlet.*;
4import javax.servlet.http.*;
5import com.nailabs.abac.credential.*;
6
7/**
8 *
9 */
10public class DiscoveryServlet extends HttpServlet {
11    public DiscoveryService service = null;
12    public String fileName = new String();
13
14    /** Initialize the discovery service with a credential store */
15    public void init(ServletConfig config) throws ServletException {
16        fileName = config.getInitParameter("PolicyFile");
17        service = new DiscoveryService(fileName);
18    }
19
20    /**
21     *
22     */
23    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
24        throws ServletException, java.io.IOException {
25        String issuer = req.getParameter("Issuer");
26        String defines = req.getParameter("Defines");
27        String subject = req.getParameter("Subject");
28        PrintWriter out = resp.getWriter();
29        String results[] = new String[0];
30
31        if(issuer != null) {
32            //out.println("<!--issuer = " + issuer + "-->");
33            results = service.getCredentialsIssuedBy(issuer);
34        }
35        if(defines != null) {
36            StringTokenizer st = new StringTokenizer(defines, ".");
37            if(st.countTokens() < 2) {
38                out.close();
39                return;
40            }
41            String entity = st.nextToken();
42            String role = st.nextToken();
43            //out.print("<!--entity=");
44            //out.print(entity);
45            //out.print(", role=");
46            //out.print(role);
47            //out.println("-->");
48            results = service.findCredentialsDefiningRole(entity, role);
49        }
50        if(subject != null) {
51            results = service.findCredentialsBySubject(subject);
52        }
53
54        for(int i = 0; i < results.length; i++) {
55            out.println(results[i]);
56        }
57        out.close();
58    }
59
60    /**
61     * Post handles adding a credential domain since the XML file is
62     * potentially quite large.
63     */
64    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
65        throws ServletException, java.io.IOException {
66        String xml = req.getParameter("xml");
67        String reset = req.getParameter("reset");
68        PrintWriter out = resp.getWriter();
69
70        out.println("<html><head><title>Adding RTML Credential</title");
71        out.println("<body>");
72        if(xml == null) {
73            service = new DiscoveryService(fileName);
74            System.out.println("Intializing service with file " + fileName);
75            out.println("Deleting credential domain . . .");
76        } else {
77            service.addCredentialDomain(xml);
78            out.println("Added credential domain . . .");
79        }
80        //out.println("<br>reset = " + reset);
81        out.println("</body>");
82        out.println("</html>");
83        out.println(xml);
84        out.close();
85    }
86}
Note: See TracBrowser for help on using the repository browser.