com.soento.security.support.OauthEntryPoint Maven / Gradle / Ivy
The newest version!
package com.soento.security.support;
import com.soento.core.base.consts.MessageCode;
import com.soento.spring.support.MessageSourceAccessor;
import com.soento.web.util.SpringMvcUtil;
import org.springframework.security.authentication.InsufficientAuthenticationException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author soento
*/
public class OauthEntryPoint implements AuthenticationEntryPoint {
private MessageSourceAccessor msa;
public OauthEntryPoint(MessageSourceAccessor msa) {
this.msa = msa;
}
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
if (e instanceof InsufficientAuthenticationException) {
SpringMvcUtil.writeResponse(response, msa, MessageCode.INVALID_TOKEN);
} else {
SpringMvcUtil.writeResponse(response, msa, MessageCode.FORBIDDEN);
}
}
}