use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.
the class SyncLdap method retrievePassword.
private String retrievePassword() throws SEPASecurityException {
String ret = null;
try {
bind();
logger.log(Level.getLevel("ldap"), "[LDAP] Sync LDAP " + ldap.getConfig().getLdapHost() + ":" + ldap.getConfig().getLdapPort() + " Base DN: " + endpointPasswordUid);
EntryCursor cursor = ldap.search(endpointPasswordUid, "(objectclass=simpleSecurityObject)", SearchScope.OBJECT);
if (cursor.next()) {
// Password has to be store as "plain text"
ret = new String(cursor.get().get("userPassword").get().getBytes());
logger.log(Level.getLevel("ldap"), "userPassword: " + ret);
} else
throw new SEPASecurityException(endpointPasswordUid + " not found in LDAP");
} catch (LdapException | CursorException e) {
throw new SEPASecurityException(e.getMessage());
} finally {
unbind();
}
return ret;
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.
the class SyncLdap method sync.
public JsonObject sync() throws SEPASecurityException {
JsonObject ret = new JsonObject();
try {
bind();
logger.log(Level.getLevel("ldap"), "[LDAP] Sync LDAP " + ldap.getConfig().getLdapHost() + ":" + ldap.getConfig().getLdapPort() + " Base DN: " + usersUid);
EntryCursor cursor = ldap.search(usersUid, "(objectclass=inetOrgPerson)", SearchScope.ONELEVEL);
for (org.apache.directory.api.ldap.model.entry.Entry entry : cursor) {
logger.log(Level.getLevel("ldap"), entry.toString("--"));
if (entry.get("uid") == null) {
logger.log(Level.getLevel("ldap"), "Missing *uid*");
continue;
}
if (entry.get("description") == null) {
logger.log(Level.getLevel("ldap"), "Missing *description* " + entry.get("uid"));
continue;
}
String uid = entry.get("uid").getString();
String description = entry.get("description").getString();
ret.add(uid, new JsonParser().parse(description).getAsJsonObject());
}
} catch (LdapException | SEPASecurityException e) {
logger.error("[LDAP] LdapException|CursorException : " + e.getMessage());
} finally {
unbind();
}
return ret;
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.
the class VirtuosoIsql method createUser.
public void createUser(String uid, JsonElement graphs) throws SEPASecurityException {
logger.info("createUser " + uid + " " + graphs);
new File("command.sql").delete();
try {
PrintWriter f = new PrintWriter(new BufferedWriter(new FileWriter("command.sql")));
f.write("DB.DBA.USER_CREATE ('" + uid + "', '" + endpointUsersPassword + "');");
f.println();
f.write("DB.DBA.RDF_DEFAULT_USER_PERMS_SET ('nobody', 0);");
f.println();
f.write("DB.DBA.RDF_DEFAULT_USER_PERMS_SET ('" + uid + "', 0);");
f.println();
f.write("GRANT SPARQL_UPDATE TO \"" + uid + "\";");
f.println();
for (Entry<String, JsonElement> graph : graphs.getAsJsonObject().entrySet()) {
f.write("DB.DBA.RDF_GRAPH_USER_PERMS_SET ('" + graph.getKey() + "', '" + uid + "', " + graph.getValue().getAsInt() + ");");
f.println();
}
f.close();
isql();
} catch (IOException | InterruptedException e) {
throw new SEPASecurityException(e.getMessage());
}
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.
the class VirtuosoIsql method updateUser.
public void updateUser(String uid, JsonObject addGraphs, JsonArray removeGraphs) throws SEPASecurityException {
logger.info("updateUser " + uid + " add:" + addGraphs + " remove:" + removeGraphs);
if (new File("command.sql").exists())
new File("command.sql").delete();
try {
PrintWriter f = new PrintWriter(new BufferedWriter(new FileWriter("command.sql")));
for (Entry<String, JsonElement> graph : addGraphs.entrySet()) {
f.write("DB.DBA.RDF_GRAPH_USER_PERMS_SET ('" + graph.getKey() + "', '" + uid + "', " + graph.getValue().getAsInt() + ");");
f.println();
}
for (JsonElement graph : removeGraphs) {
f.write("DB.DBA.RDF_GRAPH_USER_PERMS_SET ('" + graph.getAsString() + "', '" + uid + "', 0);");
f.println();
}
f.close();
isql();
} catch (IOException | InterruptedException e) {
throw new SEPASecurityException(e.getMessage());
}
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.
the class ITPattern method genericClientDoubleSubscribe.
@RepeatedTest(ConfigurationProvider.REPEATED_TEST)
@Timeout(10)
public void genericClientDoubleSubscribe() {
try {
genericClient = new GenericClient(provider.getJsap(), handler);
genericClient.subscribe("RANDOM", null, "first", provider.TIMEOUT, provider.NRETRY);
genericClient.subscribe("RANDOM1", null, "second", provider.TIMEOUT, provider.NRETRY);
handler.waitSubscribes(2);
Response ret = genericClient.update("RANDOM", null, provider.TIMEOUT, provider.NRETRY);
assertFalse(ret.isError(), ret.toString());
ret = genericClient.update("RANDOM1", null, provider.TIMEOUT, provider.NRETRY);
assertFalse(ret.isError(), ret.toString());
handler.waitEvents(4);
genericClient.unsubscribe(handler.getSpuid("first"), provider.TIMEOUT, provider.NRETRY);
genericClient.unsubscribe(handler.getSpuid("second"), provider.TIMEOUT, provider.NRETRY);
handler.waitUnsubscribes(2);
} catch (SEPAProtocolException | SEPASecurityException | SEPAPropertiesException | SEPABindingsException | InterruptedException | IOException e) {
e.printStackTrace();
assertFalse(true, e.getMessage());
}
}
Aggregations