use of org.apache.directory.fortress.core.model.PermGrant in project directory-fortress-core by apache.
the class FortressAntTask method deletePermGrants.
/**
* @throws BuildException An error occurred while building
*/
private void deletePermGrants() throws BuildException {
if (delpermGrants == null) {
return;
}
// Loop through the entityclass elements
for (DelpermGrant delpermGrant : delpermGrants) {
List<PermGrant> permGrants = delpermGrant.getPermGrants();
for (PermGrant permGrant : permGrants) {
try {
Permission perm = new Permission(permGrant.getObjName(), permGrant.getOpName(), permGrant.isAdmin());
perm.setOpName(permGrant.getOpName());
perm.setObjId(permGrant.getObjId());
if (permGrant.getRoleNm() != null && permGrant.getRoleNm().length() > 0) {
LOG.info("deletePermGrants tenant={} roleName={} objName={} opName={} objId={}", getTenant(), permGrant.getRoleNm(), permGrant.getObjName(), permGrant.getOpName(), permGrant.getObjId());
adminMgr.revokePermission(perm, new Role(permGrant.getRoleNm()));
} else if (permGrant.getUserId() != null && permGrant.getUserId().length() > 0) {
LOG.info("deletePermGrants tenant={} userId={} objName={} opName={} objId={}", getTenant(), permGrant.getUserId(), permGrant.getObjName(), permGrant.getOpName(), permGrant.getObjId());
adminMgr.revokePermission(perm, new User(permGrant.getUserId()));
} else {
String warning = "deletePermGrants called without user or role set in xml";
LOG.warn(warning);
}
} catch (SecurityException se) {
LOG.warn("deletePermGrants tenant={} roleName={} objName={} opName={} objId={} caught SecurityException={}", getTenant(), permGrant.getRoleNm(), permGrant.getObjName(), permGrant.getOpName(), permGrant.getObjId(), se);
}
}
}
}
use of org.apache.directory.fortress.core.model.PermGrant in project directory-fortress-core by apache.
the class FortressAntTask method addPermGrants.
/**
* @throws BuildException An error occurred while building
*/
private void addPermGrants() throws BuildException {
if (addpermGrants == null) {
return;
}
// Loop through the entityclass elements
for (AddpermGrant addpermGrant : addpermGrants) {
List<PermGrant> permGrants = addpermGrant.getPermGrants();
for (PermGrant permGrant : permGrants) {
try {
Permission perm = new Permission(permGrant.getObjName(), permGrant.getOpName(), permGrant.isAdmin());
perm.setOpName(permGrant.getOpName());
perm.setObjId(permGrant.getObjId());
if (permGrant.getRoleNm() != null && permGrant.getRoleNm().length() > 0) {
LOG.info("addPermGrants tenant={} roleName={} objName={} opName={} objId={}", getTenant(), permGrant.getRoleNm(), permGrant.getObjName(), permGrant.getOpName(), permGrant.getObjId());
adminMgr.grantPermission(perm, new Role(permGrant.getRoleNm()));
} else if (permGrant.getUserId() != null && permGrant.getUserId().length() > 0) {
LOG.info("addPermGrants tenant={} userId={} objName={} opName={} objId={}", getTenant(), permGrant.getUserId(), permGrant.getObjName(), permGrant.getOpName(), permGrant.getObjId());
adminMgr.grantPermission(perm, new User(permGrant.getUserId()));
} else {
String warning = "addPermGrants called without user or role set in xml";
LOG.warn(warning);
}
} catch (SecurityException se) {
LOG.warn("addPermGrants tenant={} roleName={} objName={} opName={} objId={} caught SecurityException={}", getTenant(), permGrant.getRoleNm(), permGrant.getObjName(), permGrant.getOpName(), permGrant.getObjId(), se);
}
}
}
}
use of org.apache.directory.fortress.core.model.PermGrant in project directory-fortress-core by apache.
the class DelAdminMgrRestImpl method grantPermission.
/**
* {@inheritDoc}
*/
@Override
public void grantPermission(Permission perm, AdminRole role) throws SecurityException {
VUtil.assertNotNull(perm, GlobalErrIds.PERM_OPERATION_NULL, CLS_NM + ".grantPermission");
VUtil.assertNotNull(role, GlobalErrIds.ROLE_NULL, CLS_NM + ".grantPermission");
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_GRANT);
FortResponse response = RestUtils.unmarshall(szResponse);
if (response.getErrorCode() != 0) {
throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
}
}
use of org.apache.directory.fortress.core.model.PermGrant in project directory-fortress-core by apache.
the class DelAdminMgrRestImpl method grantPermission.
/**
* {@inheritDoc}
*/
@Override
public void grantPermission(Permission perm, User user) throws SecurityException {
VUtil.assertNotNull(perm, GlobalErrIds.PERM_OPERATION_NULL, CLS_NM + ".grantPermissionUser");
VUtil.assertNotNull(user, GlobalErrIds.USER_NULL, CLS_NM + ".grantPermissionUser");
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_GRANT);
FortResponse response = RestUtils.unmarshall(szResponse);
if (response.getErrorCode() != 0) {
throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
}
}
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, User user) throws SecurityException {
VUtil.assertNotNull(perm, GlobalErrIds.PERM_OPERATION_NULL, CLS_NM + ".grantPermissionUser");
VUtil.assertNotNull(user, GlobalErrIds.USER_NULL, CLS_NM + ".grantPermissionUser");
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.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_GRANT);
FortResponse response = RestUtils.unmarshall(szResponse);
if (response.getErrorCode() != 0) {
throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
}
}
Aggregations