Skip to content

Commit

Permalink
Modified federation of authenticated Orion CB
Browse files Browse the repository at this point in the history
  • Loading branch information
robcalla committed Oct 12, 2018
1 parent 3c87fa2 commit 92f5467
Show file tree
Hide file tree
Showing 9 changed files with 1,446 additions and 1,448 deletions.
2,779 changes: 1,389 additions & 1,390 deletions Idra/src/main/java/it/eng/idra/api/AdministrationAPI.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class OrionCatalogueConfiguration extends ODMSCatalogueAdditionalConfigur

private boolean isAuthenticated;
private String authToken;
private String refreshToken;
//private String refreshToken;
private String oauth2Endpoint;
private String clientID;
private String clientSecret;
Expand All @@ -38,20 +38,20 @@ public OrionCatalogueConfiguration() {
this.setType("ORION");
}

public OrionCatalogueConfiguration(boolean isAuthenticated, String authToken,String refreshToken,String oauth2Endpoint,String client_id,String client_secret, String datasets) {
public OrionCatalogueConfiguration(boolean isAuthenticated, String authToken,String oauth2Endpoint,String client_id,String client_secret, String datasets) {
super();
this.isAuthenticated = isAuthenticated;
this.authToken = authToken;
this.refreshToken=refreshToken;
// this.refreshToken=refreshToken;
this.oauth2Endpoint=oauth2Endpoint;
this.clientID=client_id;
this.clientSecret=client_secret;
this.orionDatasetDumpString = datasets;
this.setType("ORION");
}

public OrionCatalogueConfiguration(boolean isAuthenticated, String authToken,String refreshToken,String oauth2Endpoint,String client_id,String client_secret, String datasets,String dumpPath) {
this(isAuthenticated, authToken, refreshToken,oauth2Endpoint,client_id,client_secret,datasets);
public OrionCatalogueConfiguration(boolean isAuthenticated, String authToken,String oauth2Endpoint,String client_id,String client_secret, String datasets,String dumpPath) {
this(isAuthenticated, authToken, oauth2Endpoint,client_id,client_secret,datasets);
this.orionDatasetFilePath=dumpPath;
}

Expand Down Expand Up @@ -93,13 +93,13 @@ public void setOrionDatasetFilePath(String orionDatasetFilePath) {
this.orionDatasetFilePath = orionDatasetFilePath;
}

public String getRefreshToken() {
return refreshToken;
}

public void setRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
}
// public String getRefreshToken() {
// return refreshToken;
// }
//
// public void setRefreshToken(String refreshToken) {
// this.refreshToken = refreshToken;
// }

public String getOauth2Endpoint() {
return oauth2Endpoint;
Expand Down Expand Up @@ -136,7 +136,7 @@ public int hashCode() {
result = prime * result + ((oauth2Endpoint == null) ? 0 : oauth2Endpoint.hashCode());
result = prime * result + ((orionDatasetDumpString == null) ? 0 : orionDatasetDumpString.hashCode());
result = prime * result + ((orionDatasetFilePath == null) ? 0 : orionDatasetFilePath.hashCode());
result = prime * result + ((refreshToken == null) ? 0 : refreshToken.hashCode());
//result = prime * result + ((refreshToken == null) ? 0 : refreshToken.hashCode());
return result;
}

Expand Down Expand Up @@ -181,11 +181,11 @@ public boolean equals(Object obj) {
return false;
} else if (!orionDatasetFilePath.equals(other.orionDatasetFilePath))
return false;
if (refreshToken == null) {
if (other.refreshToken != null)
return false;
} else if (!refreshToken.equals(other.refreshToken))
return false;
// if (refreshToken == null) {
// if (other.refreshToken != null)
// return false;
// } else if (!refreshToken.equals(other.refreshToken))
// return false;
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions Idra/src/main/java/it/eng/idra/odfscheduler/ODFScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ public void startOAUTHTokenSynchJob(ODMSCatalogue node) {
.newTrigger()
.withIdentity("synchToken_"+Integer.toString(node.getId()), "triggers")
.withSchedule(simpleSchedule().repeatForever()
.withIntervalInSeconds(3600) //Ogni ora fa il check
.withMisfireHandlingInstructionNextWithExistingCount())
.withIntervalInSeconds(3000) //Ogni 55 min fa il check
.withMisfireHandlingInstructionNowWithRemainingCount() //Per casomai aggiornarlo subito quando il server riparte
)
.build();

scheduler.scheduleJob(job, trigger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
// TODO Auto-generated method stub

try {
logger.info("Requesting token for catalogue: "+context.getJobDetail().getJobDataMap().get("nodeID"));
ODMSCatalogue node = ODMSManager.getODMSCatalogue((int) context.getJobDetail().getJobDataMap().get("nodeID"));
OrionCatalogueConfiguration orionConfig = (OrionCatalogueConfiguration) node.getAdditionalConfig();
HashMap<String, String> map = retrieveUpdatedToken(orionConfig);
orionConfig.setAuthToken(map.get("access_token"));
orionConfig.setRefreshToken(map.get("refresh_token"));
logger.info("New Token: "+orionConfig.getAuthToken());
//orionConfig.setRefreshToken(map.get("refresh_token"));
node.setAdditionalConfig(orionConfig);
ODMSManager.updateODMSCatalogue(node, true);

Expand All @@ -89,8 +91,10 @@ private static HashMap<String,String> retrieveUpdatedToken(OrionCatalogueConfigu
WebTarget webTarget = client.target(conf.getOauth2Endpoint());
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_FORM_URLENCODED);
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
formData.add("grant_type", "refresh_token");
formData.add("refresh_token", conf.getRefreshToken());
//formData.add("grant_type", "refresh_token");
//formData.add("refresh_token", conf.getRefreshToken());
formData.add("grant_type", "client_credentials");

Response response = invocationBuilder.post(Entity.form(formData));

StatusType status = response.getStatusInfo();
Expand All @@ -99,7 +103,7 @@ private static HashMap<String,String> retrieveUpdatedToken(OrionCatalogueConfigu
if(status.getStatusCode() == 200){
HashMap<String, String> map = new HashMap<String, String>();
map.put("access_token", res.getString("access_token"));
map.put("refresh_token",res.getString("refresh_token"));
//map.put("refresh_token",res.getString("refresh_token"));
return map;
}else{
throw new Exception("Error while retrieving the authentication token");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ public ODMSCatalogueAdditionalConfiguration deserialize(JsonElement arg0, Type a
boolean isAuth=false;
String datasets=j.optString("orionDatasetDumpString","");
String dumpPath=j.optString("orionDatasetFilePath","");
String authToken="",refreshToken="",oauth2Endpoint="",client_id="",client_secret="";
String authToken="",oauth2Endpoint="",client_id="",client_secret="";
try {
isAuth=j.getBoolean("isAuthenticated");
}catch(JSONException e) {

}
if(isAuth) {
authToken=j.optString("authToken");
refreshToken=j.optString("refreshToken");
//refreshToken=j.optString("refreshToken");
oauth2Endpoint=j.optString("oauth2Endpoint");
client_id=j.optString("clientID");
client_secret=j.optString("clientSecret");
}
return new OrionCatalogueConfiguration(isAuth, authToken, refreshToken, oauth2Endpoint, client_id, client_secret, datasets,dumpPath);
//return new OrionCatalogueConfiguration(isAuth, authToken, refreshToken, oauth2Endpoint, client_id, client_secret, datasets,dumpPath);
return new OrionCatalogueConfiguration(isAuth, authToken, oauth2Endpoint, client_id, client_secret, datasets,dumpPath);
}else if(j.has("sparqlDatasetDumpString")) {
String datasets=j.optString("sparqlDatasetDumpString","");
String dumpPath=j.optString("sparqlDatasetFilePath","");
Expand All @@ -77,7 +78,7 @@ public JsonElement serialize(ODMSCatalogueAdditionalConfiguration arg0, Type arg
OrionCatalogueConfiguration c = (OrionCatalogueConfiguration) arg0;
jsonObject.addProperty("isAuthenticated", c.isAuthenticated());
jsonObject.addProperty("authToken", c.getAuthToken());
jsonObject.addProperty("refreshToken", c.getRefreshToken());
//jsonObject.addProperty("refreshToken", c.getRefreshToken());
jsonObject.addProperty("clientID", c.getClientID());
jsonObject.addProperty("clientSecret", c.getClientSecret());
jsonObject.addProperty("oauth2Endpoint", c.getOauth2Endpoint());
Expand Down
23 changes: 5 additions & 18 deletions IdraPortal/src/main/webapp/catalogues/Catalogue.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,33 +157,20 @@
<div class="col-md-12 form-group">
<label for="oauth2Endpoint">Oauth2 Endpoint:</label> <input type="text"
name="refreshToken" class="form-control" ng-model="node.additionalConfig.oauth2Endpoint" />
<!-- <p class="help-block" ng-show="dumpInvalid">Please provide a -->
<!-- valid dump url</p> -->
</div>
<div class="col-md-6 form-group">
<label for="accessToken">Access Token:</label> <input type="text"
name="accessToken" class="form-control" ng-model="node.additionalConfig.authToken" />
<!-- <p class="help-block" ng-show="dumpInvalid">Please provide a -->
<!-- valid dump url</p> -->
</div>
<div class="col-md-6 form-group">
<label for="refreshToken">Refresh Token:</label> <input type="text"
name="refreshToken" class="form-control" ng-model="node.additionalConfig.refreshToken" />
<!-- <p class="help-block" ng-show="dumpInvalid">Please provide a -->
<!-- valid dump url</p> -->
</div>
<div class="col-md-6 form-group">
<label for="clientID">Client ID:</label> <input type="text"
name="clientID" class="form-control" ng-model="node.additionalConfig.clientID" />
<!-- <p class="help-block" ng-show="dumpInvalid">Please provide a -->
<!-- valid dump url</p> -->
</div>
<div class="col-md-6 form-group">
<label for="clientSecret">Client Secret:</label> <input type="text"
name="clientSecret" class="form-control" ng-model="node.additionalConfig.clientSecret" />
<!-- <p class="help-block" ng-show="dumpInvalid">Please provide a -->
<!-- valid dump url</p> -->
</div>
<div class="col-md-6 form-group" ng-show="mode=='update'">
<label for="accessToken">Access Token:</label> <input ng-disabled="true" type="text"
name="accessToken" class="form-control" ng-model="node.additionalConfig.authToken" />
</div>

</span>
</div>

Expand Down
16 changes: 9 additions & 7 deletions IdraPortal/src/main/webapp/catalogues/Catalogues.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
<li class="breadcrumb-item"><a href="#metadata">Home</a></li>
<li class="breadcrumb-item active">Federated Catalogues</li>
</ul>
<div class="col-md-3 tabbable" style="padding-left:0px">
<ul class="nav nav-tabs" ng-init="main.active.tab = 'local'">
<li ng-class="{active: main.active.tab == 'local'}"><a
ng-click="main.active.tab = 'local'">Local</a></li>
<li ng-class="{active: main.active.tab == 'remote'}"><a
ng-click="main.active.tab = 'remote'">Remote</a></li>
</ul>
<div class="col-12-md">
<div class="col-md-3 tabbable" style="padding-left:0px">
<ul class="nav nav-tabs" ng-init="main.active.tab = 'local'">
<li ng-class="{active: main.active.tab == 'local'}"><a
ng-click="main.active.tab = 'local'">Local</a></li>
<li ng-class="{active: main.active.tab == 'remote'}"><a
ng-click="main.active.tab = 'remote'">Remote</a></li>
</ul>
</div>
</div>

<div class="tab-content">
Expand Down
4 changes: 2 additions & 2 deletions IdraPortal/src/main/webapp/catalogues/catalogues.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ angular.module("IdraPlatform").controller('CataloguesController',["$scope","$htt

}


$scope.itemsByPage=8;

$scope.itemsByPage=20;

$scope.selectedPredicate = $scope.predicates[0];

$scope.getHours = function(millisecond){
Expand Down
10 changes: 7 additions & 3 deletions IdraPortal/src/main/webapp/catalogues/single_catalogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ angular.module("IdraPlatform").controller('CatalogueCtrl',['$scope','$http','con

$scope.types=config.NODE_TYPES.split(',');
$scope.grades=config.FEDERATION_LEVEL.split(',');
$scope.updatePeriods=[{text:'1 hour',value:'3600'},{text:'1 day',value:'86400'},{text:'1 week',value:'604800'}];
$scope.updatePeriods=[{text:'-',value:'0'},{text:'1 hour',value:'3600'},{text:'1 day',value:'86400'},{text:'1 week',value:'604800'}];

$scope.dcatProfiles = [{text:'DCATAP',value:'DCATAP'},{text:'DCATAP_IT',value:'DCATAP_IT'}];
$scope.ODMSCategories = [{text:'Municipality',value:'Municipality'},{text:'Province',value:'Province'},{text:'Private Institution',value:'Private Institution'},{text:'Public Body',value:'Public Body'},{text:'Region',value:'Region'}];
Expand Down Expand Up @@ -532,8 +532,12 @@ angular.module("IdraPlatform").controller('CatalogueCtrl',['$scope','$http','con
break;
}

if((node.federationLevel=='LEVEL_3' || node.federationLevel=='LEVEL_2') && node.refreshPeriod==''){
node.refreshPeriod=$scope.refreshPeriod;
if(node.refreshPeriod==''){
if((node.federationLevel=='LEVEL_3' || node.federationLevel=='LEVEL_2')){
node.refreshPeriod=$scope.refreshPeriod;
}else{
node.refreshPeriod="0";
}
}

if(node.nodeType == 'WEB'){
Expand Down

0 comments on commit 92f5467

Please sign in to comment.