Announcement Announcement Module
Collapse
No announcement yet.
How to cast Authentication in createAuthentication method security 3.1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to cast Authentication in createAuthentication method security 3.1

    Hi!

    I need to find a way to make a cast to Authentication when the user is guest.
    because I need to put other objects like shopcart before login.

    anyone know what to do?

    my code
    Code:
    public class CustomAnonymousAuthenticationFilter extends  AnonymousAuthenticationFilter{
    .
    .
    .
    protected Authentication createAuthentication(final HttpServletRequest request) {
    	UsuarioGuest auth = (UsuarioGuest) super.createAuthentication(request);
    	return auth;
    }
    ERROR
    java.lang.ClassCastException: org.springframework.security.authentication.Anonym ousAuthenticationToken cannot be cast to cl.work.security.UsuarioGuest

    UsuarioGuest Class
    Code:
    public class UsuarioGuest extends AnonymousAuthenticationToken{
    
    	public UsuarioGuest(String key, Object principal, Collection<? extends GrantedAuthority> authorities) {
    		super(key, principal, authorities);
    	
    	}
    
     
    	private static final long serialVersionUID = 2322514539993169503L;
    	List<ShoppingCartProductGuestDTO> listShoppCartProduct = new ArrayList();
    	
    
    	public List<ShoppingCartProductGuestDTO> getListShoppCartProduct() {
    		return listShoppCartProduct;
    	}
    
    	public void setListShoppCartProduct(
    			List<ShoppingCartProductGuestDTO> listShoppCartProduct) {
    		this.listShoppCartProduct = listShoppCartProduct;
    	}
    
     
    	
    
    }
Working...
X