1 | import java.io.*; |
---|
2 | import java.util.*; |
---|
3 | import javax.servlet.*; |
---|
4 | import javax.servlet.http.*; |
---|
5 | import com.nailabs.abac.credential.*; |
---|
6 | |
---|
7 | /** |
---|
8 | * |
---|
9 | */ |
---|
10 | public 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 | } |
---|