2323import javax .inject .Inject ;
2424import javax .servlet .http .HttpServletRequest ;
2525
26+ import eu .openanalytics .containerproxy .auth .IAuthenticationBackend ;
27+ import eu .openanalytics .containerproxy .auth .impl .OpenIDAuthenticationBackend ;
2628import org .springframework .core .env .Environment ;
2729import org .springframework .stereotype .Controller ;
2830import org .springframework .ui .ModelMap ;
2931import org .springframework .web .bind .annotation .RequestMapping ;
3032import org .springframework .web .bind .annotation .RequestMethod ;
3133
3234import eu .openanalytics .containerproxy .api .BaseController ;
35+ import org .springframework .web .bind .annotation .RequestParam ;
36+ import org .springframework .web .servlet .view .RedirectView ;
37+
38+ import java .util .Optional ;
3339
3440@ Controller
3541public class AuthController extends BaseController {
3642
3743 @ Inject
3844 private Environment environment ;
3945
46+ @ Inject
47+ private IAuthenticationBackend auth ;
48+
49+ @ RequestMapping (value = "/login" , method = RequestMethod .GET )
50+ public Object getLoginPage (@ RequestParam Optional <String > error , ModelMap map ) {
51+ prepareMap (map );
52+ if (error .isPresent ()) map .put ("error" , "Invalid user name or password" );
53+
54+ if (auth instanceof OpenIDAuthenticationBackend ) {
55+ return new RedirectView (((OpenIDAuthenticationBackend ) auth ).getLoginRedirectURI ());
56+ } else {
57+ return "login" ;
58+ }
59+ }
60+
4061 @ RequestMapping (value = "/auth-error" , method = RequestMethod .GET )
41- public String getAuthErrorPage (ModelMap map , HttpServletRequest request ) {
62+ public String getAuthErrorPage (ModelMap map ) {
63+ prepareMap (map );
4264 map .put ("application_name" , environment .getProperty ("spring.application.name" ));
4365 return "auth-error" ;
4466 }
4567
4668 @ RequestMapping (value = "/app-access-denied" , method = RequestMethod .GET )
47- public String getAppAccessDeniedPage (ModelMap map , HttpServletRequest request ) {
69+ public String getAppAccessDeniedPage (ModelMap map ) {
70+ prepareMap (map );
4871 return "app-access-denied" ;
4972 }
5073
74+ @ RequestMapping (value = "/logout-success" , method = RequestMethod .GET )
75+ public String getLogoutSuccessPage (ModelMap map ) {
76+ prepareMap (map );
77+ return "logout-success" ;
78+ }
79+
5180}
0 commit comments