Skip to content

Commit d10573c

Browse files
committed
#116 - redirect to /admin if the user is already logged in
(cherry picked from commit d96e7e2)
1 parent feb2957 commit d10573c

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/main/java/alfio/config/WebSecurityConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected void configure(HttpSecurity http) throws Exception {
138138
.and()
139139
.formLogin()
140140
.loginPage("/authentication")
141-
.loginProcessingUrl("/authentication")
141+
.loginProcessingUrl("/authenticate")
142142
.failureUrl("/authentication?failed");
143143
}
144144
}

src/main/java/alfio/controller/#Controller.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,25 @@
2222
import org.springframework.web.bind.annotation.RequestMethod;
2323
import org.springframework.web.bind.annotation.RequestParam;
2424

25+
import java.security.Principal;
26+
2527
@Controller
2628
public class LoginController {
2729

30+
private static final String REDIRECT_ADMIN = "redirect:/admin/";
31+
2832
@RequestMapping(value="/authentication", method = RequestMethod.GET)
29-
public String getLoginPage(@RequestParam(value="failed", required = false) String failed, Model model) {
33+
public String getLoginPage(@RequestParam(value="failed", required = false) String failed, Model model, Principal principal) {
34+
if(principal != null) {
35+
return REDIRECT_ADMIN;
36+
}
3037
model.addAttribute("failed", failed != null);
3138
return "/#/#";
3239
}
3340

34-
@RequestMapping(value="/authentication", method = RequestMethod.POST)
41+
@RequestMapping(value="/authenticate", method = RequestMethod.POST)
3542
public String doLogin() {
36-
return "redirect:/admin/";
43+
return REDIRECT_ADMIN;
3744
}
3845

3946
}

src/main/webapp/WEB-INF/templates/#/#.ms

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<div class="container">
1414
<div class="row">
1515
<div class="col-sm-10 col-sm-push-1 col-xs-12 col-md-6 col-md-push-3">
16-
<form role="form" name="loginForm" action="{{request.contextPath}}/authentication" method="post">
16+
<form role="form" name="loginForm" action="{{request.contextPath}}/authenticate" method="post">
1717
<input name="_csrf" type="hidden" value="{{_csrf.token}}" />
1818
<div class="page-header">
1919
<h2>Authentication requested</h2>

0 commit comments

Comments
 (0)