use of com.webank.wedatasphere.qualitis.entity.Permission in project Qualitis by WeBankFinTech.
the class UserSpecPermissionDaoTest method savePermission.
private Permission savePermission() {
// 保存是否成功
Permission entity = new Permission();
entity.setUrl("/junit/**");
entity.setMethod("GET");
Permission saveEntity = permissionDao.savePermission(entity);
assertTrue(saveEntity.getId() != 0);
return saveEntity;
}
use of com.webank.wedatasphere.qualitis.entity.Permission in project Qualitis by WeBankFinTech.
the class UserSpecPermissionDaoTest method test.
@Test
@Transactional
public void test() {
Permission savePermission = savePermission();
User saveUser = saveUser();
// 保存是否成功
UserSpecPermission entity = new UserSpecPermission();
entity.setId(UuidGenerator.generate());
entity.setPermission(savePermission);
entity.setUser(saveUser);
UserSpecPermission saveEntity = dao.saveUserSpecPermission(entity);
assertNotNull(saveEntity.getId());
// 总数量大于0
long size = dao.countAll();
assertTrue(size > 0);
// 分页查询有结果
List<UserSpecPermission> datas = dao.findAllUserSpecPermission(0, 5);
assertTrue(datas.size() > 0);
// 保存到数据库的对象是否和保存的值一致
UserSpecPermission findByIdEntity = dao.findByUuid(saveEntity.getId());
assertNotNull(findByIdEntity);
assertEquals(findByIdEntity.getPermission().getUrl(), saveEntity.getPermission().getUrl());
assertEquals(findByIdEntity.getUser().getUserName(), saveEntity.getUser().getUserName());
UserSpecPermission findByRoleAndPermissionEntity = dao.findByUserAndPermission(saveUser, savePermission);
assertNotNull(findByRoleAndPermissionEntity);
assertEquals(findByRoleAndPermissionEntity.getPermission().getUrl(), saveEntity.getPermission().getUrl());
assertEquals(findByRoleAndPermissionEntity.getUser().getUserName(), saveEntity.getUser().getUserName());
// 根据username查询的数据库对象是否和保存的值一致
List<UserSpecPermission> findByRoleEntity = dao.findByUser(saveUser);
assertTrue(findByRoleEntity.size() > 0);
assertEquals(findByRoleEntity.get(0).getPermission().getUrl(), saveEntity.getPermission().getUrl());
// 根据username查询的数据库对象是否和保存的值一致
List<UserSpecPermission> findByPermissionEntity = dao.findByPermission(savePermission);
assertTrue(findByPermissionEntity.size() > 0);
assertEquals(findByPermissionEntity.get(0).getUser().getUserName(), saveEntity.getUser().getUserName());
// 删除后,是否还能找到对象
dao.deleteUserSpecPermission(saveEntity);
UserSpecPermission deleteEntity = dao.findByUuid(saveEntity.getId());
assertNull(deleteEntity);
}
use of com.webank.wedatasphere.qualitis.entity.Permission in project Qualitis by WeBankFinTech.
the class PermissionServiceImpl method addPermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<PermissionResponse> addPermission(AddPermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
AddPermissionRequest.checkRequest(request);
String method = request.getMethod().trim();
String url = request.getUrl().trim();
// Find permission by method and url
Permission permissionInDb = permissionDao.findByMethodAndUrl(method, url);
if (permissionInDb != null) {
throw new UnExpectedRequestException("{&METHOD_AND_URL_ALREADY_EXIST}, request: " + request);
}
Permission newPermission = new Permission();
newPermission.setMethod(method);
newPermission.setUrl(url);
Permission savedPermission = permissionDao.savePermission(newPermission);
LOGGER.info("Succeed to add permission, id: {}, method: {}, url: {}, current_user: {}", savedPermission.getId(), method, url, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&ADD_PERMISSION_SUCCESSFULLY}", new PermissionResponse(savedPermission));
}
use of com.webank.wedatasphere.qualitis.entity.Permission in project Qualitis by WeBankFinTech.
the class PermissionServiceImpl method deletePermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deletePermission(DeletePermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
Long permissionId = request.getPermissionId();
// Find permissions by permission id
Permission permissionInDb = permissionDao.findById(permissionId);
if (permissionInDb == null) {
throw new UnExpectedRequestException("{&PERMISSION_ID_NOT_EXIST}, request: " + request);
}
List<RolePermission> rolePermissionsInDb = rolePermissionDao.findByPermission(permissionInDb);
if (null != rolePermissionsInDb && !rolePermissionsInDb.isEmpty()) {
throw new UnExpectedRequestException("{&DELETE_ERROR_ROLE_PERMISSION_HAS_FOREIGN_KEY}");
}
List<UserSpecPermission> userSpecPermissionsInDb = userSpecPermissionDao.findByPermission(permissionInDb);
if (null != userSpecPermissionsInDb && !userSpecPermissionsInDb.isEmpty()) {
throw new UnExpectedRequestException("{&DELETE_ERROR_USER_SPEC_PERMISSION_HAS_FOREIGN_KEY}");
}
permissionDao.deletePermission(permissionInDb);
LOGGER.info("Succeed to delete permission, permissionId: {}, method: {}, url: {}, current_user: {}", permissionId, permissionInDb.getMethod(), permissionInDb.getUrl(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&DELETE_PERMISSION_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.entity.Permission in project Qualitis by WeBankFinTech.
the class RolePermissionServiceImpl method modifyRolePermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyRolePermission(ModifyRolePermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of role permission
String uuid = request.getUuid();
RolePermission rolePermissionInDb = rolePermissionDao.findByUuid(uuid);
if (rolePermissionInDb == null) {
throw new UnExpectedRequestException("role permission id {&DOES_NOT_EXIST}, request: " + request);
}
LOGGER.info("Succeed to find role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, rolePermissionInDb.getRole().getId(), rolePermissionInDb.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
long roleId = request.getRoleId();
long permissionId = request.getPermissionId();
Role roleInDb = roleDao.findById(roleId);
if (roleInDb == null) {
throw new UnExpectedRequestException("role id {&DOES_NOT_EXIST}, request: " + request);
}
Permission permissionInDb = permissionDao.findById(permissionId);
if (permissionInDb == null) {
throw new UnExpectedRequestException("permission id {&DOES_NOT_EXIST}, request: " + request);
}
RolePermission roleIdAndPermissionIdInDb = rolePermissionDao.findByRoleAndPermission(roleInDb, permissionInDb);
if (roleIdAndPermissionIdInDb != null) {
throw new UnExpectedRequestException("role and permission {&ALREADY_EXIST}, request: " + request);
}
// Save role permission
rolePermissionInDb.setRole(roleInDb);
rolePermissionInDb.setPermission(permissionInDb);
RolePermission savedRolePermission = rolePermissionDao.saveRolePermission(rolePermissionInDb);
LOGGER.info("Succeed to modify role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, savedRolePermission.getRole().getId(), savedRolePermission.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&MODIFY_ROLE_PERMISSION_SUCCESSFULLY}", null);
}
Aggregations