diff --git a/pom.xml b/pom.xml index 7a5067e..64f3aab 100644 --- a/pom.xml +++ b/pom.xml @@ -157,12 +157,6 @@ 2.7 test - - org.gcube.common - couchdb-connector - 2.0.0-SNAPSHOT - test - diff --git a/src/test/java/org/gcube/common/authz/Importer.java b/src/test/java/org/gcube/common/authz/Importer.java deleted file mode 100644 index 1337b4e..0000000 --- a/src/test/java/org/gcube/common/authz/Importer.java +++ /dev/null @@ -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 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 idList = new ArrayList(); - - 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 roles = new ArrayList(); - 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); - - } -} -