-
Notifications
You must be signed in to change notification settings - Fork 2
/
SingleSingOnVlex.java
52 lines (37 loc) · 1.46 KB
/
SingleSingOnVlex.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.*;
import java.util.Date;
public class SingleSingOnVlex
{
public String remote_auth(HashMap<String,String> hm)throws Exception
{
MessageDigest md = MessageDigest.getInstance("MD5");
Number current = System.currentTimeMillis()/1000;
if (hm.get("timestamp") == null){
hm.put("timestamp",current.toString());
};
String keys[] = {"name", "email", "account_id", "token","timestamp"};
String buffer = new String();
for(int i=0;i<keys.length;i++){
buffer = buffer.concat(hm.get(keys[i]).toString());
}
byte[] dataBytes = buffer.getBytes();
md.update(dataBytes, 0, dataBytes.length);
byte[] mdbytes = md.digest();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < mdbytes.length; i++) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
}
hm.put("hash",sb.toString());
hm.remove("token");
String remote_auth_url = "http://vlex.com/session/remote_auth?";
Object params[] = hm.keySet().toArray();
for(int i=0;i<params.length;i++){
remote_auth_url += params[i].toString()+"="+hm.get(params[i]).toString();
if (i < params.length-1) {
remote_auth_url +="&";}
}
return remote_auth_url;
}
}