Search in sources :

Example 21 with SEPASecurityException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.

the class LdapSecurityManager method setApplicationExpiringPeriod.

@Override
public void setApplicationExpiringPeriod(long period) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] setApplicationExpiringPeriod " + period + " uid=application,uid=expiring,ou=jwt," + prop.getBase());
    bind();
    try {
        Modification expiring = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "pwdGraceExpire");
        ldap.modify("uid=application,uid=expiring,ou=jwt," + prop.getBase(), expiring);
    } catch (LdapException e) {
        logger.error("setApplicationExpiringPeriod exception " + e.getMessage());
        throw new SEPASecurityException("setApplicationExpiringPeriod exception " + e.getMessage());
    } finally {
        unbind();
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 22 with SEPASecurityException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.

the class LdapSecurityManager method getJwt.

@Override
public SignedJWT getJwt(String uid) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] getToken " + uid + " uid=" + uid + ",ou=tokens," + prop.getBase(), "(objectclass=*)");
    bind();
    try {
        cursor = ldap.search("uid=" + uid + ",ou=tokens," + prop.getBase(), "(objectclass=*)", SearchScope.OBJECT, "*");
        if (!cursor.next())
            throw new SEPASecurityException("uid=" + uid + ",ou=tokens," + prop.getBase() + " NOT FOUND");
        return SignedJWT.parse(cursor.get().get("javaSerializedData").getString());
    } catch (LdapException | CursorException | ParseException e) {
        logger.error("[LDAP] getToken exception " + e.getMessage());
        throw new SEPASecurityException("getToken exception " + e.getMessage());
    } finally {
        unbind();
    }
}
Also used : CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) ParseException(java.text.ParseException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 23 with SEPASecurityException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.

the class LdapSecurityManager method storeCredentials.

@Override
public boolean storeCredentials(DigitalIdentity identity, String client_secret) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] storeCredentials " + identity + " secret: " + client_secret);
    byte[] password = PasswordUtil.createStoragePassword(client_secret.getBytes(), LdapSecurityConstants.HASH_METHOD_SSHA);
    bind();
    try {
        cursor = ldap.search("uid=" + identity.getUid() + ",ou=credentials," + prop.getBase(), "(objectclass=*)", SearchScope.OBJECT, "*");
        if (cursor.next())
            removeCredentials(identity);
        Entry entry = new DefaultEntry("uid=" + identity.getUid() + ",ou=credentials," + prop.getBase());
        entry.add("ObjectClass", "top");
        entry.add("ObjectClass", identity.getObjectClass());
        entry.add("ObjectClass", "uidObject");
        entry.add("ObjectClass", "simpleSecurityObject");
        entry.add("ObjectClass", "javaSerializedObject");
        if (identity.getObjectClass().equals("inetOrgPerson")) {
            entry.add("cn", ((UserIdentity) identity).getCommonName());
            entry.add("sn", ((UserIdentity) identity).getSurname());
        } else
            entry.add("cn", "Authorized Digital Identity " + identity.getUid());
        entry.add("uid", identity.getUid());
        entry.add("userPassword", password);
        entry.add("javaClassName", identity.getEndpointCredentials().getClass().getName());
        entry.add("javaSerializedData", identity.getEndpointCredentials().serialize());
        ldap.add(entry);
    } catch (LdapException | CursorException e) {
        logger.error("[LDAP] storeCredentials exception " + e.getMessage());
        throw new SEPASecurityException("storeCredentials exception " + e.getMessage());
    } finally {
        unbind();
    }
    return true;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 24 with SEPASecurityException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.

the class LdapSecurityManager method getDefaultExpiringPeriod.

@Override
public long getDefaultExpiringPeriod() throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] getDefaultExpiringPeriod " + "uid=default,uid=expiring,ou=jwt," + prop.getBase(), "(objectclass=*)");
    bind();
    try {
        cursor = ldap.search("uid=default,uid=expiring,ou=jwt," + prop.getBase(), "(objectclass=*)", SearchScope.OBJECT, "*");
        if (!cursor.next())
            throw new SEPASecurityException("uid=default,uid=expiring,ou=jwt," + prop.getBase() + " NOT FOUND");
        if (cursor.get().get("pwdGraceExpire") == null)
            throw new SEPASecurityException("uid=default,uid=expiring,ou=jwt," + prop.getBase() + " pwdGraceExpire NOT FOUND");
        Attribute attr = cursor.get().get("pwdGraceExpire");
        return Long.parseLong(attr.getString());
    } catch (LdapException | CursorException e) {
        logger.error("getDefaultExpiringPeriod exception " + e.getMessage());
        throw new SEPASecurityException("getDefaultExpiringPeriod exception " + e.getMessage());
    } finally {
        unbind();
    }
}
Also used : Attribute(org.apache.directory.api.ldap.model.entry.Attribute) 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 25 with SEPASecurityException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.

the class LdapSecurityManager method removeAuthorizedIdentity.

@Override
public void removeAuthorizedIdentity(String id) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] removeIdentity " + "uid=" + id + ",ou=authorizedIdentities," + prop.getBase());
    bind();
    try {
        ldap.delete("uid=" + id + ",ou=authorizedIdentities," + prop.getBase());
    } catch (LdapException e) {
        logger.error("[LDAP] Exception on removing identity: " + "uid=" + id + ",ou=authorizedIdentities," + prop.getBase() + " " + e.getMessage());
        if (logger.isTraceEnabled())
            e.printStackTrace();
        throw new SEPASecurityException("Exception on removing identity: " + "uid=" + id + ",ou=authorizedIdentities," + prop.getBase());
    } finally {
        unbind();
    }
}
Also used : SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

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