Search in sources :

Example 56 with SEPASecurityException

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

the class LdapSecurityManager method getIdentity.

@Override
public DigitalIdentity getIdentity(String uid) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] getIdentity " + uid + " uid=" + uid + ",ou=authorizedIdentities," + prop.getBase(), "(objectclass=*)");
    bind();
    try {
        cursor = ldap.search("uid=" + uid + ",ou=authorizedIdentities," + prop.getBase(), "(objectclass=*)", SearchScope.OBJECT, "*");
        if (!cursor.next())
            throw new SEPASecurityException("uid=" + uid + ",ou=authorizedIndentities," + prop.getBase() + " NOT FOUND");
        // SPARQL endpoint credentials are stored as Java Serialized Object
        Credentials credentials = null;
        if (cursor.get().contains("objectClass", "javaSerializedObject")) {
            credentials = Credentials.deserialize(cursor.get().get("javaSerializedData").getBytes());
        }
        if (cursor.get().contains("objectClass", "device"))
            return new DeviceIdentity(uid, credentials);
        else if (cursor.get().contains("objectClass", "applicationProcess"))
            return new ApplicationIdentity(uid, credentials);
        else
            throw new SEPASecurityException("Digital identity class NOT FOUND");
    } catch (LdapException | CursorException e) {
        logger.error("[LDAP] getIdentity exception " + e.getMessage());
        throw new SEPASecurityException("getIdentity exception " + e.getMessage());
    } finally {
        unbind();
    }
}
Also used : DeviceIdentity(it.unibo.arces.wot.sepa.engine.dependability.authorization.identities.DeviceIdentity) ApplicationIdentity(it.unibo.arces.wot.sepa.engine.dependability.authorization.identities.ApplicationIdentity) 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) Credentials(it.unibo.arces.wot.sepa.commons.security.Credentials)

Example 57 with SEPASecurityException

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

the class LdapSecurityManager method setDeviceExpiringPeriod.

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

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

the class LdapSecurityManager method addAuthorizedIdentity.

@Override
public void addAuthorizedIdentity(DigitalIdentity identity) throws SEPASecurityException {
    logger.log(Level.getLevel("ldap"), "[LDAP] addIdentity uid=" + identity.getUid() + " class: " + identity.getObjectClass());
    bind();
    try {
        Entry entry = new DefaultEntry("uid=" + identity.getUid() + ",ou=authorizedIdentities," + prop.getBase());
        entry.add("ObjectClass", "uidObject");
        entry.add("ObjectClass", "top");
        entry.add("ObjectClass", "javaSerializedObject");
        entry.add("ObjectClass", identity.getObjectClass());
        entry.add("cn", "Authorized Digital Identity");
        entry.add("uid", identity.getUid());
        entry.add("javaClassName", identity.getEndpointCredentials().getClass().getName());
        entry.add("javaSerializedData", identity.getEndpointCredentials().serialize());
        ldap.add(entry);
    } catch (LdapException e) {
        logger.error("[LDAP] addAuthorizedIdentity exception: " + e.getMessage());
        throw new SEPASecurityException("addIdentity exception: " + e.getMessage());
    } finally {
        unbind();
    }
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) 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 59 with SEPASecurityException

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

the class LdapSecurityManager method setDefaultExpiringPeriod.

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

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

the class SPUManager method subscribe.

public Response subscribe(InternalSubscribeRequest req) {
    logger.log(Level.getLevel("SPUManager"), "@subscribe");
    SPUManagerBeans.subscribeRequest();
    // Create or link to an existing SPU
    SPU spu;
    if (Subscriptions.containsSubscribe(req)) {
        spu = Subscriptions.getSPU(req);
    } else {
        spu = Subscriptions.createSPU(req, this);
        // Initialize SPU
        Response init;
        try {
            logger.log(Level.getLevel("SPUManager"), "init SPU");
            init = spu.init();
        } catch (SEPASecurityException | IOException e) {
            logger.error(e.getMessage());
            if (logger.isTraceEnabled())
                e.printStackTrace();
            init = new ErrorResponse(401, "SEPASecurityException", e.getMessage());
        }
        if (init.isError()) {
            logger.error("@subscribe SPU initialization failed: " + init);
            if (req.getAlias() != null) {
                ((ErrorResponse) init).setAlias(req.getAlias());
            }
            return init;
        }
        // Register request
        logger.log(Level.getLevel("SPUManager"), "Register SPU");
        Subscriptions.registerSubscribe(req, spu);
        // Start the SPU thread
        spu.setName(spu.getSPUID());
        logger.log(Level.getLevel("SPUManager"), "Start SPU");
        spu.start();
    }
    Subscriber sub = Subscriptions.addSubscriber(req, spu);
    return new SubscribeResponse(sub.getSID(), req.getAlias(), sub.getSPU().getLastBindings());
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) UnsubscribeResponse(it.unibo.arces.wot.sepa.commons.response.UnsubscribeResponse) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

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