Sticky FAQs

»

ID #1194

How can I generate HMAC Muse Proxy proxified links in Java?

The instructions and code provided below are based on the following assumptions: 
-  MuseProxyFoundationHMAC  is the Muse Proxy application configured with HMAC authentication; 
-  quiet  is the value of the secret; 
-  userName  and  timestamp  are the signature parameters; 
-  SHA256  is the algorithm; 
- the separator between the signature parameters is . .

 

Integrate the following code into your Java project:

package com.edulib.muse.proxy.samples;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedHashMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/index")
public class Index extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* Default constructor.
*/
public Index() {
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");

String algorithm = "HmacSHA256";
String secret = "quiet";
String proxyURL = "http://MUSE_PROXY_HOST:PORT";
String applicationID = "MuseProxyFoundationHMAC";
String separator = ".";

// timestamp represent the current UNIX timestamp
String timestamp = "" + System.currentTimeMillis() / 1000L;
// referer is the referer from request
String referer = request.getRequestURL().toString();
// userAddres is IP adress for user from request
String userAddress = request.getRemoteAddr();
// userAgent is userAgent from request header
String userAgent = request.getHeader("user-agent");

LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>();
parameters.put("userName", "test");
parameters.put("ts", timestamp);
parameters.put("referer", referer);
parameters.put("userAddress", userAddress);
parameters.put("userAgent", userAgent);

MuseProxyHMAC museProxyHMAC = new MuseProxyHMAC(proxyURL, applicationID, secret, algorithm, separator, parameters);

PrintWriter out = response.getWriter();
out.print("<a href=\"" + museProxyHMAC.generatedURL + "\" target=\"_blank\">" + museProxyHMAC.generatedURL + "</a>");

}

}

where replace  MUSE_PROXY_HOST:PORT  with your actual Muse Proxy host and port.

The aditional file  MuseProxyHMAC.java  that needs to be integrated into your Java project can be downloaded from here.

Tags: can, generate, HMAC, how, java, links, muse, proxified, proxy

Related entries: -

Last update: 2017-05-23 12:31
Author: Administrator
Revision: 1.9

Print this record Send FAQ to a friend Show this as PDF file
Rate this FAQ

Average rating: 0 (0 Votes)

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry

powered by phpMyFAQ 2.7.2