Q:

Spring/Angular get current user and save post to that user

Sorry, I am back with just one more question. I have am using Spring security and Angular front end. My question is once I log in, how do I save a post to the current user.
Post model:  
@Id
@GeneratedValue
private Long id;

private String title;

@Column(columnDefinition = "TEXT")
private String body;

@JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss a", timezone = "America/New_York")
private Date createdAt;

private String pictureUrl;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user")
private User user;

UserDetailsServiceImpl:
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserRepository repository;

    @Override
    public UserDetails loadUserByUsername(String username) throws 
         UsernameNotFoundException {

         // Get the user's username
         User currentUser = repository.findByUsername(username);

    // Create a new UserDetails called user and set to user's :
    // username, current users password, user is enabled, account Non expired, creds non expired
    // account non locked,
    UserDetails user = new org.springframework.security.core.userdetails.User(username, currentUser.getPassword(),
            true, true, true, true,
            AuthorityUtils.createAuthorityList(currentUser.getRole()));

    return user;
}

}
Obviously this works fine with the command line runner:
Post post1 = new Post("Title", "Some content", date, user1);

Angular: 
addPost() {
    const title = this.eventForm.get('title').value;
    const body = this.eventForm.get('body').value;

    const newTask: Task = {
        post,
        body
    };

    this.data.addPost(newPost).subscribe((res) => {
       console.log(res);
       this.getPost();
    });
}

How can I, once logged in, get the actual user object to save the post object.

A:

I have no idea if this is the correct way to do this, but it works at least! Lol...
It works for now anyways, haha. 
@Autowired
private PostRepository repository;

@Autowired 
UserRepository userRepository;

@PostMapping("/posts")
public void addPost(@RequestBody Post post) {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    User user = userRepository.findByUsername(auth.getName());
    post.setUser(user);
    this.repository.save(post);
}

