use of org.apache.directory.fortress.core.model.PermObj in project directory-fortress-core by apache.
the class CreatePermSample method testAddShoppingCartObjects.
/**
*/
public static void testAddShoppingCartObjects() {
String szLocation = ".testAddShoppingCartObjects";
try {
// Instantiate the AdminMgr first
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
// Now Instantiate the Object
PermObj shoppingCart = new PermObj("ShoppingCart", "KillerBikes.com");
// Add it to the directory
adminMgr.addPermObj(shoppingCart);
// Now create the permission operations and grant...
Permission create = new Permission(shoppingCart.getObjName(), "create");
adminMgr.addPermission(create);
adminMgr.grantPermission(create, new Role("Customer"));
Permission read = new Permission(shoppingCart.getObjName(), "read");
adminMgr.addPermission(read);
adminMgr.grantPermission(read, new Role("Customer"));
Permission update = new Permission(shoppingCart.getObjName(), "update");
adminMgr.addPermission(update);
adminMgr.grantPermission(update, new Role("Admin"));
Permission delete = new Permission(shoppingCart.getObjName(), "delete");
adminMgr.addPermission(delete);
adminMgr.grantPermission(delete, new Role("Manager"));
Permission checkout = new Permission(shoppingCart.getObjName(), "checkout");
adminMgr.addPermission(checkout);
adminMgr.grantPermission(delete, new Role("Customer"));
} catch (SecurityException ex) {
LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.PermObj in project directory-fortress-core by apache.
the class AdminMgrConsole method addPermObject.
void addPermObject() {
PermObj pe = new PermObj();
try {
ReaderUtil.clearScreen();
System.out.println("Enter perm object name:");
pe.setObjName(ReaderUtil.readLn());
System.out.println("Enter Perm's description field");
pe.setDescription(ReaderUtil.readLn());
System.out.println("Enter organization unit, blank for default");
pe.setOu(ReaderUtil.readLn());
System.out.println("Enter prop key (or NULL to skip):");
String key = ReaderUtil.readLn();
for (int i = 0; key != null && key.length() > 0; i++) {
System.out.println("Enter prop val:");
String val = ReaderUtil.readLn();
pe.addProperty(key, val);
System.out.println("Enter next prop key (or NULL if done entering properties)");
key = ReaderUtil.readLn();
}
pe = am.addPermObj(pe);
System.out.println("perm object name [" + pe.getObjName() + "]");
System.out.println("internalId [" + pe.getInternalId() + "]");
System.out.println("description [" + pe.getDescription() + "]");
System.out.println("organizational unit [" + pe.getOu() + "]");
System.out.println("has been added");
System.out.println("ENTER to continue");
} catch (SecurityException e) {
LOG.error("addPermObject caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
}
ReaderUtil.readChar();
}
use of org.apache.directory.fortress.core.model.PermObj in project directory-fortress-core by apache.
the class ReviewMgrRestImpl method findPermObjs.
/**
* {@inheritDoc}
*/
@Override
public List<PermObj> findPermObjs(OrgUnit ou) throws SecurityException {
VUtil.assertNotNull(ou, GlobalErrIds.ORG_NULL_PERM, CLS_NM + ".findPermObjs");
List<PermObj> retObjs;
FortRequest request = new FortRequest();
request.setContextId(this.contextId);
PermObj inObj = new PermObj();
inObj.setOu(ou.getName());
request.setEntity(inObj);
if (this.adminSess != null) {
request.setSession(adminSess);
}
String szRequest = RestUtils.marshal(request);
String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.OBJ_SEARCH);
FortResponse response = RestUtils.unmarshall(szResponse);
if (response.getErrorCode() == 0) {
retObjs = response.getEntities();
} else {
throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
}
return retObjs;
}
use of org.apache.directory.fortress.core.model.PermObj in project directory-fortress-core by apache.
the class DelAdminMgrRestImpl method addPermObj.
/**
* {@inheritDoc}
*/
@Override
public PermObj addPermObj(PermObj pObj) throws SecurityException {
VUtil.assertNotNull(pObj, GlobalErrIds.PERM_OBJECT_NULL, CLS_NM + ".addPermObj");
PermObj retObj;
FortRequest request = new FortRequest();
request.setContextId(this.contextId);
pObj.setAdmin(true);
request.setEntity(pObj);
if (this.adminSess != null) {
request.setSession(adminSess);
}
String szRequest = RestUtils.marshal(request);
String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.OBJ_ADD);
FortResponse response = RestUtils.unmarshall(szResponse);
if (response.getErrorCode() == 0) {
retObj = (PermObj) response.getEntity();
} else {
throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
}
return retObj;
}
use of org.apache.directory.fortress.core.model.PermObj in project directory-fortress-core by apache.
the class AdminMgrRestImpl method addPermObj.
/**
* {@inheritDoc}
*/
@Override
public PermObj addPermObj(PermObj pObj) throws SecurityException {
VUtil.assertNotNull(pObj, GlobalErrIds.PERM_OBJECT_NULL, CLS_NM + ".addPermObj");
PermObj retObj;
FortRequest request = RestUtils.getRequest(this.contextId);
request.setEntity(pObj);
if (this.adminSess != null) {
request.setSession(adminSess);
}
String szRequest = RestUtils.marshal(request);
String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.OBJ_ADD);
FortResponse response = RestUtils.unmarshall(szResponse);
if (response.getErrorCode() == 0) {
retObj = (PermObj) response.getEntity();
} else {
throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
}
return retObj;
}
Aggregations