git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/common/authorization-service/2.0@132550 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
fd513d1592
commit
1e9ac077c7
6
pom.xml
6
pom.xml
|
@ -157,12 +157,6 @@
|
||||||
<version>2.7</version>
|
<version>2.7</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.common</groupId>
|
|
||||||
<artifactId>couchdb-connector</artifactId>
|
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,129 +0,0 @@
|
||||||
package org.gcube.common.authz;
|
|
||||||
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.persistence.Persistence;
|
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
|
||||||
import org.gcube.common.authorizationservice.persistence.RelationDBPersistence;
|
|
||||||
import org.gcube.common.couchdb.connector.HttpCouchClient;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean;
|
|
||||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.stream.JsonReader;
|
|
||||||
|
|
||||||
public class Importer {
|
|
||||||
|
|
||||||
private static final String URL = "http://accounting-d-d4s.d4science.org/";
|
|
||||||
private static final String TEST_DB = "authorization";
|
|
||||||
private static final String TEST_USER_USERNAME = "admin";
|
|
||||||
private static final String TEST_USER_PASSWORD = "better_than_nothing";
|
|
||||||
|
|
||||||
private static final String DESIGN_NAME = "_gcube";
|
|
||||||
private static final String VIEW_NAME = "_user_and_scope";
|
|
||||||
|
|
||||||
private static final List<String> usernameToAvoid = Arrays.asList("lucio.lelii", "roberto.cirillo", "luca.frosini", "valentina.marioli",
|
|
||||||
"massimiliano.assante", "costantino.perciante", "francesco.mangiacrapa", "fabio.sinibaldi",
|
|
||||||
"giancarlo.panichi", "alessandro.pieve","pasquale.pagano","leonardo.candela", "andrea.rossi");
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
HttpCouchClient httpCouch =new HttpCouchClient(URL,TEST_DB, TEST_USER_USERNAME, TEST_USER_PASSWORD);
|
|
||||||
String docs = httpCouch.getAllDocs();
|
|
||||||
|
|
||||||
JsonReader reader = new Gson().newJsonReader(new StringReader(docs));
|
|
||||||
|
|
||||||
ArrayList<String> idList = new ArrayList<String>();
|
|
||||||
|
|
||||||
reader.beginObject();
|
|
||||||
reader.nextName();
|
|
||||||
reader.nextInt();
|
|
||||||
reader.nextName();
|
|
||||||
reader.nextInt();
|
|
||||||
reader.nextName();
|
|
||||||
reader.beginArray();
|
|
||||||
while (reader.hasNext()){
|
|
||||||
reader.beginObject();
|
|
||||||
reader.nextName();
|
|
||||||
String id = reader.nextString();
|
|
||||||
idList.add(id);
|
|
||||||
reader.nextName();
|
|
||||||
reader.nextString();
|
|
||||||
reader.nextName();
|
|
||||||
reader.beginObject();
|
|
||||||
reader.nextName();
|
|
||||||
reader.nextString();
|
|
||||||
reader.endObject();
|
|
||||||
reader.endObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
reader.close();
|
|
||||||
|
|
||||||
int tokenToinsert =0;
|
|
||||||
|
|
||||||
RelationDBPersistence rdp = new RelationDBPersistence();
|
|
||||||
rdp.setEntitymanagerFactory(Persistence.createEntityManagerFactory("authorization"));
|
|
||||||
|
|
||||||
|
|
||||||
for (String id : idList){
|
|
||||||
|
|
||||||
String doc = httpCouch.getDoc(id);
|
|
||||||
try{
|
|
||||||
|
|
||||||
reader = new Gson().newJsonReader(new StringReader(doc));
|
|
||||||
reader.beginObject();
|
|
||||||
reader.nextName();
|
|
||||||
reader.nextString();
|
|
||||||
reader.nextName();
|
|
||||||
reader.nextString();
|
|
||||||
reader.nextName();
|
|
||||||
String token = reader.nextString();
|
|
||||||
reader.nextName();
|
|
||||||
String userName = reader.nextString();
|
|
||||||
System.out.println("token = "+token);
|
|
||||||
System.out.println("username = "+userName);
|
|
||||||
if (usernameToAvoid.contains(userName))
|
|
||||||
throw new Exception("name not to store");
|
|
||||||
|
|
||||||
//roles
|
|
||||||
reader.nextName();
|
|
||||||
reader.beginArray();
|
|
||||||
List<String> roles = new ArrayList<String>();
|
|
||||||
while (reader.hasNext())
|
|
||||||
roles.add(reader.nextString());
|
|
||||||
reader.endArray();
|
|
||||||
//end roles
|
|
||||||
|
|
||||||
System.out.println("roles = "+roles.toString());
|
|
||||||
|
|
||||||
reader.nextName();
|
|
||||||
String scope = reader.nextString();
|
|
||||||
System.out.println("scope = "+scope);
|
|
||||||
|
|
||||||
if (!new ScopeBean(scope).is(Type.VRE))
|
|
||||||
throw new Exception("is not a vre token");
|
|
||||||
reader.endObject();
|
|
||||||
|
|
||||||
try{
|
|
||||||
rdp.saveAuthorizationEntry(token, scope, new UserInfo(userName, roles), "TOKEN", "default");
|
|
||||||
}catch(Exception e){
|
|
||||||
System.out.println(e.getMessage());
|
|
||||||
}
|
|
||||||
tokenToinsert++;
|
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e) {
|
|
||||||
System.out.println(e.getMessage()+" : "+doc);
|
|
||||||
}finally{
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("token inserted "+tokenToinsert);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue