X-Git-Url: http://juplo.de/gitweb/?p=examples%2Ffacebook-app;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fyourshouter%2FSecurityContextUserIdSource.java;h=662da578e50186a5d4150b50582a377c0ad61dc7;hp=9fae3235dd5a95dd55e50979bf6a16fd3093b9d5;hb=50a5f792477308ef1e4ce458aca730c6fcc49593;hpb=a1ad44fc308e479f9a005aa2d87cb604d6eb0e7d diff --git a/src/main/java/de/juplo/yourshouter/SecurityContextUserIdSource.java b/src/main/java/de/juplo/yourshouter/SecurityContextUserIdSource.java index 9fae323..662da57 100644 --- a/src/main/java/de/juplo/yourshouter/SecurityContextUserIdSource.java +++ b/src/main/java/de/juplo/yourshouter/SecurityContextUserIdSource.java @@ -1,8 +1,7 @@ package de.juplo.yourshouter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.social.UserIdSource; +import org.springframework.util.Assert; /** @@ -13,30 +12,17 @@ import org.springframework.social.UserIdSource; */ public class SecurityContextUserIdSource implements UserIdSource { - private final static Logger LOG = - LoggerFactory.getLogger(SecurityContextUserIdSource.class); - - /** * Retrieves the ID of the current user from the {@link SecurityContext}. + * If no ID is found, an exception is thrown. * - * @return - * The ID of the current user, or the special ID anonymous, - * if no current user is present. + * @return The ID of the current user + * @throws IllegalStateException, if no current user is found. */ @Override public String getUserId() { - String user = SecurityContext.getCurrentUser(); - if (user != null) - { - LOG.debug("found user \"{}\" in the security-context", user); - } - else - { - LOG.info("found no user in the security-context, using \"anonymous\""); - user = "anonymous"; - } - return user; + Assert.state(SecurityContext.userSignedIn(), "No user signed in!"); + return SecurityContext.getCurrentUser(); } }