@Override public String getMessage() { String message = null; if (!StringUtils.isEmpty(code)) { message = MessageUtils.message(code, args); } if (message == null) { message = defaultMessage; } return message; }
public void assertHasPermission(String permission, String errorCode) { if (StringUtils.isEmpty(errorCode)) { errorCode = getDefaultErrorCode(); } String resourcePermission = resourcePermissions.get(permission); if (resourcePermission == null) { resourcePermission = this.resourceIdentity + ":" + permission; } if (!SecurityUtils.getSubject().isPermitted(resourcePermission)) { throw new UnauthorizedException(MessageUtils.message(errorCode, resourcePermission)); } }
public void assertHasAllPermission(String[] permissions, String errorCode) { if (StringUtils.isEmpty(errorCode)) { errorCode = getDefaultErrorCode(); } if (permissions == null || permissions.length == 0) { throw new UnauthorizedException( MessageUtils.message(errorCode, resourceIdentity + ":" + Arrays.toString(permissions))); } Subject subject = SecurityUtils.getSubject(); for (String permission : permissions) { String resourcePermission = resourcePermissions.get(permission); if (resourcePermission == null) { resourcePermission = this.resourceIdentity + ":" + permission; } if (!subject.isPermitted(resourcePermission)) { throw new UnauthorizedException( MessageUtils.message(errorCode, resourceIdentity + ":" + Arrays.toString(permissions))); } } }