1 package org.oxerr.spring.security.guest.authentication; 2 3 import org.oxerr.spring.security.guest.core.userdetails.GuestUserDetailsService; 4 import org.springframework.security.authentication.AuthenticationProvider; 5 import org.springframework.security.core.Authentication; 6 import org.springframework.security.core.AuthenticationException; 7 8 public class GuestAuthenticationProvider implements AuthenticationProvider { 9 10 private final GuestUserDetailsService guestUserDetailsService; 11 12 public GuestAuthenticationProvider(GuestUserDetailsService guestUserDetailsService) { 13 this.guestUserDetailsService = guestUserDetailsService; 14 } 15 16 @Override 17 public Authentication authenticate(Authentication authentication) throws AuthenticationException { 18 GuestAuthenticationToken guestAuthenticationToken = (GuestAuthenticationToken) authentication; 19 return new GuestAuthenticationToken(guestUserDetailsService.loadUser(guestAuthenticationToken)); 20 } 21 22 @Override 23 public boolean supports(Class<?> authentication) { 24 return GuestAuthenticationToken.class.isAssignableFrom(authentication); 25 } 26 27 }