1 package de.juplo.yourshouter;
3 import org.springframework.social.UserIdSource;
4 import org.springframework.util.Assert;
8 * Implementation of {@link UserIdSource}, that retrieves the ID of the current
9 * user from the {@link SecurityContext}.
13 public class SecurityContextUserIdSource implements UserIdSource
16 * Retrieves the ID of the current user from the {@link SecurityContext}.
17 * If no ID is found, an exception is thrown.
19 * @return The ID of the current user
20 * @throws IllegalStateException, if no current user is found.
23 public String getUserId()
25 Assert.state(SecurityContext.userSignedIn(), "No user signed in!");
26 return SecurityContext.getCurrentUser();