Search in sources :

Example 1 with Mod

use of org.apache.directory.fortress.core.model.Mod in project directory-fortress-core by apache.

the class AuditDAO method searchUserMods.

/**
 * @param audit
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Mod> searchUserMods(UserAudit audit) throws FinderException {
    List<Mod> modList = new ArrayList<>();
    LdapConnection ld = null;
    String auditRoot = Config.getInstance().getProperty(AUDIT_ROOT);
    String userRoot = getRootDn(audit.getContextId(), GlobalIds.USER_ROOT);
    try {
        String filter = GlobalIds.FILTER_PREFIX + ACCESS_MOD_CLASS_NM + ")(" + REQDN + "=" + SchemaConstants.UID_AT + "=" + audit.getUserId() + "," + userRoot + ")";
        if (audit.getBeginDate() != null) {
            String szTime = TUtil.encodeGeneralizedTime(audit.getBeginDate());
            filter += "(" + REQEND + ">=" + szTime + ")";
        }
        filter += ")";
        // log.warn("filter=" + filter);
        ld = getLogConnection();
        SearchCursor searchResults = search(ld, auditRoot, SearchScope.ONELEVEL, filter, AUDIT_MOD_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            modList.add(getModEntityFromLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (LdapException e) {
        String error = "searchUserMods caught LdapException id=" + e.getMessage();
        throw new FinderException(GlobalErrIds.AUDT_MOD_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "searchUserMods caught CursorException id=" + e.getMessage();
        throw new FinderException(GlobalErrIds.AUDT_MOD_SEARCH_FAILED, error, e);
    } finally {
        closeLogConnection(ld);
    }
    return modList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) Mod(org.apache.directory.fortress.core.model.Mod) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 2 with Mod

use of org.apache.directory.fortress.core.model.Mod in project directory-fortress-core by apache.

the class AuditMgrRestImpl method searchAdminMods.

/**
 * {@inheritDoc}
 */
@Override
public List<Mod> searchAdminMods(UserAudit uAudit) throws SecurityException {
    VUtil.assertNotNull(uAudit, GlobalErrIds.AUDT_INPUT_NULL, CLS_NM + ".searchAdminMods");
    List<Mod> outRecords;
    FortRequest request = new FortRequest();
    request.setContextId(this.contextId);
    request.setEntity(uAudit);
    if (this.adminSess != null) {
        request.setSession(adminSess);
    }
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.AUDIT_MODS);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() == 0) {
        outRecords = response.getEntities();
        // do not return a null list to the caller:
        if (outRecords == null) {
            outRecords = new ArrayList<>();
        }
    } else {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
    return outRecords;
}
Also used : Mod(org.apache.directory.fortress.core.model.Mod) FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 3 with Mod

use of org.apache.directory.fortress.core.model.Mod in project directory-fortress-core by apache.

the class AuditMgrConsole method printMods.

/**
 * @param list
 */
void printMods(List<Mod> list) {
    ReaderUtil.clearScreen();
    if (list != null && list.size() > 0) {
        int ctr = 0;
        for (Mod mod : list) {
            /*
                public class Mod
                {
                    private String reqSession;
                    private String objectClass;
                    private String reqAuthzID;
                    private String reqDN;
                    private String reqResult;
                    private String reqStart;
                    private String reqEnd;
                    private String reqType;
                    private List<String> reqMod;
                */
            System.out.println("AUDIT MOD OBJECT [" + ctr++ + "]:");
            System.out.println("    reqAuthzID               [" + mod.getReqAuthzID() + "]");
            System.out.println("    reqDN                    [" + mod.getReqDN() + "]");
            System.out.println("    reqStart                 [" + mod.getReqStart() + "]");
            System.out.println("    reqEnd                   [" + mod.getReqEnd() + "]");
            System.out.println("    objectClass              [" + mod.getObjectClass() + "]");
            System.out.println("    reqResult                [" + mod.getReqResult() + "]");
            System.out.println("    reqSession               [" + mod.getReqSession() + "]");
            System.out.println("    reqType                  [" + mod.getReqType() + "]");
            if (mod.getReqMod() != null) {
                int mCtr = 0;
                for (String mVal : mod.getReqMod()) {
                    System.out.println("    reqMod[" + mCtr++ + "]                [" + mVal + "]");
                }
            }
        }
    } else {
        System.out.println("Mods list empty");
    }
}
Also used : Mod(org.apache.directory.fortress.core.model.Mod)

Example 4 with Mod

use of org.apache.directory.fortress.core.model.Mod in project directory-fortress-core by apache.

the class AuditMgrImplTest method searchMods.

/**
 * @param msg
 * @param uArray
 */
private static void searchMods(String msg, String[][] uArray) {
    LogUtil.logIt(msg);
    try {
        AuditMgr auditMgr = getManagedAuditMgr();
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            // now search for successful session creation events:
            UserAudit uAudit = new UserAudit();
            uAudit.setUserId(user.getUserId());
            uAudit.setFailedOnly(false);
            List<Mod> mods = auditMgr.searchUserSessions(uAudit);
            assertNotNull(mods);
            assertTrue(CLS_NM + "searchUserSessions failed search for successful authentication user [" + user.getUserId() + "]", mods.size() > 0);
        }
        LOG.debug("searchUserSessions successful");
    } catch (SecurityException ex) {
        LOG.error("searchUserSessions: failed with SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) Mod(org.apache.directory.fortress.core.model.Mod) UserAudit(org.apache.directory.fortress.core.model.UserAudit) AuditMgr(org.apache.directory.fortress.core.AuditMgr) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 5 with Mod

use of org.apache.directory.fortress.core.model.Mod in project directory-fortress-core by apache.

the class AuditMgrImplTest method searchAdminMods.

/**
 * @param msg
 * @param uArray
 */
private static void searchAdminMods(String msg, String[][] uArray, String[][] oArray, String[][] opArray) {
    LogUtil.logIt(msg);
    try {
        AuditMgr auditMgr = getManagedAuditMgr();
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            // now search for successful session creation events:
            UserAudit uAudit = new UserAudit();
            uAudit.setUserId(user.getUserId());
            for (String[] obj : oArray) {
                String objName = AdminUtil.getObjName(PermTestData.getName(obj));
                uAudit.setObjName(objName);
                for (String[] op : opArray) {
                    uAudit.setOpName(PermTestData.getName(op));
                    List<Mod> mods = auditMgr.searchAdminMods(uAudit);
                    assertNotNull(mods);
                    assertTrue(CLS_NM + "searchAdminMods failed search for successful authentication user [" + user.getUserId() + "] object [" + objName + "] operation [" + PermTestData.getName(op) + "]", mods.size() > 0 || !isAudit(objName, PermTestData.getName(op)));
                    boolean result = mods.size() > 0 || !isAudit(objName, PermTestData.getName(op));
                    LOG.debug("searchAdminMods search user [" + user.getUserId() + "] object [" + objName + "] operation [" + PermTestData.getName(op) + "] result: " + result);
                // System.out.println("searchAdminMods search user [" + user.getUserId() + "] object [" + objName + "] operation [" + PermTestData.getName(op) + "] result: " + result);
                }
            }
        }
        LOG.debug("searchAdminMods successful");
    } catch (SecurityException ex) {
        LOG.error("searchAdminMods: failed with SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) Mod(org.apache.directory.fortress.core.model.Mod) UserAudit(org.apache.directory.fortress.core.model.UserAudit) AuditMgr(org.apache.directory.fortress.core.AuditMgr) SecurityException(org.apache.directory.fortress.core.SecurityException)

Aggregations

Mod (org.apache.directory.fortress.core.model.Mod)10 SecurityException (org.apache.directory.fortress.core.SecurityException)4 UserAudit (org.apache.directory.fortress.core.model.UserAudit)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)2 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 AuditMgr (org.apache.directory.fortress.core.AuditMgr)2 FinderException (org.apache.directory.fortress.core.FinderException)2 FortRequest (org.apache.directory.fortress.core.model.FortRequest)2 FortResponse (org.apache.directory.fortress.core.model.FortResponse)2 User (org.apache.directory.fortress.core.model.User)2 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)2 ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)1