git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-library@117106 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
809fe7e592
commit
7da0346582
|
@ -1,76 +0,0 @@
|
|||
package org.gcube.common.authorization.library;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class AuthorizationToken implements Serializable {
|
||||
|
||||
private static HexBinaryAdapter hexAdapter = new HexBinaryAdapter();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String user;
|
||||
private String group = null;
|
||||
|
||||
protected AuthorizationToken(){}
|
||||
|
||||
public AuthorizationToken(String user){
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public AuthorizationToken(String user, String group){
|
||||
this.user = user;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the user
|
||||
*/
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AuthorizationToken [user=" + user + "]";
|
||||
}
|
||||
|
||||
public static String marshal(AuthorizationToken v) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(v);
|
||||
oos.close();
|
||||
byte[] serializedBytes = baos.toByteArray();
|
||||
return hexAdapter.marshal(serializedBytes);
|
||||
}
|
||||
|
||||
public static AuthorizationToken unmarshal(String v) throws Exception {
|
||||
byte[] serializedBytes = hexAdapter.unmarshal(v);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(serializedBytes);
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
AuthorizationToken result = (AuthorizationToken) ois.readObject();
|
||||
bais.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package org.gcube.common.authorization.library.provider;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CalledMethodProvider {
|
||||
|
||||
public static CalledMethodProvider instance = new CalledMethodProvider();
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(CalledMethodProvider.class);
|
||||
|
||||
// Thread local variable containing each thread's ID
|
||||
private static final InheritableThreadLocal<String> threadMethod =
|
||||
new InheritableThreadLocal<String>() {
|
||||
|
||||
@Override protected String initialValue() {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private CalledMethodProvider(){}
|
||||
|
||||
public String get(){
|
||||
String calledMethod = threadMethod.get();
|
||||
logger.info("getting "+calledMethod+" in thread "+Thread.currentThread().getId() );
|
||||
return calledMethod;
|
||||
}
|
||||
|
||||
public void set(String calledMethod){
|
||||
threadMethod.set(calledMethod);
|
||||
logger.info("setting "+calledMethod+" in thread "+Thread.currentThread().getId() );
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
threadMethod.remove();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package org.gcube.common.authorization.library.provider;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SecurityTokenProvider {
|
||||
|
||||
public static SecurityTokenProvider instance = new SecurityTokenProvider();
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(SecurityTokenProvider.class);
|
||||
|
||||
// Thread local variable containing each thread's ID
|
||||
private static final InheritableThreadLocal<String> threadToken =
|
||||
new InheritableThreadLocal<String>() {
|
||||
|
||||
@Override protected String initialValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private SecurityTokenProvider(){}
|
||||
|
||||
public String get(){
|
||||
logger.debug("gettin securityToken "+threadToken.get()+" in thread "+Thread.currentThread().getId());
|
||||
return threadToken.get();
|
||||
}
|
||||
|
||||
public void set(String authorizationToken){
|
||||
logger.debug("setting securityToken "+authorizationToken+" in thread "+Thread.currentThread().getId());
|
||||
threadToken.set(authorizationToken);
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
threadToken.remove();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue