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();
}
}
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();
}
}
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();
}
}
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();
}
}
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());
}
Aggregations