Search in sources :

Example 26 with PermObj

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());
    }
}
Also used : Role(org.apache.directory.fortress.core.model.Role) PermObj(org.apache.directory.fortress.core.model.PermObj) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 27 with PermObj

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();
}
Also used : PermObj(org.apache.directory.fortress.core.model.PermObj) Constraint(org.apache.directory.fortress.core.model.Constraint)

Example 28 with PermObj

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;
}
Also used : PermObj(org.apache.directory.fortress.core.model.PermObj) FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 29 with PermObj

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;
}
Also used : PermObj(org.apache.directory.fortress.core.model.PermObj) FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 30 with PermObj

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;
}
Also used : PermObj(org.apache.directory.fortress.core.model.PermObj) FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Aggregations

PermObj (org.apache.directory.fortress.core.model.PermObj)33 SecurityException (org.apache.directory.fortress.core.SecurityException)22 AdminMgr (org.apache.directory.fortress.core.AdminMgr)7 FortRequest (org.apache.directory.fortress.core.model.FortRequest)7 FortResponse (org.apache.directory.fortress.core.model.FortResponse)7 Permission (org.apache.directory.fortress.core.model.Permission)6 Role (org.apache.directory.fortress.core.model.Role)6 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)5 AdminRole (org.apache.directory.fortress.core.model.AdminRole)5 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)5 User (org.apache.directory.fortress.core.model.User)4 ArrayList (java.util.ArrayList)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)3 FinderException (org.apache.directory.fortress.core.FinderException)3 Relationship (org.apache.directory.fortress.core.model.Relationship)3 UserRole (org.apache.directory.fortress.core.model.UserRole)3 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)3 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)2 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)2 Constraint (org.apache.directory.fortress.core.model.Constraint)2