Search in sources :

Example 1 with LDAPRealm

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);
    }
}
Also used : LDAPRealm(org.exist.security.realm.ldap.LDAPRealm) XPathException(org.exist.xquery.XPathException) Method(java.lang.reflect.Method) LDAPRealm(org.exist.security.realm.ldap.LDAPRealm) Realm(org.exist.security.realm.Realm) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with LDAPRealm

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;
}
Also used : Account(org.exist.security.Account) SecurityManager(org.exist.security.SecurityManager) LDAPRealm(org.exist.security.realm.ldap.LDAPRealm) XPathException(org.exist.xquery.XPathException) AuthenticationException(org.exist.security.AuthenticationException) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Aggregations

LDAPRealm (org.exist.security.realm.ldap.LDAPRealm)2 XPathException (org.exist.xquery.XPathException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Account (org.exist.security.Account)1 AuthenticationException (org.exist.security.AuthenticationException)1 PermissionDeniedException (org.exist.security.PermissionDeniedException)1 SecurityManager (org.exist.security.SecurityManager)1 Realm (org.exist.security.realm.Realm)1