use of org.exist.security.realm.ldap.LDAPRealm in project exist by eXist-db.
the class AccountFunctions method getLdapRealm.
private LDAPRealm getLdapRealm(final SecurityManager sm) throws XPathException {
try {
final Method mFindRealm = sm.getClass().getDeclaredMethod("findRealmForRealmId", String.class);
mFindRealm.setAccessible(true);
final Realm realm = (Realm) mFindRealm.invoke(sm, LDAPRealm.ID);
if (realm == null) {
throw new XPathException("The LDAP Realm is not in use!");
}
return (LDAPRealm) realm;
} catch (final NoSuchMethodException ex) {
throw new XPathException(this, "The LDAP Realm is not in use!", ex);
} catch (final SecurityException | IllegalArgumentException | IllegalAccessException se) {
throw new XPathException(this, "Permission to access the LDAP Realm is denied: " + se.getMessage(), se);
} catch (final InvocationTargetException ite) {
throw new XPathException(this, "An error occured whilst accessing the LDAP Realm: " + ite.getMessage(), ite);
}
}
use of org.exist.security.realm.ldap.LDAPRealm in project exist by eXist-db.
the class AccountFunctions method eval.
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
final SecurityManager sm = context.getBroker().getBrokerPool().getSecurityManager();
final LDAPRealm ldapRealm = getLdapRealm(sm);
final String accountName = args[0].itemAt(0).getStringValue();
final Account ldapAccount = sm.getAccount(accountName);
if (ldapAccount == null)
throw new XPathException("The Account '" + accountName + "' does not exist!");
try {
ldapRealm.refreshAccountFromLdap(ldapAccount);
} catch (final PermissionDeniedException | AuthenticationException pde) {
throw new XPathException(this, pde);
}
return Sequence.EMPTY_SEQUENCE;
}
Aggregations