1 package de.spring.example.context;
3 import javax.inject.Named;
5 import org.springframework.util.Assert;
7 @Named("userNameThreadContext")
8 public class UsernameThreadContext {
9 public static final String USERNAME_HEADER = "USERNAME";
11 private final ThreadLocal<String> contextHolder = new ThreadLocal<>();
13 public void setUsername(String username) {
14 Assert.notNull(username);
16 contextHolder.set(username);
19 public String getUsername() {
20 return contextHolder.get();
23 public void clearUsername() {
24 contextHolder.remove();