View Javadoc

1   package org.appfuse.webapp.security;
2   
3   import java.io.IOException;
4   
5   import javax.servlet.ServletException;
6   import javax.servlet.http.HttpServletRequest;
7   import javax.servlet.http.HttpServletResponse;
8   
9   import org.springframework.security.core.AuthenticationException;
10  import org.springframework.security.web.AuthenticationEntryPoint;
11  
12  /**
13   * Used to indicate RPC requests that login is required sending a '401' error,
14   * code.
15   * 
16   * <p>
17   * It can be used in combination with
18   * {@link org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint}
19   * </p>
20   * <p>
21   * A configuration might look like this:
22   * </p>
23   *
24   * <pre>
25   * &lt;bean id=&quot;daep&quot; class=&quot;org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint&quot;&gt;
26   *     &lt;constructor-arg&gt;
27   *         &lt;map&gt;
28   *             &lt;entry key=&quot;hasHeader('Content-Type','application/json; charset=utf-8')&quot; value-ref=&quot;rpcAuthenticationEntryPoint&quot; /&gt;
29   *         &lt;/map&gt;
30   *     &lt;/constructor-arg&gt;
31   *     &lt;property name=&quot;defaultEntryPoint&quot; ref=&quot;defaultEntryPoint&quot;/&gt;
32   * &lt;/bean&gt;
33   * </pre>
34   * 
35   * @author ivangsa
36   *
37   */
38  public class RpcAuthenticationEntryPoint implements AuthenticationEntryPoint {
39  
40      @Override
41      public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
42          response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
43      }
44  
45  }