use of io.apiman.manager.api.rest.exceptions.UserNotFoundException in project apiman by apiman.
the class OrganizationResourceImpl method revokeAll.
/**
* @see IOrganizationResource#revokeAll(java.lang.String, java.lang.String)
*/
@Override
public void revokeAll(String organizationId, String userId) throws OrganizationNotFoundException, RoleNotFoundException, UserNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.orgAdmin, organizationId);
get(organizationId);
users.get(userId);
MembershipData auditData = new MembershipData();
auditData.setUserId(userId);
// $NON-NLS-1$
auditData.addRole("*");
try {
storage.beginTx();
storage.deleteMemberships(userId, organizationId);
storage.createAuditEntry(AuditUtils.membershipRevoked(organizationId, auditData, securityContext));
storage.commitTx();
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.UserNotFoundException in project apiman by apiman.
the class OrganizationResourceImpl method revoke.
/**
* @see IOrganizationResource#revoke(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public void revoke(String organizationId, String roleId, String userId) throws OrganizationNotFoundException, RoleNotFoundException, UserNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.orgAdmin, organizationId);
get(organizationId);
users.get(userId);
roles.get(roleId);
MembershipData auditData = new MembershipData();
auditData.setUserId(userId);
try {
storage.beginTx();
storage.deleteMembership(userId, roleId, organizationId);
auditData.addRole(roleId);
storage.createAuditEntry(AuditUtils.membershipRevoked(organizationId, auditData, securityContext));
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Revoked User %s Role %s Org %s", userId, roleId, organizationId));
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.UserNotFoundException in project apiman by apiman.
the class OrganizationResourceImpl method grant.
/**
* @see IOrganizationResource#grant(java.lang.String, io.apiman.manager.api.beans.idm.GrantRolesBean)
*/
@Override
public void grant(String organizationId, GrantRolesBean bean) throws OrganizationNotFoundException, RoleNotFoundException, UserNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.orgAdmin, organizationId);
// Verify that the references are valid.
get(organizationId);
users.get(bean.getUserId());
for (String roleId : bean.getRoleIds()) {
roles.get(roleId);
}
MembershipData auditData = new MembershipData();
auditData.setUserId(bean.getUserId());
try {
storage.beginTx();
for (String roleId : bean.getRoleIds()) {
RoleMembershipBean membership = RoleMembershipBean.create(bean.getUserId(), roleId, organizationId);
membership.setCreatedOn(new Date());
// If the membership already exists, that's fine!
if (storage.getMembership(bean.getUserId(), roleId, organizationId) == null) {
storage.createMembership(membership);
}
auditData.addRole(roleId);
}
storage.createAuditEntry(AuditUtils.membershipGranted(organizationId, auditData, securityContext));
storage.commitTx();
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
Aggregations