import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import com.nailabs.abac.credential.*; /** * */ public class DiscoveryServlet extends HttpServlet { public DiscoveryService service = null; public String fileName = new String(); /** Initialize the discovery service with a credential store */ public void init(ServletConfig config) throws ServletException { fileName = config.getInitParameter("PolicyFile"); service = new DiscoveryService(fileName); } /** * */ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { String issuer = req.getParameter("Issuer"); String defines = req.getParameter("Defines"); String subject = req.getParameter("Subject"); PrintWriter out = resp.getWriter(); String results[] = new String[0]; if(issuer != null) { //out.println(""); results = service.getCredentialsIssuedBy(issuer); } if(defines != null) { StringTokenizer st = new StringTokenizer(defines, "."); if(st.countTokens() < 2) { out.close(); return; } String entity = st.nextToken(); String role = st.nextToken(); //out.print(""); results = service.findCredentialsDefiningRole(entity, role); } if(subject != null) { results = service.findCredentialsBySubject(subject); } for(int i = 0; i < results.length; i++) { out.println(results[i]); } out.close(); } /** * Post handles adding a credential domain since the XML file is * potentially quite large. */ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { String xml = req.getParameter("xml"); String reset = req.getParameter("reset"); PrintWriter out = resp.getWriter(); out.println("