我想在每个方法执行之前检查服务类中的用户权限。这是我目前的做法:
appContext.xml:
<bean id="requestSeviceImpl" class="services.impl.RequestSeviceImpl">
<property name="permissionService" ref="permissionServiceImpl" />
...
</bean>
执行:
public class RequestServiceImpl implements RequestService
{
private PermissionService permissionService;
...
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
@Override
@Transactional
public RequestResultModel submitRequest(Request request)
{
if(permissionService.isCurrentUserAuthorized(request,"submit"))
{
//submit request
}
//throw a permission exception
}
@Override
@Transactional
public void sendRequest(Request request)
{
if(permissionService.isCurrentUserAuthorized(request,"send"))
{
//send request
}
//throw a permission exception
}
...
}
我想要的只是在我的自定义注释(@Secure)中处理权限检查;它应该使用 permissionService 检查权限,并在必要时抛出权限异常。而且我不想重新实例化 requestServiceImpl 或 permissionServiceImpl 类(它应该使用 spring bean):
@Override
@Transactional
@Secure(...)
public RequestResultModel submitRequest(Request request)
{
//submit request
}
我怎样才能做到这一点?