Java
The following code example is written in Java,for use with a JSP file:
- <%@ page language="java" import="java.util.*,java.net.*,javax.servlet.*,java.io.*" %>
- <%
- // set up the SecureKey call
- // define parts of the SecureKey request URL
- String LogiAppURL;
- String Username;
- String Roles;
- LogiAppURL = "http://<yourServer>/<LogiApp>";
- Username = "Bob";
- Roles = "1";
- // build complete URL to Logi app
- String getKeyURL = "/rdTemplate/rdGetSecureKey.aspx?Username=" + URLEncoder.encode(Username) + "&Roles=" + URLEncoder.encode(Roles) + "&ClientBrowserAddress=" + URLEncoder.encode(request.getRemoteAddr());
- String finalURL = LogiAppURL + getKeyURL;
- // back-end handshake, passing username, roles and rights to Logi app
- URL url = new URL(response.encodeRedirectURL(finalURL));
- // attempt to make SecureKey call
- try {
- // open the connection
- URLConnection conn = url.openConnection();
- conn.setDoOutput(true);
- // debugging aid: use StreamWriter to write POST data
- // OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
- // wr.write(data);
- // wr.flush();
- // wr.close();
- // get the response
- BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- StringBuffer sb = new StringBuffer();
- String line;
- while ((line = rd.readLine()) != null) {
- sb.append(line);
- }
- rd.close();
- // set the url with the retrieved SecureKey parameter
- LogiAppURL = LogiAppURL + "/rdPage.aspx?rdSecureKey=" + sb.toString();
- // redirect to the application with SecureKey parameter
- response.sendRedirect(LogiAppURL);
- }
- catch (Exception e) {
- throw new Exception("Failed to get SecureKey, request URL: [" + url + "], POST data: [" + data +"]", e);
- }
- %>