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