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;
}
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;
}
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");
}
}
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());
}
}
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());
}
}
Aggregations