Java 8 use of optional I have two methods I'd like to improve using optional and any other tool,

 @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userRepository.findByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException(String.format("No user found with username '%s'.", username));
        } else {
            return user;
        }
    }

    public void changePassword(String oldPassword, String newPassword) {

        Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
        String username = currentUser.getName();

        if (authenticationManager != null) {
            LOGGER.debug("Re-authenticating user '"+ username + "' for password change request.");

            authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, oldPassword));
        } else {
            LOGGER.debug("No authentication manager set. Can't change Password!");

            return;
        }

        LOGGER.debug("Changing password for user '"+ username + "'");

        User user = (User) loadUserByUsername(username);
        user.setPassword(passwordEncoder.encode(newPassword));
        userRepository.save(user);

    }


First solution was to do 
Optional.ofNullable(user).orElseThrow() but I couldn't use the string format here for the UsernameNotFoundException. I don't want to lose the message I have written in the exceptions.

Any suggestions on how to improve this code?
Optionals do not improve your code. You're using if statements and null checks just like they are intended to be used. There is no need to improve anything there.

Edit: If-statements and null-checks are not evil. There is no need to try to get rid of either one and Optionals were not intended to replace them. The evil is having an API made by someone else and not knowing if it returns a null or not. Optionals were intended to give the person reading the code and the compiler compiling it a strongly typed fact about the possibility of a method return value not existing.

If I have to try to find something worth mentioning from your code it's the use of heavy String.format to create a trivial exception message. Just use concatenation like in the logging statements. :)