English 中文(简体)
春季安全 3 初步请求更正
原标题:Spring Security 3 Get Initially Requested URL

我需要根据用户来自何处,修改我的春季安全日志。 我的客户想要的是两种不同的风格。 如果您来自<代码>appcontextroot/test vsappcontextroot/choose。 我试图做以下的工作,但String url=savedRequest.getRedirectUrl()与已经而不是用户要求的首页相同。 任何想法?

ExternalContext externalContext = FacesUtils.getExternalContext();
    HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
    HttpSession session = request.getSession(false);
    if(session != null) {
        SavedRequest savedRequest = new DefaultSavedRequest(request, new PortResolverImpl());
        String url=savedRequest.getRedirectUrl();
    } 
最佳回答

您需要从本届会议中提取<代码>SavedRequest,不要产生新的内容:

SavedRequest savedRequest = 
    new HttpSessionRequestCache().getRequest(request, response);
问题回答
SavedRequest savedRequest =
    (SavedRequest)session.getAttribute("SPRING_SECURITY_SAVED_REQUEST");
// ...check for null...
String targetUrl = savedRequest.getRedirectUrl();

如果你不提供HttpServletResponse(例如,如果你使用org. Cerframework.social.link.web.SignInAdapter)。

测试了春天安全3.1.0.RC2。

I didn t make it work with the solution proposed, here s what i found : (Using spring 3.1).

您的职衔:

CharsetFilter implements Filter {
    @OVerride public void doFilter(ServletRequest request, ServletResponse response, FilterChain next) throws IOException, ServletException {
        HttpServletRequest hsr = (HttpServletRequest) request;
        if (hsr.getUserPrincipal() == null) {
            HttpSession session = hsr.getSession();
            if (!(hsr == null)) {
                logger.info("path : " + hsr.getPathInfo());
                session.setAttribute("beforeLoginUrl", hsr.getPathInfo());
    }
  }
}

之后,您的网页xml宣布:

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
    <filter-name>charsetFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>charsetFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
    <filter-name>CharsetFilter</filter-name>
    <filter-class>com.ent.foo.CharsetFilter</filter-class>
    <init-param>
        <param-name>requestEncoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>

之后,在成功登录后,在你回旋转时,HttpSession返回:

@RequestMapping(value = "successful")
public void showSuccessfulogin (HttpSession session) {
    String redirectUrl = (String) session.getAttribute("beforeLoginUrl");
    if (redirectUrl != null) {
        session.removeAttribute("beforeLoginUrl");
        return "redirect:" + redirectUrl;
    }
    return "redirect:/";
}

这里,你在工作上站得住脚,但youll必须检查

hsr.getPathInfo()

and see if it ends with .css or .js, etc...

Also if the login fail you ll should see if session attribute is already set and see any others special case !

此前,我的过滤器曾用于对图f-8的所有投入/产出进行格式。

希望会有所助益。

对我来说,我使用了春天安全3.0.0,以下工作:

DefaultSavedRequest savedRequest=(DefaultSavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST_KEY"); targetUrl=savedRequest.getRedirectUrl();





相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签