I'm creating a web app that will be run on a single page. For this reason, I need to have my authentication paths accessible using only Ajax calls (no redirection).
I'm using Spring Security and I have the login and logout functionality working fine so far. The issue is that when the user is already authenticated and they POST to the login-processing-url they are actually logged in again. What I want to happen is my jsonAuthenticationHandler or some other handler to return a 500 or something telling me I can't log in again.
Here's what I've got for my security XML:
<sec:http use-expressions="true" entry-point-ref="jsonAuthenticationHandler">
<sec:intercept-url pattern="/data/**" access="isAuthenticated()"/>
<sec:intercept-url pattern="/data/login" access="!isAuthenticated()"/> <!--This is the line that is not behaving as expected-->
<sec:form-login login-page="/data/loginpage"
login-processing-url="/data/login"
username-parameter="username"
password-parameter="password"
authentication-failure-handler-ref="authenticationFailureHandler"
authentication-success-handler-ref="authenticationSuccessHandler"/>
<sec:logout logout-url="/data/logout"
delete-cookies="true"
invalidate-session="true"
logout-success-url="/"/>
</sec:http>
<bean id="jsonAuthenticationHandler" class="com.example.security.JsonAuthenticationHandler">
<constructor-arg name="loginUrl" value="/data/loginpage"/>
</bean>
<bean id="userDetailsService" class="com.example.security.UserDetailService"/>
<bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
<bean id="authenticationSuccessHandler" class="com.example.security.AuthenticationSuccessHandler"/>
<bean id="authenticationFailureHandler" class="com.example.security.AuthenticationFailureHandler"/>
<sec:authentication-manager>
<sec:authentication-provider user-service-ref="userDetailsService">
<sec:password-encoder ref="encoder"/>
</sec:authentication-provider>
</sec:authentication-manager>
Thanks in advance for any help!