package org.appfuse.webapp.security;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
/**
* Used to indicate RPC requests that login is required sending a '401' error,
* code.
*
* <p>
* It can be used in combination with
* {@link org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint}
* </p>
* <p>
* A configuration might look like this:
* </p>
*
* <pre>
* <bean id="daep" class="org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint">
* <constructor-arg>
* <map>
* <entry key="hasHeader('Content-Type','application/json; charset=utf-8')" value-ref="rpcAuthenticationEntryPoint" />
* </map>
* </constructor-arg>
* <property name="defaultEntryPoint" ref="defaultEntryPoint"/>
* </bean>
* </pre>
*
* @author ivangsa
*
*/
public class RpcAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
}
}