Search in sources :

Example 6 with PermGrant

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

the class AdminMgrRestImpl method grantPermission.

/**
 * {@inheritDoc}
 */
@Override
public void grantPermission(Permission perm, Role role) throws SecurityException {
    VUtil.assertNotNull(perm, GlobalErrIds.PERM_OPERATION_NULL, CLS_NM + ".grantPermission");
    VUtil.assertNotNull(role, GlobalErrIds.ROLE_NULL, CLS_NM + ".grantPermission");
    FortRequest request = RestUtils.getRequest(this.contextId);
    PermGrant permGrant = new PermGrant();
    permGrant.setAdmin(perm.isAdmin());
    permGrant.setObjName(perm.getObjName());
    permGrant.setObjId(perm.getObjId());
    permGrant.setOpName(perm.getOpName());
    permGrant.setRoleNm(role.getName());
    request.setEntity(permGrant);
    if (this.adminSess != null) {
        request.setSession(adminSess);
    }
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.ROLE_GRANT);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() != 0) {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
}
Also used : PermGrant(org.apache.directory.fortress.core.model.PermGrant) FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 7 with PermGrant

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

the class FortressAntLoadTest method permissionRoles.

private static void permissionRoles(String msg, List<PermGrant> permGrants) {
    LogUtil.logIt(msg);
    Permission pOp;
    try {
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        for (PermGrant permGrant : permGrants) {
            pOp = new Permission();
            pOp.setObjName(permGrant.getObjName());
            pOp.setOpName(permGrant.getOpName());
            pOp.setObjId(permGrant.getObjId());
            List<String> roles = reviewMgr.permissionRoles(pOp);
            assertNotNull(roles);
            int indx = roles.indexOf(permGrant.getRoleNm());
            assertTrue("Failed to find roleNm: " + permGrant.getRoleNm(), indx != -1);
        }
    } catch (SecurityException ex) {
        LOG.error("permissionRoles caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : PermGrant(org.apache.directory.fortress.core.model.PermGrant) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 8 with PermGrant

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

the class FortressAntLoadTest method testPermissionRoles.

@Test
public void testPermissionRoles() {
    // gather permission to role grant input data:
    List<AddpermGrant> addpermGrants = fortressAntTask.getAddpermGrants();
    for (AddpermGrant addpermGrant : addpermGrants) {
        List<PermGrant> permGrants = addpermGrant.getPermGrants();
        permissionRoles("PRM-RLS", permGrants);
    }
}
Also used : PermGrant(org.apache.directory.fortress.core.model.PermGrant) AddpermGrant(org.apache.directory.fortress.core.ant.AddpermGrant) Test(org.junit.Test)

Example 9 with PermGrant

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

the class DelAdminMgrRestImpl method revokePermission.

/**
 * {@inheritDoc}
 */
@Override
public void revokePermission(Permission perm, User user) throws SecurityException {
    VUtil.assertNotNull(perm, GlobalErrIds.PERM_OPERATION_NULL, CLS_NM + ".revokePermission");
    VUtil.assertNotNull(user, GlobalErrIds.USER_NULL, CLS_NM + ".revokePermission");
    FortRequest request = new FortRequest();
    request.setContextId(this.contextId);
    PermGrant permGrant = new PermGrant();
    permGrant.setAdmin(true);
    permGrant.setObjName(perm.getObjName());
    permGrant.setObjId(perm.getObjId());
    permGrant.setOpName(perm.getOpName());
    permGrant.setUserId(user.getUserId());
    request.setEntity(permGrant);
    if (this.adminSess != null) {
        request.setSession(adminSess);
    }
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.USER_REVOKE);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() != 0) {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
}
Also used : PermGrant(org.apache.directory.fortress.core.model.PermGrant) FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 10 with PermGrant

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

the class DelAdminMgrRestImpl method revokePermission.

/**
 * {@inheritDoc}
 */
@Override
public void revokePermission(Permission perm, AdminRole role) throws SecurityException {
    VUtil.assertNotNull(perm, GlobalErrIds.PERM_OPERATION_NULL, CLS_NM + ".revokePermission");
    VUtil.assertNotNull(role, GlobalErrIds.ROLE_NULL, CLS_NM + ".revokePermission");
    FortRequest request = new FortRequest();
    request.setContextId(this.contextId);
    PermGrant permGrant = new PermGrant();
    permGrant.setAdmin(true);
    permGrant.setObjName(perm.getObjName());
    permGrant.setObjId(perm.getObjId());
    permGrant.setOpName(perm.getOpName());
    permGrant.setRoleNm(role.getName());
    request.setEntity(permGrant);
    if (this.adminSess != null) {
        request.setSession(adminSess);
    }
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.ROLE_REVOKE);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() != 0) {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
}
Also used : PermGrant(org.apache.directory.fortress.core.model.PermGrant) FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Aggregations

PermGrant (org.apache.directory.fortress.core.model.PermGrant)12 SecurityException (org.apache.directory.fortress.core.SecurityException)11 FortRequest (org.apache.directory.fortress.core.model.FortRequest)8 FortResponse (org.apache.directory.fortress.core.model.FortResponse)8 Permission (org.apache.directory.fortress.core.model.Permission)3 AdminRole (org.apache.directory.fortress.core.model.AdminRole)2 Role (org.apache.directory.fortress.core.model.Role)2 User (org.apache.directory.fortress.core.model.User)2 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)2 UserRole (org.apache.directory.fortress.core.model.UserRole)2 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)1 AddpermGrant (org.apache.directory.fortress.core.ant.AddpermGrant)1 Test (org.junit.Test)1