package org.carlspring.strongbox.authentication.api.impl.xml;

import org.carlspring.strongbox.data.CacheName;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.crypto.password.StandardPasswordEncoder;

public class CacheManagerAuthenticationCache implements AuthenticationCache
{
    private StandardPasswordEncoder standardPasswordEncoder = new StandardPasswordEncoder();

    @Cacheable(cacheNames = CacheName.User.AUTHENTICATIONS, key = "#p0", unless = "true")
    public UsernamePasswordAuthenticationToken getAuthenticationToken(String userName)
    {
        return null;
    }

    @Cacheable(cacheNames = CacheName.User.AUTHENTICATIONS, key = "#p0.principal")
    public UsernamePasswordAuthenticationToken putAuthenticationToken(UsernamePasswordAuthenticationToken authentication)
    {
        return createCachableAuthentication(authentication);
    }

    public UsernamePasswordAuthenticationToken createCachableAuthentication(UsernamePasswordAuthenticationToken authentication)
    {
        String encodedPassword = encode(authentication.getCredentials().toString());

        return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), encodedPassword);
    }

    public String encode(CharSequence rawPassword)
    {
        return standardPasswordEncoder.encode(rawPassword);
    }

    public boolean matches(CharSequence rawPassword,
                           String encodedPassword)
    {
        return standardPasswordEncoder.matches(rawPassword, encodedPassword);
    }

}

@@ -250,85 +250,8 @@
 ken;
-%0Aimport org.springframework.security.crypto.password.StandardPasswordEncoder;
 %0A%0Apu
@@ -330,74 +330,214 @@
 e%0A%7B%0A
-    private StandardPasswordEncoder standardPasswordEncoder = new 
+%0A    @SuppressWarnings(%22deprecation%22)%0A    private org.springframework.security.crypto.password.StandardPasswordEncoder standardPasswordEncoder = new%0A            org.springframework.security.crypto.password.
 Stan

fix deprecation