package com.drumonii.loltrollbuild.api.admin;

import com.drumonii.loltrollbuild.api.status.BadRequestException;
import com.drumonii.loltrollbuild.security.AdminUserDetails;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
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 java.util.Optional;

/**
 * REST controller for administration authentication.
 */
@RestController
@RequestMapping("${api.base-path}/admin")
public class AdminAuthenticationRestController {

    /**
     * Gets the current authentication principal - {@link AdminUserDetails}.
     *
     * @param userDetails the {@link User}
     * @return the {@link AdminUserDetails} if authenticated, otherwise {@code null}
     */
    @GetMapping("/authentication")
    public AdminUserDetails getAuthentication(@AuthenticationPrincipal User userDetails) {
        User user = Optional.ofNullable(userDetails)
                .orElseThrow(() -> new BadRequestException("Authentication was not found"));
        return AdminUserDetails.from(user);
    }

}

@@ -1053,19 +1053,14 @@
     
-User user =
+return
  Opt
@@ -1089,16 +1089,61 @@
 etails)%0A
+                .map(AdminUserDetails::from)%0A
         
@@ -1231,52 +1231,8 @@
 ));%0A
-        return AdminUserDetails.from(user);%0A
     

Simplify get AdminUserDetails from nullable UserDetails