Stated switching to new authz
This commit is contained in:
parent
0c718dcee6
commit
e1423021d9
6
pom.xml
6
pom.xml
|
@ -149,6 +149,12 @@
|
||||||
<artifactId>storagehub-application-persistence</artifactId>
|
<artifactId>storagehub-application-persistence</artifactId>
|
||||||
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>keycloak-client</artifactId>
|
||||||
|
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.taliox</groupId>
|
<groupId>io.taliox</groupId>
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class SocialPost extends Thread {
|
||||||
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(basePath);
|
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(basePath);
|
||||||
gxhttpStringRequest.from(Constants.CATALOGUE_NAME);
|
gxhttpStringRequest.from(Constants.CATALOGUE_NAME);
|
||||||
gxhttpStringRequest.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
gxhttpStringRequest.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||||
gxhttpStringRequest.setSecurityToken(Constants.getCatalogueApplicationToken());
|
gxhttpStringRequest.setSecurityToken(Constants.getSecurityToken());
|
||||||
gxhttpStringRequest.path(SOCIAL_SERVICE_WRITE_APPLICATION_POST_PATH);
|
gxhttpStringRequest.path(SOCIAL_SERVICE_WRITE_APPLICATION_POST_PATH);
|
||||||
|
|
||||||
HttpURLConnection httpURLConnection = gxhttpStringRequest.post(objectMapper.writeValueAsString(objectNode));
|
HttpURLConnection httpURLConnection = gxhttpStringRequest.post(objectMapper.writeValueAsString(objectNode));
|
||||||
|
|
|
@ -9,6 +9,9 @@ import java.util.Properties;
|
||||||
import javax.ws.rs.InternalServerErrorException;
|
import javax.ws.rs.InternalServerErrorException;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
|
||||||
|
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||||
|
import org.gcube.common.keycloak.model.TokenResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
|
@ -17,22 +20,12 @@ public class Constants {
|
||||||
public static final String CATALOGUE_NAME = "gCat";
|
public static final String CATALOGUE_NAME = "gCat";
|
||||||
|
|
||||||
private static final String PROPERTY_FILENAME = "config.properties";
|
private static final String PROPERTY_FILENAME = "config.properties";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Key : Context
|
* Key : Context
|
||||||
* Value : Application Token
|
* Value : Application Token
|
||||||
*/
|
*/
|
||||||
protected static final Map<String,String> applicationTokens;
|
protected static final Map<String,String> applicationTokens;
|
||||||
|
|
||||||
public static String getCatalogueApplicationToken() {
|
|
||||||
try {
|
|
||||||
return applicationTokens.get(ContextUtility.getCurrentContext());
|
|
||||||
} catch(Exception e) {
|
|
||||||
throw new InternalServerErrorException(
|
|
||||||
"Unable to retrieve Application Token for context " + ContextUtility.getCurrentContext(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
applicationTokens = new HashMap<>();
|
applicationTokens = new HashMap<>();
|
||||||
|
@ -50,4 +43,50 @@ public class Constants {
|
||||||
throw new WebApplicationException(e);
|
throw new WebApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static String getCatalogueApplicationToken() {
|
||||||
|
try {
|
||||||
|
return applicationTokens.get(ContextUtility.getCurrentContext());
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new InternalServerErrorException(
|
||||||
|
"Unable to retrieve Application Token for context " + ContextUtility.getCurrentContext(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String CLIENT_SECRET_FILENAME = "clientSecret";
|
||||||
|
private static final String CLIENT_ID = "gcat";
|
||||||
|
protected static String clientSecret;
|
||||||
|
|
||||||
|
private static String getClientSecret(String context) {
|
||||||
|
try {
|
||||||
|
if(clientSecret==null) {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
InputStream input = Constants.class.getClassLoader().getResourceAsStream(CLIENT_SECRET_FILENAME);
|
||||||
|
properties.load(input);
|
||||||
|
String root = context.substring(0, context.indexOf('/', 1));
|
||||||
|
clientSecret = properties.getProperty(root);
|
||||||
|
}
|
||||||
|
return clientSecret;
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new InternalServerErrorException(
|
||||||
|
"Unable to retrieve Application Token for context " + ContextUtility.getCurrentContext(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getJWTAccessToken() throws Exception {
|
||||||
|
String contextToAuthorise = ContextUtility.getCurrentContext();
|
||||||
|
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(CLIENT_ID, getClientSecret(contextToAuthorise), contextToAuthorise, null);
|
||||||
|
return tr.getAccessToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getSecurityToken() throws Exception {
|
||||||
|
try {
|
||||||
|
return getJWTAccessToken();
|
||||||
|
}catch (Exception e) {
|
||||||
|
return getCatalogueApplicationToken();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class CatalogueStorageHubManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL ensureResourcePersistence(URL persistedURL, String itemID, String resourceID) throws Exception {
|
public URL ensureResourcePersistence(URL persistedURL, String itemID, String resourceID) throws Exception {
|
||||||
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
|
ApplicationMode applicationMode = new ApplicationMode(Constants.getSecurityToken());
|
||||||
try {
|
try {
|
||||||
applicationMode.start();
|
applicationMode.start();
|
||||||
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(persistedURL.toString());
|
GXHTTPStringRequest gxhttpStringRequest = GXHTTPStringRequest.newRequest(persistedURL.toString());
|
||||||
|
@ -68,7 +68,7 @@ public class CatalogueStorageHubManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteResourcePersistence(String itemID, String resourceID, String mimeType) throws Exception {
|
public void deleteResourcePersistence(String itemID, String resourceID, String mimeType) throws Exception {
|
||||||
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
|
ApplicationMode applicationMode = new ApplicationMode(Constants.getSecurityToken());
|
||||||
try {
|
try {
|
||||||
applicationMode.start();
|
applicationMode.start();
|
||||||
storageHubManagement = new StorageHubManagement();
|
storageHubManagement = new StorageHubManagement();
|
||||||
|
@ -97,7 +97,7 @@ public class CatalogueStorageHubManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renameFile(String resourceID, String revisionID) throws Exception {
|
public void renameFile(String resourceID, String revisionID) throws Exception {
|
||||||
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
|
ApplicationMode applicationMode = new ApplicationMode(Constants.getSecurityToken());
|
||||||
try {
|
try {
|
||||||
applicationMode.start();
|
applicationMode.start();
|
||||||
FileContainer createdfile = storageHubManagement.getPersistedFile();
|
FileContainer createdfile = storageHubManagement.getPersistedFile();
|
||||||
|
@ -110,7 +110,7 @@ public class CatalogueStorageHubManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRevisionID(String resourceID, String revisionID) throws Exception {
|
public void addRevisionID(String resourceID, String revisionID) throws Exception {
|
||||||
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
|
ApplicationMode applicationMode = new ApplicationMode(Constants.getSecurityToken());
|
||||||
try {
|
try {
|
||||||
applicationMode.start();
|
applicationMode.start();
|
||||||
internalAddRevisionID(resourceID, revisionID);
|
internalAddRevisionID(resourceID, revisionID);
|
||||||
|
@ -120,7 +120,7 @@ public class CatalogueStorageHubManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileContainer retrievePersistedFile(String id, String mimeType) throws Exception {
|
public FileContainer retrievePersistedFile(String id, String mimeType) throws Exception {
|
||||||
ApplicationMode applicationMode = new ApplicationMode(Constants.getCatalogueApplicationToken());
|
ApplicationMode applicationMode = new ApplicationMode(Constants.getSecurityToken());
|
||||||
try {
|
try {
|
||||||
applicationMode.start();
|
applicationMode.start();
|
||||||
return storageHubManagement.getPersistedFile(id, mimeType);
|
return storageHubManagement.getPersistedFile(id, mimeType);
|
||||||
|
@ -129,8 +129,8 @@ public class CatalogueStorageHubManagement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public FileContainer getPersistedFile() {
|
public FileContainer getPersistedFile() {
|
||||||
return storageHubManagement.getPersistedFile();
|
return storageHubManagement.getPersistedFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
/*.gcubekey
|
/*.gcubekey
|
||||||
/*.properties
|
/*.properties
|
||||||
/gCat_zuliprc
|
/*_zuliprc
|
||||||
/leonardo.candela_zuliprc
|
/clientSecret
|
||||||
/luca.frosini_zuliprc
|
|
||||||
/pasquale.pagano_zuliprc
|
|
||||||
/clientID
|
|
Loading…
Reference in New Issue