package <%=packageName%>.security.social;

import <%=packageName%>.config.JHipsterProperties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.web.SignInAdapter;
import org.springframework.web.context.request.NativeWebRequest;
<%_ if (authenticationType == 'jwt') { _%>
import com.mycompany.myapp.security.jwt.TokenProvider;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.context.request.ServletWebRequest;
import javax.servlet.http.Cookie;
<%_ } _%>

import javax.inject.Inject;

public class CustomSignInAdapter implements SignInAdapter {

    private final Logger log = LoggerFactory.getLogger(CustomSignInAdapter.class);

    @Inject
    private UserDetailsService userDetailsService;

    @Inject
    private JHipsterProperties jHipsterProperties;

    <%_ if (authenticationType == 'jwt') { _%>
    @Inject
    private TokenProvider tokenProvider;
    <%_ } _%>

    <%_ if (authenticationType == 'jwt') { _%>
    @Override
    public String signIn(String userId, Connection<?> connection, NativeWebRequest request){
        try {
            UserDetails user = userDetailsService.loadUserByUsername(userId);
            UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
                user,
                null,
                user.getAuthorities());

            SecurityContextHolder.getContext().setAuthentication(authenticationToken);
            String jwt = tokenProvider.createToken(authenticationToken, false);
            ServletWebRequest servletWebRequest = (ServletWebRequest) request;
            servletWebRequest.getResponse().addCookie(getSocialAuthenticationCookie(jwt));
        } catch (AuthenticationException exception) {
            log.error("Social authentication error");
        }
        return jHipsterProperties.getSocial().getRedirectAfterSignIn();
    }

    private Cookie getSocialAuthenticationCookie(String token) {
        Cookie socialAuthCookie = new Cookie("social-authentication", token);
        socialAuthCookie.setPath("/");
        socialAuthCookie.setMaxAge(10);
        return socialAuthCookie;
    }
    <%_ } else { _%>
    @Override
    public String signIn(String userId, Connection<?> connection, NativeWebRequest request) {
        UserDetails user = userDetailsService.loadUserByUsername(userId);
        Authentication newAuth = new UsernamePasswordAuthenticationToken(
            user,
            null,
            user.getAuthorities());
        SecurityContextHolder.getContext().setAuthentication(newAuth);
        return jHipsterProperties.getSocial().getRedirectAfterSignIn();
    }
    <%_ } _%>
}

@@ -86,16 +86,121 @@
 perties;
+%0A%3C%25_ if (authenticationType == 'jwt') %7B _%25%3E%0Aimport %3C%25=packageName%25%3E.security.jwt.TokenProvider;%0A%3C%25_ %7D _%25%3E
 %0A%0Aimport
@@ -835,63 +835,8 @@
 _%25%3E%0A
-import com.mycompany.myapp.security.jwt.TokenProvider;%0A
 impo

Fix import