Search in sources :

Example 6 with SEPASecurityException

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

the class LdapSecurityManager method isAuthorized.

@Override
public boolean isAuthorized(String uid) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] isAuthorized " + uid + " uid=" + uid + ",ou=authorizedIdentities," + prop.getBase(), "(objectclass=*)");
    bind();
    try {
        cursor = ldap.search("uid=" + uid + ",ou=authorizedIdentities," + prop.getBase(), "(objectclass=*)", SearchScope.OBJECT, "*");
        return cursor.next();
    } catch (LdapException | CursorException e) {
        logger.error("[LDAP] isAuthorized exception " + e.getMessage());
        throw new SEPASecurityException("isAuthorized 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) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 7 with SEPASecurityException

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

the class LdapSecurityManager method setUserExpiringPeriod.

@Override
public void setUserExpiringPeriod(long period) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] setUserExpiringPeriod " + period + " uid=user,uid=expiring,ou=jwt," + prop.getBase());
    bind();
    try {
        Modification expiring = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "pwdGraceExpire");
        ldap.modify("uid=user,uid=expiring,ou=jwt," + prop.getBase(), expiring);
    } catch (LdapException e) {
        logger.error("setUserExpiringPeriod exception " + e.getMessage());
        throw new SEPASecurityException("setUserExpiringPeriod 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 8 with SEPASecurityException

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

the class LdapSecurityManager method containsCredentials.

@Override
public boolean containsCredentials(String uid) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] containsCredentials " + "uid=" + uid + ",ou=credentials," + prop.getBase(), "(objectclass=*)");
    bind();
    try {
        cursor = ldap.search("uid=" + uid + ",ou=credentials," + prop.getBase(), "(objectclass=*)", SearchScope.OBJECT, "*");
        return cursor.next();
    } catch (LdapException | CursorException e) {
        logger.error("[LDAP] checkCredentials exception " + e.getMessage());
        throw new SEPASecurityException("checkCredentials 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) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 9 with SEPASecurityException

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

the class LdapSecurityManager method setIssuer.

@Override
public void setIssuer(String issuer) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] setIssuer " + issuer + " uid=issuer,ou=jwt," + prop.getBase());
    bind();
    try {
        Modification replaceGn = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "host", issuer);
        ldap.modify("uid=issuer,ou=jwt," + prop.getBase(), replaceGn);
    } catch (LdapException e) {
        logger.error("[LDAP] setIssuer exception " + e.getMessage());
        throw new SEPASecurityException("setIssuer 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 10 with SEPASecurityException

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

the class LdapSecurityManager method removeJwt.

@Override
public void removeJwt(String uid) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] removeToken " + "uid=" + uid + ",ou=tokens," + prop.getBase());
    bind();
    try {
        ldap.delete("uid=" + uid + ",ou=tokens," + prop.getBase());
    } catch (LdapException e) {
        logger.error("[LDAP] removeToken exception " + e.getMessage());
        throw new SEPASecurityException("removeToken exception " + e.getMessage());
    } 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