Search in sources :

Example 6 with Mod

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

the class AuditMgrConsole method getModReport.

/**
 */
void getModReport() {
    ReaderUtil.clearScreen();
    try {
        UserAudit uAudit = new UserAudit();
        System.out.println("Enter userId to search Audit Mods with:");
        String val = ReaderUtil.readLn();
        if (StringUtils.isNotEmpty(val)) {
            uAudit.setUserId(val);
            System.out.println("size=" + val.length() + " val=" + val);
        } else {
            System.out.println("val is empty or null");
        }
        System.out.println("Check within the last n hours?  Enter number of hours or null for unlimited");
        val = ReaderUtil.readLn();
        if (val != null && val.length() > 0) {
            int hours = Integer.parseInt(val);
            Date date = new Date();
            long millis = date.getTime();
            millis = millis - (1000 * 60 * 60 * hours);
            Date date2 = new Date(millis);
            uAudit.setBeginDate(date2);
        }
        List<Mod> list = am.searchUserSessions(uAudit);
        printMods(list);
        System.out.println("ENTER to continue");
    } catch (SecurityException e) {
        LOG.error("getModReport caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
    }
    ReaderUtil.readChar();
}
Also used : Mod(org.apache.directory.fortress.core.model.Mod) UserAudit(org.apache.directory.fortress.core.model.UserAudit) Date(java.util.Date)

Example 7 with Mod

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

the class AuditMgrConsole method getAdminModReport.

void getAdminModReport() {
    ReaderUtil.clearScreen();
    try {
        UserAudit uAudit = new UserAudit();
        System.out.println("Enter userId to search Audit Mods with or NULL for skip:");
        String val = ReaderUtil.readLn();
        if (StringUtils.isNotEmpty(val)) {
            uAudit.setUserId(val);
            System.out.println("size=" + val.length() + " val=" + val);
        }
        System.out.println("Check within the last n hours?  Enter number of hours or null for unlimited");
        val = ReaderUtil.readLn();
        if (val != null && val.length() > 0) {
            int hours = Integer.parseInt(val);
            Date date = new Date();
            long millis = date.getTime();
            millis = millis - (1000 * 60 * 60 * hours);
            Date date2 = new Date(millis);
            uAudit.setBeginDate(date2);
        }
        /*
            System.out.println("Enter begin time and date - format YYYYMMDDHHMM or null for unlimited");
            val = ReaderUtil.readLn();
            if (val != null && val.length() > 0)
            {
                //int hours = Integer.parseInt(val);
                int year = new Integer(val.substring(0, 3));
                int month = new Integer(val.substring(0, 3));
                int day = new Integer(val.substring(0, 3));


                Date date = new Date();
                java.sql.Date date2 = new java.sql.Date(2011, 11, 25);
                date2.getTime();
                long millis = date.getTime();
                millis = millis - (1000 * 60 * 60 * hours);
                Date date2 = new Date(millis);
                uAudit.setBeginDate(date2);
            } */
        System.out.println("Enter admin object name to search Audit Mods with or NULL for skip:");
        val = ReaderUtil.readLn();
        if (StringUtils.isNotEmpty(val)) {
            uAudit.setObjName(val);
            System.out.println("size=" + val.length() + " val=" + val);
        }
        System.out.println("Enter admin operation name to search Audit Mods with or NULL for skip:");
        val = ReaderUtil.readLn();
        if (StringUtils.isNotEmpty(val)) {
            uAudit.setOpName(val);
            System.out.println("size=" + val.length() + " val=" + val);
        }
        List<Mod> list = am.searchAdminMods(uAudit);
        printMods(list);
        System.out.println("ENTER to continue");
    } catch (SecurityException e) {
        LOG.error("getAdminModReport caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
    }
    ReaderUtil.readChar();
}
Also used : Mod(org.apache.directory.fortress.core.model.Mod) UserAudit(org.apache.directory.fortress.core.model.UserAudit) Date(java.util.Date)

Example 8 with Mod

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

the class AuditMgrRestImpl method searchUserSessions.

/**
 * {@inheritDoc}
 */
@Override
public List<Mod> searchUserSessions(UserAudit uAudit) throws SecurityException {
    VUtil.assertNotNull(uAudit, GlobalErrIds.AUDT_INPUT_NULL, CLS_NM + ".searchUserSessions");
    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_SESSIONS);
    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 9 with Mod

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

the class AuditDAO method searchAdminMods.

/**
 * @param audit
 * @return
 * @throws FinderException
 */
List<Mod> searchAdminMods(UserAudit audit) throws FinderException {
    List<Mod> modList = new ArrayList<>();
    LdapConnection ld = null;
    String auditRoot = Config.getInstance().getProperty(AUDIT_ROOT);
    try {
        String filter = "(&(|(objectclass=" + ACCESS_MOD_CLASS_NM + ")";
        filter += "(objectclass=" + ACCESS_ADD_CLASS_NM + "))";
        if (StringUtils.isNotEmpty(audit.getDn())) {
            filter += "(" + REQDN + "=" + audit.getDn() + ")";
        }
        if (StringUtils.isNotEmpty(audit.getObjName())) {
            filter += "(|(" + REQMOD + "=" + GlobalIds.FT_MODIFIER_CODE + ":= " + audit.getObjName() + ".";
            if (StringUtils.isNotEmpty(audit.getOpName())) {
                filter += audit.getOpName();
            }
            filter += "*)";
            filter += "(" + REQMOD + "=" + GlobalIds.FT_MODIFIER_CODE + ":+ " + audit.getObjName() + ".";
            if (StringUtils.isNotEmpty(audit.getOpName())) {
                filter += audit.getOpName();
            }
            filter += "*))";
        }
        if (StringUtils.isNotEmpty(audit.getInternalUserId())) {
            filter += "(|(" + REQMOD + "=" + GlobalIds.FT_MODIFIER + ":= " + audit.getInternalUserId() + ")";
            filter += "(" + REQMOD + "=" + GlobalIds.FT_MODIFIER + ":+ " + audit.getInternalUserId() + "))";
        }
        if (audit.getBeginDate() != null) {
            String szTime = TUtil.encodeGeneralizedTime(audit.getBeginDate());
            filter += "(" + REQEND + ">=" + szTime + ")";
        }
        if (audit.getEndDate() != null) {
            String szTime = TUtil.encodeGeneralizedTime(audit.getEndDate());
            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 = "searchAdminMods caught LdapException id=" + e.getMessage();
        throw new FinderException(GlobalErrIds.AUDT_MOD_ADMIN_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "searchAdminMods caught CursorException id=" + e.getMessage();
        throw new FinderException(GlobalErrIds.AUDT_MOD_ADMIN_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 10 with Mod

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

the class AuditDAO method getModEntityFromLdapEntry.

private Mod getModEntityFromLdapEntry(Entry le, long sequence) throws LdapInvalidAttributeValueException {
    Mod mod = new ObjectFactory().createMod();
    mod.setSequenceId(sequence);
    mod.setObjectClass(getAttribute(le, OBJECTCLASS));
    mod.setReqAuthzID(getAttribute(le, REQUAUTHZID));
    mod.setReqDN(getAttribute(le, REQDN));
    mod.setReqEnd(getAttribute(le, REQEND));
    mod.setReqResult(getAttribute(le, REQRESULT));
    mod.setReqSession(getAttribute(le, REQSESSION));
    mod.setReqStart(getAttribute(le, REQSTART));
    mod.setReqType(getAttribute(le, REQTYPE));
    mod.setReqMod(getAttributes(le, REQMOD));
    return mod;
}
Also used : Mod(org.apache.directory.fortress.core.model.Mod) ObjectFactory(org.apache.directory.fortress.core.model.ObjectFactory)

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