use of org.mx.comps.rbac.dal.entity.Accredit in project main by JohnPeng739.
the class AccreditManageResource method deleteAccredit.
@Path("accredits/{id}")
@DELETE
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<AccreditVO> deleteAccredit(@QueryParam("userCode") String userCode, @PathParam("id") String id) {
if (StringUtils.isBlank(userCode) || StringUtils.isBlank(id)) {
return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM));
}
sessionDataStore.setCurrentUserCode(userCode);
try {
Accredit accredit = accreditManageService.closeAccredit(id);
AccreditVO vo = AccreditVO.transform(accredit, true);
sessionDataStore.removeCurrentUserCode();
return new DataVO<>(vo);
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Delete accredit fail.", ex);
}
return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.comps.rbac.dal.entity.Accredit in project main by JohnPeng739.
the class AccreditManageResource method accredits.
@Path("accredits")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<AccreditVO>> accredits(Pagination pagination) {
if (pagination == null) {
pagination = new Pagination();
}
try {
List<Accredit> accredits = accessor.list(pagination, Accredit.class);
List<AccreditVO> list = AccreditVO.transform(accredits);
return new PaginationDataVO<>(pagination, list);
} catch (UserInterfaceException ex) {
return new PaginationDataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("List accredits fail.", ex);
}
return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.comps.rbac.dal.entity.Accredit in project main by JohnPeng739.
the class AccreditManageResource method newAccredit.
@Path("accredits/new")
@POST
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<AccreditVO> newAccredit(@QueryParam("userCode") String userCode, AccreditInfoVO accreditInfoVO) {
sessionDataStore.setCurrentUserCode(userCode);
try {
Accredit accredit = accreditManageService.accredit(accreditInfoVO.getAccreditInfo());
AccreditVO vo = AccreditVO.transform(accredit, true);
sessionDataStore.removeCurrentUserCode();
return new DataVO<>(vo);
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Create accredit fail.", ex);
}
return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.comps.rbac.dal.entity.Accredit in project main by JohnPeng739.
the class AccreditManageServiceCommonImpl method accredit.
/**
* {@inheritDoc}
*
* @see AccreditManageService#accredit(AccreditInfo)
*/
@Override
public Accredit accredit(AccreditInfo accreditInfo) {
if (accreditInfo == null || StringUtils.isBlank(accreditInfo.getSrcAccountId()) || StringUtils.isBlank(accreditInfo.getTarAccountId()) || accreditInfo.getRoleIds() == null || accreditInfo.getRoleIds().isEmpty()) {
throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
}
// 判断是否存在相同的有效授权
if (hasSameAccredit(accreditInfo)) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCREDIT_SAME_FOUND);
}
Account src = accessor.getById(accreditInfo.getSrcAccountId(), Account.class);
if (src == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOT_FOUND);
}
Account tar = accessor.getById(accreditInfo.getTarAccountId(), Account.class);
if (tar == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOT_FOUND);
}
Set<Role> roles = new HashSet<>();
for (String roleId : accreditInfo.getRoleIds()) {
Role role = accessor.getById(roleId, Role.class);
if (role == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ROLE_NOT_FOUND);
}
roles.add(role);
}
Accredit accredit = EntityFactory.createEntity(Accredit.class);
accredit.setSrc(src);
accredit.setTar(tar);
accredit.setRoles(roles);
accredit.setStartTime(new Date(accreditInfo.getStartTime()));
if (accreditInfo.getEndTime() > 0 && accreditInfo.getEndTime() > accreditInfo.getStartTime()) {
accredit.setEndTime(new Date(accreditInfo.getEndTime()));
}
accredit.setValid(true);
accredit.setDesc(accreditInfo.getDesc());
accredit = this.save(accredit);
if (operateLogService != null) {
operateLogService.writeLog(String.format("新增授权[%s=>%s]成功。", accredit.getSrc().getName(), accredit.getTar().getName()));
}
return accredit;
}
use of org.mx.comps.rbac.dal.entity.Accredit in project main by JohnPeng739.
the class AccreditManageServiceImpl method hasSameAccredit.
/**
* {@inheritDoc}
*
* @see AccreditManageServiceCommonImpl#hasSameAccredit(AccreditInfo)
*/
@Override
protected boolean hasSameAccredit(AccreditInfo accreditInfo) {
List<GeneralAccessor.ConditionTuple> conditions = new ArrayList<>();
conditions.add(new GeneralAccessor.ConditionTuple("src", accessor.getById(accreditInfo.getSrcAccountId(), Account.class)));
conditions.add(new GeneralAccessor.ConditionTuple("tar", accessor.getById(accreditInfo.getTarAccountId(), Account.class)));
conditions.add(new GeneralAccessor.ConditionTuple("valid", true));
List<Accredit> list = accessor.find(conditions, Accredit.class);
List<Accredit> accredits = new ArrayList<>();
if (list != null && !list.isEmpty()) {
list.forEach(accredit -> {
if (!accredit.isClosed()) {
accredits.add(accredit);
}
});
}
if (accredits.isEmpty()) {
return false;
}
for (Accredit accredit : accredits) {
if (!accredit.isClosed()) {
for (String roleId : accreditInfo.getRoleIds()) {
boolean found = false;
for (Role role : accredit.getRoles()) {
if (roleId.equals(role.getId())) {
found = true;
}
}
if (!found) {
return false;
}
}
}
}
return true;
}
Aggregations