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