Search in sources :

Example 6 with Bind

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

the class AuditMgrConsole method printAuthNReport.

/**
 * @param list
 */
void printAuthNReport(List<Bind> list) {
    if (list != null && list.size() > 0) {
        int ctr = 0;
        for (Bind aBind : list) {
            /*
            public class Bind
                private String createTimestamp;
                private String creatorsName;
                private String entryCSN;
                private String entryDN;
                private String entryUUID;
                private String hasSubordinates;
                private String modifiersName;
                private String modifyTimestamp;
                private String objectClass;
                private String reqAuthzID;
                private String reqControls;
                private String reqDN;
                private String reqEnd;
                private String reqMethod;
                private String reqResult;
                private String reqSession;
                private String reqStart;
                private String reqType;
                private String reqVersion;
                private String structuralObjectClass;
                */
            System.out.println("AUTHENTICATION AUDIT RECORD " + ctr++);
            System.out.println("***************************************");
            System.out.println("    UserId        " + AuditUtil.getAuthZId(aBind.getReqDN()));
            Date aDate = null;
            try {
                aDate = TUtil.decodeGeneralizedTime(aBind.getReqEnd());
            } catch (ParseException pe) {
                System.out.println("    Bind Time     " + "ParseException=" + pe.getMessage());
            }
            if (aDate != null) {
                SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
                String formattedDate = formatter.format(aDate);
                System.out.println("    Bind Time     " + formattedDate);
            }
            System.out.println("    AuthN Type    " + aBind.getReqMethod());
            System.out.println("    Success?      " + aBind.getReqResult().equals("0"));
            System.out.println("    Session       " + aBind.getReqSession());
            System.out.println("    Type          " + aBind.getReqType());
            System.out.println("    Version       " + aBind.getReqVersion());
            System.out.println();
            System.out.println();
        }
    } else {
        System.out.println("no authN's found");
    }
}
Also used : Bind(org.apache.directory.fortress.core.model.Bind) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 7 with Bind

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

the class AuditDAO method getBindEntityFromLdapEntry.

/**
 * @param le
 * @return
 * @throws LdapInvalidAttributeValueException
 * @throws LdapException
 */
private Bind getBindEntityFromLdapEntry(Entry le, long sequence) throws LdapInvalidAttributeValueException {
    Bind auditBind = new ObjectFactory().createBind();
    auditBind.setSequenceId(sequence);
    auditBind.setCreateTimestamp(getAttribute(le, CREATETIMESTAMP));
    auditBind.setCreatorsName(getAttribute(le, CREATORSNAME));
    auditBind.setEntryCSN(getAttribute(le, ENTRYCSN));
    auditBind.setEntryDN(getAttribute(le, ENTRYDN));
    auditBind.setEntryUUID(getAttribute(le, ENTRYUUID));
    auditBind.setHasSubordinates(getAttribute(le, HASSUBORDINATES));
    auditBind.setModifiersName(getAttribute(le, MODIFIERSNAME));
    auditBind.setModifyTimestamp(getAttribute(le, MODIFYTIMESTAMP));
    auditBind.setObjectClass(getAttribute(le, OBJECTCLASS));
    auditBind.setReqAuthzID(getAttribute(le, REQUAUTHZID));
    auditBind.setReqControls(getAttribute(le, REQCONTROLS));
    auditBind.setReqDN(getAttribute(le, REQDN));
    auditBind.setReqEnd(getAttribute(le, REQEND));
    auditBind.setReqMethod(getAttribute(le, REQMETHOD));
    auditBind.setReqResult(getAttribute(le, REQRESULT));
    auditBind.setReqSession(getAttribute(le, REQSESSION));
    auditBind.setReqStart(getAttribute(le, REQSTART));
    auditBind.setReqType(getAttribute(le, REQTYPE));
    auditBind.setReqVersion(getAttribute(le, REQVERSION));
    auditBind.setStructuralObjectClass(getAttribute(le, STRUCTURALOBJECTCLASS));
    return auditBind;
}
Also used : Bind(org.apache.directory.fortress.core.model.Bind) ObjectFactory(org.apache.directory.fortress.core.model.ObjectFactory)

Example 8 with Bind

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

the class AuditDAO method searchBinds.

/**
 * @param audit
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Bind> searchBinds(UserAudit audit) throws FinderException {
    List<Bind> auditList = new ArrayList<>();
    LdapConnection ld = null;
    String auditRoot = Config.getInstance().getProperty(AUDIT_ROOT);
    String userRoot = getRootDn(audit.getContextId(), GlobalIds.USER_ROOT);
    try {
        String filter;
        if (audit.getUserId() != null && audit.getUserId().length() > 0) {
            filter = GlobalIds.FILTER_PREFIX + ACCESS_BIND_CLASS_NM + ")(" + REQDN + "=" + SchemaConstants.UID_AT + "=" + audit.getUserId() + "," + userRoot + ")";
            if (audit.isFailedOnly()) {
                filter += "(" + REQRESULT + ">=" + 1 + ")";
            }
            if (audit.getBeginDate() != null) {
                String szTime = TUtil.encodeGeneralizedTime(audit.getBeginDate());
                filter += "(" + REQEND + ">=" + szTime + ")";
            }
            filter += ")";
        } else {
            filter = GlobalIds.FILTER_PREFIX + ACCESS_BIND_CLASS_NM + ")";
            if (audit.isFailedOnly()) {
                filter += "(" + REQRESULT + ">=" + 1 + ")";
            }
            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_BIND_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            auditList.add(getBindEntityFromLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (LdapException e) {
        String error = "LdapException in AuditDAO.searchBinds id=" + e.getMessage();
        throw new FinderException(GlobalErrIds.AUDT_BIND_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "CursorException in AuditDAO.searchBinds id=" + e.getMessage();
        throw new FinderException(GlobalErrIds.AUDT_BIND_SEARCH_FAILED, error, e);
    } finally {
        closeLogConnection(ld);
    }
    return auditList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) Bind(org.apache.directory.fortress.core.model.Bind) 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)

Aggregations

Bind (org.apache.directory.fortress.core.model.Bind)8 UserAudit (org.apache.directory.fortress.core.model.UserAudit)3 Date (java.util.Date)2 SecurityException (org.apache.directory.fortress.core.SecurityException)2 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 AuditMgr (org.apache.directory.fortress.core.AuditMgr)1 FinderException (org.apache.directory.fortress.core.FinderException)1 FortRequest (org.apache.directory.fortress.core.model.FortRequest)1 FortResponse (org.apache.directory.fortress.core.model.FortResponse)1 ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)1 User (org.apache.directory.fortress.core.model.User)1 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)1