Refactored authorization from HomeController to UserCookieInterceptor
[examples/facebook-app] / src / main / java / de / juplo / yourshouter / SecurityContextUserIdSource.java
1 package de.juplo.yourshouter;
2
3 import org.springframework.social.UserIdSource;
4 import org.springframework.util.Assert;
5
6
7 /**
8  * Implementation of {@link UserIdSource}, that retrieves the ID of the current
9  * user from the {@link SecurityContext}.
10  *
11  * @author Kai Moritz
12  */
13 public class SecurityContextUserIdSource implements UserIdSource
14 {
15   /**
16    * Retrieves the ID of the current user from the {@link SecurityContext}.
17    * If no ID is found, an exception is thrown.
18    *
19    * @return The ID of the current user
20    * @throws IllegalStateException, if no current user is found.
21    */
22   @Override
23   public String getUserId()
24   {
25     Assert.state(SecurityContext.userSignedIn(), "No user signed in!");
26     return SecurityContext.getCurrentUser();
27   }
28 }