Search in sources :

Example 31 with SEPASecurityException

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;
}
Also used : EntryCursor(org.apache.directory.api.ldap.model.cursor.EntryCursor) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 32 with SEPASecurityException

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;
}
Also used : EntryCursor(org.apache.directory.api.ldap.model.cursor.EntryCursor) JsonObject(com.google.gson.JsonObject) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) JsonParser(com.google.gson.JsonParser)

Example 33 with SEPASecurityException

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());
    }
}
Also used : JsonElement(com.google.gson.JsonElement) FileWriter(java.io.FileWriter) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 34 with SEPASecurityException

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());
    }
}
Also used : JsonElement(com.google.gson.JsonElement) FileWriter(java.io.FileWriter) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 35 with SEPASecurityException

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());
    }
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPABindingsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)69 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)29 IOException (java.io.IOException)20 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)18 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)15 Response (it.unibo.arces.wot.sepa.commons.response.Response)12 SEPAPropertiesException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)11 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)10 JsonObject (com.google.gson.JsonObject)7 JsonParser (com.google.gson.JsonParser)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)7 Modification (org.apache.directory.api.ldap.model.entry.Modification)7 SEPABindingsException (it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException)5 Credentials (it.unibo.arces.wot.sepa.commons.security.Credentials)5 HttpEntity (org.apache.http.HttpEntity)5 JOSEException (com.nimbusds.jose.JOSEException)4 SignedJWT (com.nimbusds.jwt.SignedJWT)4 JWTResponse (it.unibo.arces.wot.sepa.commons.response.JWTResponse)4 ParseException (java.text.ParseException)4