package io.github.jhipster.registry.web.rest;

import com.codahale.metrics.annotation.Timed;
import io.github.jhipster.registry.web.rest.vm.UserVM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.stream.Collectors;

/**
 * REST controller for managing the current user's account.
 */
@RestController
@RequestMapping("/api")
public class AccountResource {

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

    /**
     * GET  /authenticate : check if the user is authenticated, and return its login.
     *
     * @param request the HTTP request
     * @return the login if the user is authenticated
     */
    @GetMapping("/authenticate")
    @Timed
    public String isAuthenticated(HttpServletRequest request) {
        log.debug("REST request to check if the current user is authenticated");
        return request.getRemoteUser();
    }

    /**
     * GET  /account : get the current user.
     *
     * @return the ResponseEntity with status 200 (OK) and the current user in body, or status 500 (Internal Server
     * Error) if the user couldn't be returned
     */
    @GetMapping("/account")
    @Timed
    public ResponseEntity<UserVM> getAccount() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        User user = (User) authentication.getPrincipal();
        UserVM userVM = new UserVM(user.getUsername(),
            user.getAuthorities().stream()
                .map(authority -> authority.getAuthority()).collect(Collectors.toSet()));
        return new ResponseEntity<>(userVM, HttpStatus.OK);
    }
}

@@ -347,16 +347,75 @@
 cation;%0A
+import org.springframework.security.core.GrantedAuthority;%0A
 import o
@@ -2060,30 +2060,24 @@
 map(
-authority -%3E a
+GrantedA
 uthority
 .get
@@ -2072,17 +2072,18 @@
 uthority
-.
+::
 getAutho
@@ -2086,18 +2086,16 @@
 uthority
-()
 ).collec

Remove Lambda warning