<%@page import="java.util.ArrayList"%> <%@page import="java.net.URLEncoder"%> <%@page import="java.util.List"%> <%@page import="java.security.MessageDigest"%> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> Insert title here
<%
	// If the user needs to signup, verify the user credentials and then redirect as follows.
	String email = "john.abraham@yourcompany.com";
	String ts = request.getParameter("ts"); // or Get the current time in millis on GMT 0:0 /UTC eg: 1341224998301
	String remoteauthkey = "xxxxxxxxxxb3691xxxxx9cbb9xxxxx87dc5xxxxxed3e5xxxxx0a7b8xxxxx7639dxxxxx4fdcbxxxxxc8514dxxxxxec1bfxxxxxccc61xxxxxc54e58xxxxx0123f4"; // Remote Authentication key
	String operation = "signup"; 
	String utype = "supportrep"; // Type to user - supportrep | portal
	String fullName = "John Abraham Thomas"; // Name of the user
	String loginName = "john.abraham"; // login name should contain only 6 to 30 characters, with letters, numbers, underscores and dot (.) 
	/*
	String role = "manager";  //Role of the User (optional, applicable only if utype is "supportrep", if not specified - "CEO" Role is the default)  eg: Manager
	String profile = "standard"; //Profile of the User (optional, applicable only if utype is "supportrep", if not specified - "Administrator" is the default) eg: Standard
	*/
	/*Order of md5 digest operation+email+loginName+fullName+utype+role+profile+token+ts  or operation+email+loginName+fullName+utype+token+ts*/
	List  inputList = new ArrayList();
	inputList.add(operation);
	inputList.add(email);
	inputList.add(loginName);
	inputList.add(fullName);
	inputList.add(utype);
	/* inputList.add(role);
	inputList.add(profile); */
	inputList.add(remoteauthkey);
	inputList.add(ts);
	String apikey = hexdigit(md5Of(inputList));
	String redirectURL = "https://support.yourcompany.com/support/RemoteAuth?operation="+URLEncoder.encode(operation, "UTF8")+"&email="+URLEncoder.encode(email,"UTF8")+"&fullname="+URLEncoder.encode(fullName,"UTF8")+"&loginname="+URLEncoder.encode(loginName,"UTF8")+"&utype="+URLEncoder.encode(utype,"UTF8")+"&ts="+URLEncoder.encode(ts,"UTF8")+"&apikey="+apikey;
	response.sendRedirect(redirectURL);
%>

<%!
public static final char[] HEX = { '0', '1', '2', '3', '4', '5', '6', '7','8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
public static byte[] md5Of(List list) {
	try {
		StringBuffer rawString = new StringBuffer();
		for (String elem : list) {
			rawString.append(elem);
		}
		byte[] p = rawString.toString().getBytes("ISO-8859-1");
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.reset();
		md.update(p);
		byte[] digest = md.digest();
		return digest;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}

public static String hexdigit(byte[] input) {
	char[] b16 = new char[input.length * 2];
	int i = 0;
	for (byte c : input) {
		int low = c & 0xF;
		int high = (c & 0xF0) >> 4;
		b16[(i++)] = HEX[high];
		b16[(i++)] = HEX[low];
	}
	return new String(b16);
}
%>