Added a way to simulate users and roles
This commit is contained in:
parent
40fa20a871
commit
84ebc54546
|
@ -0,0 +1,121 @@
|
|||
package org.gcube.informationsystem.resourceregistry.authorization;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.common.authorization.library.ClientType;
|
||||
import org.gcube.common.authorization.library.exception.AuthorizationException;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.gcube.common.authorization.utils.secret.Secret;
|
||||
import org.gcube.common.authorization.utils.user.GCubeUser;
|
||||
import org.gcube.common.authorization.utils.user.User;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class FakeSecret extends Secret {
|
||||
|
||||
protected ObjectMapper mapper;
|
||||
protected String context;
|
||||
protected GCubeUser user;
|
||||
protected ClientInfo clientInfo;
|
||||
|
||||
public FakeSecret(String json, String context) {
|
||||
this(json);
|
||||
this.context = context;
|
||||
user.setAdditionalProperty("context", context);
|
||||
try {
|
||||
token = mapper.writeValueAsString(user);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public FakeSecret(String json) {
|
||||
super(100, json);
|
||||
mapper = new ObjectMapper();
|
||||
try {
|
||||
user = mapper.readValue(json, GCubeUser.class);
|
||||
context = (String) user.getAdditionalProperty("context");
|
||||
clientInfo = new ClientInfo() {
|
||||
|
||||
private static final long serialVersionUID = -7249742033510171100L;
|
||||
|
||||
@Override
|
||||
public ClientType getType() {
|
||||
return ClientType.USER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRoles() {
|
||||
return (List<String>) user.getRoles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return user.getUsername();
|
||||
}
|
||||
};
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void check(String token) throws AuthorizationException {
|
||||
super.check(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setToken() throws Exception {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetToken() throws Exception {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientInfo getClientInfo() throws Exception {
|
||||
return clientInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Caller getCaller() throws Exception {
|
||||
Caller caller = new Caller(clientInfo, "TOKEN");
|
||||
return caller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContext() throws Exception {
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getHTTPAuthorizationHeaders() {
|
||||
Map<String, String> authorizationHeaders = new HashMap<>();
|
||||
authorizationHeaders.put("x-fake-secret", token);
|
||||
return authorizationHeaders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpired() throws Exception {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRefreshable() throws Exception {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"id": "user.four",
|
||||
"roles": ["Context-Manager"],
|
||||
"picture": "",
|
||||
"name": "User Four",
|
||||
"middle_name": "",
|
||||
"male": true,
|
||||
"location_industry": "Pisa, Italy",
|
||||
"given_name": "User",
|
||||
"email": "user.user.four@d4science.org",
|
||||
"job_title": "No Job",
|
||||
"family_name": "Four",
|
||||
"verified_email": true,
|
||||
"context" : "/gcube"
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"id": "user.three",
|
||||
"roles": ["Infrastructure-Manager"],
|
||||
"picture": "",
|
||||
"name": "User Three",
|
||||
"middle_name": "",
|
||||
"male": true,
|
||||
"location_industry": "Pisa, Italy",
|
||||
"given_name": "User",
|
||||
"email": "user.three@d4science.org",
|
||||
"job_title": "No Job",
|
||||
"family_name": "Three",
|
||||
"verified_email": true,
|
||||
"context" : "/gcube"
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"id": "user.two",
|
||||
"roles": ["IS-Manager"],
|
||||
"picture": "",
|
||||
"name": "User Two",
|
||||
"middle_name": "",
|
||||
"male": true,
|
||||
"location_industry": "Pisa, Italy",
|
||||
"given_name": "User",
|
||||
"email": "user.two@d4science.org",
|
||||
"job_title": "No Job",
|
||||
"family_name": "Two",
|
||||
"verified_email": true,
|
||||
"context" : "/gcube"
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"id": "user.one",
|
||||
"roles": [],
|
||||
"picture": "",
|
||||
"name": "User One",
|
||||
"middle_name": "",
|
||||
"male": true,
|
||||
"location_industry": "Pisa, Italy",
|
||||
"given_name": "User",
|
||||
"email": "user.one@d4science.org",
|
||||
"job_title": "No Job",
|
||||
"family_name": "One",
|
||||
"verified_email": true,
|
||||
"context" : "/gcube"
|
||||
}
|
Loading…
Reference in New Issue