<%#
 Copyright 2013-2017 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see http://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
package <%=packageName%>.web.rest;

import <%=packageName%>.security.jwt.JWTConfigurer;
import <%=packageName%>.security.jwt.TokenProvider;
import <%=packageName%>.web.rest.vm.LoginVM;

import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Collections;

/**
 * Controller to authenticate users.
 */
@RestController
@RequestMapping("/api")
public class UserJWTController {

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

    private final TokenProvider tokenProvider;

    private final AuthenticationManager authenticationManager;

    public UserJWTController(TokenProvider tokenProvider, AuthenticationManager authenticationManager) {
        this.tokenProvider = tokenProvider;
        this.authenticationManager = authenticationManager;
    }

    @PostMapping("/authenticate")
    @Timed
    public ResponseEntity<JWTToken> authorize(@Valid @RequestBody LoginVM loginVM, HttpServletResponse response) {

        UsernamePasswordAuthenticationToken authenticationToken =
            new UsernamePasswordAuthenticationToken(loginVM.getUsername(), loginVM.getPassword());

        Authentication authentication = this.authenticationManager.authenticate(authenticationToken);
        SecurityContextHolder.getContext().setAuthentication(authentication);
        boolean rememberMe = (loginVM.isRememberMe() == null) ? false : loginVM.isRememberMe();
        String jwt = tokenProvider.createToken(authentication, rememberMe);
        response.addHeader(JWTConfigurer.AUTHORIZATION_HEADER, "Bearer " + jwt);
        return ResponseEntity.ok(new JWTToken(jwt));

    }

    /**
     * Object to return as body in JWT Authentication.
     */
    static class JWTToken {

        private String idToken;

        JWTToken(String idToken) {
            this.idToken = idToken;
        }

        @JsonProperty("id_token")
        String getIdToken() {
            return idToken;
        }

        void setIdToken(String idToken) {
            this.idToken = idToken;
        }
    }
}

@@ -1016,51 +1016,38 @@
 rg.s
-lf4j.Logger;%0Aimport org.slf4j.LoggerFactory
+pringframework.http.HttpStatus
 ;%0Aim
@@ -1072,37 +1072,38 @@
 mework.http.Http
-Statu
+Header
 s;%0Aimport org.sp
@@ -1360,74 +1360,8 @@
 on;%0A
-import org.springframework.security.core.AuthenticationException;%0A
 impo
@@ -1496,101 +1496,24 @@
 vax.
-servlet.http.HttpServletResponse;%0Aimport javax.validation.Valid;%0Aimport java.util.Collections
+validation.Valid
 ;%0A%0A/
@@ -1634,90 +1634,8 @@
  %7B%0A%0A
-    private final Logger log = LoggerFactory.getLogger(UserJWTController.class);%0A%0A
     
@@ -2088,38 +2088,8 @@
 inVM
-, HttpServletResponse response
 ) %7B%0A
@@ -2619,26 +2619,76 @@
     
-response.add
+HttpHeaders httpHeaders = new HttpHeaders();%0A        http
 Header
+s.add
 (JWT
@@ -2753,16 +2753,20 @@
  return 
+new 
 Response
@@ -2775,11 +2775,10 @@
 tity
-.ok
+%3C%3E
 (new
@@ -2791,20 +2791,47 @@
 ken(jwt)
+, httpHeaders, HttpStatus.OK
 );%0A
-%0A
     %7D%0A%0A 

Remove HttpServletResponse in UserJWTController