New LoginController in place of the login method in MultiController.

Slight introduction to Java annotation based configuration (note that <mvc:annotation-driven /> has been added to libresonic-servlet.xml).
master
remi 8 years ago
parent c9bdff4dff
commit a03aa2805d
  1. 72
      libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java
  2. 28
      libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java
  3. 16
      libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml

@ -0,0 +1,72 @@
package org.libresonic.player.controller;
import org.libresonic.player.Logger;
import org.libresonic.player.domain.User;
import org.libresonic.player.service.PlaylistService;
import org.libresonic.player.service.SecurityService;
import org.libresonic.player.service.SettingsService;
import org.libresonic.player.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
/**
* Spring MVC Controller that serves the login page.
*/
@Controller
@RequestMapping("/login")
public class LoginController {
private static final Logger LOG = Logger.getLogger(LoginController.class);
private final SecurityService securityService;
private final SettingsService settingsService;
private final PlaylistService playlistService;
@Autowired
public LoginController(SecurityService securityService, SettingsService settingsService, PlaylistService playlistService) {
this.securityService = securityService;
this.settingsService = settingsService;
this.playlistService = playlistService;
}
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {
// Auto-login if "user" and "password" parameters are given.
String username = request.getParameter("user");
String password = request.getParameter("password");
if (username != null && password != null) {
username = StringUtil.urlEncode(username);
password = StringUtil.urlEncode(password);
return new ModelAndView(new RedirectView("/j_spring_security_check?"+
UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY+"=" + username +
"&"+UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY+"=" + password
));
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("logout", request.getParameter("logout") != null);
map.put("error", request.getParameter("error") != null);
map.put("brand", settingsService.getBrand());
map.put("loginMessage", settingsService.getLoginMessage());
User admin = securityService.getUserByName(User.USERNAME_ADMIN);
if (User.USERNAME_ADMIN.equals(admin.getPassword())) {
map.put("insecure", true);
}
return new ModelAndView("login", "model", map);
}
}

@ -64,34 +64,6 @@ public class MultiController extends MultiActionController {
private SettingsService settingsService; private SettingsService settingsService;
private PlaylistService playlistService; private PlaylistService playlistService;
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {
// Auto-login if "user" and "password" parameters are given.
String username = request.getParameter("user");
String password = request.getParameter("password");
if (username != null && password != null) {
username = StringUtil.urlEncode(username);
password = StringUtil.urlEncode(password);
return new ModelAndView(new RedirectView("/j_spring_security_check?"+
UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY+"=" + username +
"&"+UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY+"=" + password
));
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("logout", request.getParameter("logout") != null);
map.put("error", request.getParameter("error") != null);
map.put("brand", settingsService.getBrand());
map.put("loginMessage", settingsService.getLoginMessage());
User admin = securityService.getUserByName(User.USERNAME_ADMIN);
if (User.USERNAME_ADMIN.equals(admin.getPassword())) {
map.put("insecure", true);
}
return new ModelAndView("login", "model", map);
}
public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception { public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();

@ -2,7 +2,18 @@
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="org.libresonic.player.controller"/>
<bean id="leftController" class="org.libresonic.player.controller.LeftController"> <bean id="leftController" class="org.libresonic.player.controller.LeftController">
<property name="viewName" value="left"/> <property name="viewName" value="left"/>
@ -434,7 +445,10 @@
<prop key="/top.view">topController</prop> <prop key="/top.view">topController</prop>
<prop key="/randomPlayQueue.view">randomPlayQueueController</prop> <prop key="/randomPlayQueue.view">randomPlayQueueController</prop>
<prop key="/changeCoverArt.view">changeCoverArtController</prop> <prop key="/changeCoverArt.view">changeCoverArtController</prop>
<!--
login.view has moved to the LoginController
<prop key="/login.view">multiController</prop> <prop key="/login.view">multiController</prop>
-->
<prop key="/recover.view">multiController</prop> <prop key="/recover.view">multiController</prop>
<prop key="/accessDenied.view">multiController</prop> <prop key="/accessDenied.view">multiController</prop>
<prop key="/notFound.view">multiController</prop> <prop key="/notFound.view">multiController</prop>

Loading…
Cancel
Save