diff --git a/src/main/java/de/thm/arsnova/aop/UserSessionAspect.java b/src/main/java/de/thm/arsnova/aop/UserSessionAspect.java index bb4a5032901b9f3461b1df2b7a6d264f42d20765..bede3b28acd1df08d2483e39f93cbf0c57e3b8d4 100644 --- a/src/main/java/de/thm/arsnova/aop/UserSessionAspect.java +++ b/src/main/java/de/thm/arsnova/aop/UserSessionAspect.java @@ -8,8 +8,6 @@ import org.aspectj.lang.annotation.Aspect; import org.springframework.beans.factory.annotation.Autowired; import de.thm.arsnova.entities.Session; -import de.thm.arsnova.events.Publisher; -import de.thm.arsnova.services.IUserService; import de.thm.arsnova.services.UserSessionService; @Aspect @@ -18,12 +16,6 @@ public class UserSessionAspect { @Autowired private UserSessionService userSessionService; - @Autowired - private IUserService userService; - - @Autowired - private Publisher publisher; - /** Sets current user and ARSnova session in session scoped UserSessionService * * @param jp @@ -35,7 +27,6 @@ public class UserSessionAspect { returning="session" ) public final void joinSessionAdvice(final JoinPoint jp, final String keyword, final Session session) { - userSessionService.setUser(userService.getCurrentUser()); userSessionService.setSession(session); } @@ -54,28 +45,4 @@ public class UserSessionAspect { userSessionService.setSession(session); userSessionService.setSocketId(socketId); } - - /** Sets current user, ARSnova session and websocket session ID in session scoped UserSessionService - * - * @param jp - * @param keyword - * @param socketId - * @param session - */ - @AfterReturning( - pointcut="execution(public * de.thm.arsnova.controller.LoginController.doLogin(..)) " + - "&& args(type, guestName, forcedReferer, successUrl, failureUrl, role, ..)" - ) - public final void doLogin( - final JoinPoint jp, - final String type, - final String guestName, - final String forcedReferer, - final String successUrl, - final String failureUrl, - final UserSessionService.Role role) { - - userSessionService.setRole(role); - userSessionService.setUser(userService.getCurrentUser()); - } } diff --git a/src/main/java/de/thm/arsnova/controller/LoginController.java b/src/main/java/de/thm/arsnova/controller/LoginController.java index ff743fb035a978ac2ae4080883ed4b62937c0cbc..42869c66116609af3ad0473e38de8894f4b6cc88 100644 --- a/src/main/java/de/thm/arsnova/controller/LoginController.java +++ b/src/main/java/de/thm/arsnova/controller/LoginController.java @@ -94,6 +94,8 @@ public class LoginController extends AbstractController { final HttpServletRequest request, final HttpServletResponse response ) throws IOException, ServletException { + userSessionService.setRole(role); + String referer = request.getHeader("referer"); if (null != forcedReferer && null != referer && !UrlUtils.isAbsoluteUrl(referer)) { /* Use a url from a request parameter as referer as long as the url is not absolute (to prevent @@ -111,17 +113,19 @@ public class LoginController extends AbstractController { null == failureUrl ? referer : failureUrl ); + View result = null; + if ("cas".equals(type)) { casEntryPoint.commence(request, response, null); } else if ("twitter".equals(type)) { String authUrl = twitterProvider.getAuthorizationUrl(new HttpUserSession(request)); - return new RedirectView(authUrl); + result = new RedirectView(authUrl); } else if ("facebook".equals(type)) { String authUrl = facebookProvider.getAuthorizationUrl(new HttpUserSession(request)); - return new RedirectView(authUrl); + result = new RedirectView(authUrl); } else if ("google".equals(type)) { String authUrl = googleProvider.getAuthorizationUrl(new HttpUserSession(request)); - return new RedirectView(authUrl); + result = new RedirectView(authUrl); } else if ("guest".equals(type)) { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(new SimpleGrantedAuthority("ROLE_GUEST")); @@ -140,9 +144,9 @@ public class LoginController extends AbstractController { SecurityContextHolder.getContext().setAuthentication(token); request.getSession(true).setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext()); - return new RedirectView(null == successUrl ? referer + "#auth/checkLogin" : successUrl); + result = new RedirectView(null == successUrl ? referer + "#auth/checkLogin" : successUrl); } - return null; + return result; } @RequestMapping(value = { "/auth/", "/whoami" }, method = RequestMethod.GET)