Search in sources :

Example 66 with ReviewMgr

use of org.apache.directory.fortress.core.ReviewMgr in project directory-fortress-core by apache.

the class ReviewMgrImplTest method readUsers.

/**
 * @param msg
 * @param uArray
 */
public static void readUsers(String msg, String[][] uArray) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] usr : uArray) {
            User entity = reviewMgr.readUser(new User(UserTestData.getUserId(usr)));
            assertNotNull(entity);
            UserTestData.assertEquals(entity, usr);
            LOG.debug("readUsers userId [" + entity.getUserId() + "] successful");
        }
    } catch (SecurityException ex) {
        LOG.error("readUsers caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 67 with ReviewMgr

use of org.apache.directory.fortress.core.ReviewMgr in project directory-fortress-core by apache.

the class ReviewMgrImplTest method readPermissionOps.

/**
 * @param msg
 * @param pObjArray
 * @param pOpArray
 */
public static void readPermissionOps(String msg, String[][] pObjArray, String[][] pOpArray) {
    Permission pOp = new Permission();
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] objs : pObjArray) {
            for (String[] ops : pOpArray) {
                pOp = new Permission();
                pOp.setObjName(PermTestData.getName(objs));
                pOp.setOpName(PermTestData.getName(ops));
                pOp.setObjId(PermTestData.getObjId(ops));
                Permission entity = reviewMgr.readPermission(pOp);
                assertNotNull(entity);
                PermTestData.assertEquals(PermTestData.getName(objs), entity, ops);
                LOG.debug("readPermissionOps object name [" + pOp.getObjName() + "] operation name [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] successful");
            }
        }
    } catch (SecurityException ex) {
        LOG.error("readPermissionOps object name [" + pOp.getObjName() + "] operation name [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage() + ex);
        fail(ex.getMessage());
    }
}
Also used : ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 68 with ReviewMgr

use of org.apache.directory.fortress.core.ReviewMgr in project directory-fortress-core by apache.

the class CreateRoleSample method testDeleteRoles.

/**
 * Remove the Role from the directory.  Role removal will trigger automatic deassignment from all Users or revocation of Permission as well.
 */
public static void testDeleteRoles() {
    String szLocation = ".testDeleteRoles";
    if (AllSamplesJUnitTest.isFirstRun()) {
        return;
    }
    try {
        // Instantiate the AdminMgr implementation which is used to provision RBAC policies.
        AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
        for (int i = 1; i < 11; i++) {
            // The key that must be set to locate any Role is simply the name.
            Role inRole = new Role(TEST_ROLE_PREFIX + i);
            // Remove the Role from directory along with associated assignments:
            adminMgr.deleteRole(inRole);
            // Instantiate the ReviewMgr implementation which is used to interrogate RBAC policy information.
            ReviewMgr reviewMgr = ReviewMgrFactory.createInstance(TestUtils.getContext());
            try {
                // this should fail because the Role was deleted above:
                reviewMgr.readRole(inRole);
                fail(szLocation + " role [" + inRole.getName() + "] delete failed");
            } catch (FinderException se) {
                assertTrue(szLocation + " excep id check", se.getErrorId() == GlobalErrIds.ROLE_NOT_FOUND);
            // pass
            }
            LOG.info(szLocation + " role [" + inRole.getName() + "] success");
        }
    } 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) FinderException(org.apache.directory.fortress.core.FinderException) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 69 with ReviewMgr

use of org.apache.directory.fortress.core.ReviewMgr in project directory-fortress-core by apache.

the class CreateUserSample method testCreateUser.

/**
 * Demonstrate how to create a simple user and assign to a single RBAC Role in one API call.  The example will
 * also read the User back from LDAP after creation but this is not required for real world examples.
 */
public static void testCreateUser() {
    String szLocation = ".testCreateUser";
    try {
        // Instantiate the AdminMgr implementation.  All AdminMgr APIs can throw a SecurityException in the event
        // of rule violation or system error.
        AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
        // You do not have to assign a Role to User when calling 'addUser'.  Role assignment may be done using the 'assignUser' API.
        /**
         * Create new User entity:
         *   {@link org.apache.directory.fortress.core.model.User#userId}="sampleUser1"
         *   {@link User#password}="password1"
         *   {@link User#setRole(String)}="sampleRole1"
         *   {@link User#ou}="sampleUserOU1"
         */
        // User inUser = new User(TEST_USERID, TEST_PASSWORD, CreateRoleSample.TEST_SIMPLE_ROLE, CreateUserOrgSample.TEST_USER_OU_NM);
        // User inUser = new User(TEST_USERID, TEST_PASSWORD, CreateRoleSample.TEST_SIMPLE_ROLE, CreateUserOrgSample.TEST_USER_OU_NM);
        User inUser = new User(TEST_USERID, TEST_PASSWORD);
        inUser.setOu(CreateUserOrgSample.TEST_USER_OU_NM);
        // Now call the add API.  The API will return User entity with associated LDAP dn if creation was successful.
        User outUser = adminMgr.addUser(inUser);
        assertNotNull(outUser);
        // Instantiate the ReviewMgr implementation which is used to interrogate policy information.
        ReviewMgr reviewMgr = ReviewMgrFactory.createInstance(TestUtils.getContext());
        // now read the newly created User entity back:
        User outUser2 = reviewMgr.readUser(inUser);
        assertTrue(szLocation + " failed read", inUser.equals(outUser2));
        LOG.info(szLocation + " user [" + outUser2.getUserId() + "] success");
    } catch (SecurityException ex) {
        LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 70 with ReviewMgr

use of org.apache.directory.fortress.core.ReviewMgr in project directory-fortress-core by apache.

the class LoadTestUserSample method teardownRequired.

/**
 * Determines if teardown needs to occur on sample data.
 *
 * @return true if teardown is required
 */
static boolean teardownRequired() {
    // The default for this check is 'true'
    boolean tearDown = true;
    String methodName = ".teardownRequired";
    try {
        ReviewMgr reviewMgr = ReviewMgrFactory.createInstance(TestUtils.getContext());
        User inUser = new User(TEST_USERID + 1, TEST_PASSWORD);
        reviewMgr.readUser(inUser);
    // If we get here, the sample data needs to be removed:
    } catch (SecurityException ex) {
        if (ex.getErrorId() == GlobalErrIds.USER_NOT_FOUND) {
            // If we get here the sample data does not need to be removed:
            tearDown = false;
        } else {
            String warning = methodName + " caught SecurityException=" + ex.getMessage();
            LOG.warn(warning);
        }
    }
    LOG.info(methodName + ":" + tearDown);
    return tearDown;
}
Also used : User(org.apache.directory.fortress.core.model.User) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException)

Aggregations

ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)75 SecurityException (org.apache.directory.fortress.core.SecurityException)65 UserRole (org.apache.directory.fortress.core.model.UserRole)32 User (org.apache.directory.fortress.core.model.User)31 Role (org.apache.directory.fortress.core.model.Role)30 AdminMgr (org.apache.directory.fortress.core.AdminMgr)27 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)22 Permission (org.apache.directory.fortress.core.model.Permission)16 SDSet (org.apache.directory.fortress.core.model.SDSet)8 PermObj (org.apache.directory.fortress.core.model.PermObj)5 ArrayList (java.util.ArrayList)3 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)3 PermAnt (org.apache.directory.fortress.core.ant.PermAnt)2 CSVWriter (au.com.bytecode.opencsv.CSVWriter)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Map (java.util.Map)1 AccessMgr (org.apache.directory.fortress.core.AccessMgr)1