Скорее всего, это слишком поздно, но я сделал то, что вы делаете, внедрив Servlet Filter перед службой, которая выполняет авторизацию.Это полностью исключает необходимость в АОП и дает вам фактический запрос ServletRequest напрямую, не обходя его системой.
Как ни странно, вопрос , на который вы помогли мне ответить, скорее всего поможет.Вы здесь, если вы действительно хотели AOP.
Вы можете предоставить Spring RequestContextFilter для запроса, а затем получить доступ к HttpServletRequest
(в отличие от HttpContext
):
<filter>
<filter-name>requestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>requestContextFilter</filter-name>
<url-pattern>/path/to/services/*</url-pattern>
</filter-mapping>
Код доступа по цепочке фильтров:
/**
* Get the current {@link HttpServletRequest} [hopefully] being made
* containing the {@link HttpServletRequest#getAttribute(String) attribute}.
* @return Never {@code null}.
* @throws NullPointerException if the Servlet Filter for the {@link
* RequestContextHolder} is not setup
* appropriately.
* @see org.springframework.web.filter.RequestContextFilter
*/
protected HttpServletRequest getRequest()
{
// get the request from the Spring Context Holder (this is done for
// every request by a filter)
ServletRequestAttributes attributes =
(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
return attributes.getRequest();
}