I am new in Spring security. I need create 3 types of autontification.
by ip
by sms
by pin code
Now I tried realize auth by ip. I use spring security.
I get ip address of client(my spring-boot app) and pass to backend server(another remote java server) by rest. if user is authenticated I get this User in my spring app and I wand show him index.html or if not - I get null and I want show him login.html
I create AuthenticationProvider
@Component
public class IPAddressBasedAuthenticationProvider implements AuthenticationProvider {
@Autowired
private HttpServletRequest request;
@Autowired
AuthService authService;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String ipAddress = request.getRemoteAddr();
AuthLkUser authLkUserByIp = authService.getAuthLkUserByIp(ipAddress);
if (authLkUserByIp == null) return null;
boolean b = authService.checkAuthLkUser(authLkUserByIp);
if (b) return null;
UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken("John Principal", "PlaceholderPWE");
result.setDetails(authentication.getDetails());
result.setAuthenticated(true);
return result;
}
@Override
public boolean supports(Class<?> aClass) {
return true;
}
}
When I open page for example index.html and my spring app in debbug mode I check in debbug point(method is worcked) and i have my authLkUserByIp
(user is authenticated normaly). I have result
and returne it. But on the page I have error
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Jul 11 12:48:25 ALMT 2016
There was an unexpected error (type=Forbidden, status=403).
Access is denied
But user is authenticated normaly. Why I have error?
I tried by this example
But I do not have web.xml. All configs in code.
I have some quations: 1. Why I get error and how can fix it? 2. When I trid realize another two types authontification How can I manage it?