use of org.apache.directory.fortress.core.ant.UserAnt in project directory-fortress-core by apache.
the class FortressAntLoadTest method testReadUser.
@Test
public void testReadUser() {
// gather user input data:
List<Adduser> addusers = fortressAntTask.getAddusers();
for (Adduser adduser : addusers) {
List<UserAnt> users = adduser.getUsers();
readUsers("READ-USRS", users);
}
}
use of org.apache.directory.fortress.core.ant.UserAnt in project directory-fortress-core by apache.
the class FortressAntLoadTest method checkPermissions.
/**
* @param msg
* @param permissions
*/
private void checkPermissions(String msg, List<UserAnt> users, List<PermAnt> permissions) {
String DATE_FORMAT = "E yyyy.MM.dd 'at' hh:mm:ss a zzz";
SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
Date now = new Date();
String szTimestamp = format.format(now);
AccessMgr accessMgr = null;
CSVWriter writer = null;
LogUtil.logIt(msg);
try {
accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
writer = new CSVWriter(new FileWriter(fileName + ".csv"), '\t');
String[] entries = "user#resource#operation#result#assigned roles#activated roles#timestamp#warnings".split("#");
writer.writeNext(entries);
} catch (SecurityException ex) {
LOG.error("checkPermissions caught SecurityException creating AccessMgr rc=" + ex.getErrorId() + ", " + "msg=" + ex.getMessage() + ex);
// Can't continue without AccessMgr
fail(ex.getMessage());
} catch (IOException ioe) {
String error = "File IO Exception=" + ioe;
LOG.warn(error);
// Can't continue without output file to write the results in
fail(ioe.getMessage());
}
for (UserAnt user : users) {
try {
List<String> warnings = null;
Session session = accessMgr.createSession(user, false);
assertNotNull(session);
if (session.getWarnings() != null) {
warnings = new ArrayList();
for (Warning warning : session.getWarnings()) {
warnings.add(warning.getMsg());
}
}
ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
List<UserRole> assignedRoles = reviewMgr.assignedRoles(user);
for (PermAnt permAnt : permissions) {
Boolean result = accessMgr.checkAccess(session, permAnt);
// TODO: send this message as CSV output file:
LOG.info("User: " + user.getUserId() + " Perm Obj: " + permAnt.getObjName() + " Perm " + "Operation: " + permAnt.getOpName() + " RESULT: " + result);
String[] entries = (user.getUserId() + "#" + permAnt.getObjName() + "#" + permAnt.getOpName() + "#" + result + "#" + assignedRoles + "#" + session.getUser().getRoles() + "#" + szTimestamp + "#" + warnings).split("#");
writer.writeNext(entries);
}
} catch (SecurityException ex) {
// Log but don't fail test so entire permission matrix can be evaluated.
LOG.error("checkPermissions caught SecurityException rc=" + ex.getErrorId() + ", " + "msg=" + ex.getMessage() + ex);
}
}
try {
writer.close();
} catch (IOException ioe) {
// ignore
}
}
Aggregations