English 中文(简体)
Wicket 和 servlet 过滤验证 - 有没有更好的方法?
原标题:Wicket and servlet filter authentication - is there a better way?

我们的应用程序是使用Wicket。我们使用Wicket的表格处理认证,主要的好处是网站的外观保持一致。

我们认为我们无法进行集装箱认证, 因为我们的应用程序允许用户在中途转换认证机制, Jetty 自己也制造了点摩擦,

因此,我们最终通过过滤器实施认证(有许多好的例子。 )

现在,我发现,通过这样做,Wicket认证被略微打破。

  1. Anonymous user would visit the site.
  2. Security filter determines that the user isn t authenticated and redirects to sign-in.
  3. Wicket renders the sign-in page.
  4. User signs in.
  5. Wicket processes the post to the sign-in form and redirects user back.
  6. Security filter determines that the user isn t authenticated and redirects...

我查看了我的经认证的网络会议子类,希望找到某种办法,让我能够掌握Http会议,并设定一个会话属性,然后可以从过滤器中检查。然而,我无法为我的一生找到一个方法。

我所要做的是做另一个过滤器 yet, , 代码是这样的:

public class StealWicketUserFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // Nothing to initialise.
    }

    @Override
    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException
    {
        filterChain.doFilter(servletRequest, servletResponse);

        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        if ("POST".equals(httpServletRequest.getMethod()) &&
                "/sign_in".equals(httpServletRequest.getRequestURI())) {
            HttpSession session = httpServletRequest.getSession();
            ServerUser currentUser = (ServerUser)
                session.getAttribute("wicket:webUIServlet:currentUser");
            if (currentUser != null) {
                session.setAttribute(CombinedSecurityFilter.CURRENT_USER_ATTRIBUTE,
                                     currentUser);
            }
        }
        else if ("/sign_out".equals(httpServletRequest.getRequestURI())) {
            HttpSession session = httpServletRequest.getSession();
            session.removeAttribute(CombinedSecurityFilter.CURRENT_USER_ATTRIBUTE);
        }
    }

    @Override
    public void destroy() {
        // Nothing to destroy.
    }
}

这当然有用( 并将继续工作, 直到 Wicket 更改他们存储会话属性的前缀 。 )

我想我要知道的是,这是否是一个坏主意, 以及是否有一种“适当的威克特方法”来做这种事情。

至于我们不光使用Wicket认证的原因, 是因为我们希望支持SPNEGO认证和可能的其他外部认证类型。

最佳回答

您可以通过 request 而不是 session 获得您的

您需要的是:

WebRequest req = (WebRequest)RequestCycle.get().getRequest();
HttpSession session = req.getHttpServletRequest().getSession();

但我很肯定Wicket认证没有以如此明显的方式被打破 所以我可能想找出 是什么导致了这个故障

问题回答

暂无回答




相关问题
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 ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签