From 63253e4ff8fc7ee586000ab9b0a7b05cfad18155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 11 Dec 2016 21:46:31 +0100 Subject: [PATCH 01/50] Intoduce SpringBoot --- libresonic-main/pom.xml | 121 +++++++++++++++------------------------- 1 file changed, 45 insertions(+), 76 deletions(-) diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 95dabbaf..0361c119 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -68,49 +68,36 @@ - org.springframework - spring-webmvc + org.springframework.boot + spring-boot-starter-web - - org.springframework - spring-web + javax.servlet + jstl - - org.springframework - spring-jdbc + org.springframework.boot + spring-boot-starter-tomcat + provided - - org.springframework - spring-tx - - - - org.springframework - spring-context + org.apache.tomcat.embed + tomcat-embed-jasper + provided - - org.springframework - spring-beans + org.springframework.boot + spring-boot-starter-jdbc - - org.springframework.security - spring-security-core + org.springframework.boot + spring-boot-starter-security - org.springframework.security - spring-security-web + spring-security-ldap - - org.springframework.security - spring-security-config - org.apache.lucene @@ -186,19 +173,6 @@ 1.0-b2 - - log4j - log4j - 1.2.16 - runtime - - - - org.slf4j - slf4j-log4j12 - 1.6.1 - runtime - org.directwebremoting @@ -260,46 +234,12 @@ 2.5.1 - - javax.servlet - servlet-api - 2.4 - provided - - - - javax.servlet - jsp-api - 2.0 - provided - - - - javax.servlet - jstl - 1.1.2 - runtime - - javax.mail javax.mail-api 1.5.5 - - taglibs - standard - 1.1.2 - - - - taglibs - string - 1.1.0 - runtime - - com.hoodcomputing natpmp @@ -389,12 +329,28 @@ + + + + + org.springframework.boot + spring-boot-dependencies + 1.4.2.RELEASE + pom + import + + + full + + org.springframework.boot + spring-boot-maven-plugin + org.codehaus.mojo buildnumber-maven-plugin @@ -419,7 +375,20 @@ libresonic - + + org.springframework.boot + spring-boot-maven-plugin + + org.libresonic.player.boot.Application + + + + + repackage + + + + org.apache.maven.plugins maven-antrun-plugin From 2ad8ec005cd98c948378ebbc566593d11e7d07d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 11 Dec 2016 22:39:13 +0100 Subject: [PATCH 02/50] Add SpringBoot application. --- .../libresonic/player/boot/Application.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 libresonic-main/src/main/java/org/libresonic/player/boot/Application.java diff --git a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java new file mode 100644 index 00000000..56c1633a --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java @@ -0,0 +1,23 @@ +package org.libresonic.player.boot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.support.SpringBootServletInitializer; + +@SpringBootApplication +public class Application extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + // Customize the application or call application.sources(...) to add sources + // Since our example is itself a @Configuration class (via @SpringBootApplication) + // we actually don't need to override this method. + return application; + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} \ No newline at end of file From c3240b03bd9cc327253459a646a4feffd0a650ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Mon, 12 Dec 2016 21:20:01 +0100 Subject: [PATCH 03/50] Remove direct Spring dependencies (as they come from SpringBoot) --- libresonic-main/pom.xml | 12 --------- pom.xml | 57 +++++------------------------------------ 2 files changed, 7 insertions(+), 62 deletions(-) diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 906b136b..949a389a 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -296,18 +296,6 @@ - - - - - org.springframework.boot - spring-boot-dependencies - 1.4.2.RELEASE - pom - import - - - diff --git a/pom.xml b/pom.xml index aea990cd..3d6bdb47 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,6 @@ true iso-8859-1 3.1.8 - 4.3.4.RELEASE 3.2.9.RELEASE @@ -96,55 +95,12 @@ - org.springframework - spring-webmvc - ${spring.version} - - - org.springframework - spring-context - ${spring.version} - - - org.springframework - spring-web - ${spring.version} - - - org.springframework.security - spring-security-core - ${spring.security.version} - - - org.springframework.security - spring-security-web - ${spring.security.version} - - - org.springframework.security - spring-security-ldap - ${spring.security.version} - - - org.springframework.security - spring-security-config - ${spring.security.version} - jar - - - org.springframework - spring-jdbc - ${spring.version} - - - org.springframework - spring-tx - ${spring.version} - - - org.springframework - spring-beans - ${spring.version} + + org.springframework.boot + spring-boot-dependencies + 1.4.2.RELEASE + pom + import @@ -208,6 +164,7 @@ org.apache.maven.plugins maven-dependency-plugin + 2.10 analyze From 2e09bc9b75fe03c246b0dab98f9d6fce2baa9a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Wed, 14 Dec 2016 00:24:58 +0100 Subject: [PATCH 04/50] WIP Spring Boot --- libresonic-main/pom.xml | 25 +++++++++++---- .../libresonic/player/boot/Application.java | 8 +++++ .../applicationContext-cache.xml | 0 .../applicationContext-security.xml | 32 +++++++++---------- .../applicationContext-service.xml | 0 .../applicationContext-sonos.xml | 0 .../libresonic-servlet.xml | 0 7 files changed, 43 insertions(+), 22 deletions(-) rename libresonic-main/src/main/{webapp/WEB-INF => resources}/applicationContext-cache.xml (100%) rename libresonic-main/src/main/{webapp/WEB-INF => resources}/applicationContext-security.xml (73%) rename libresonic-main/src/main/{webapp/WEB-INF => resources}/applicationContext-service.xml (100%) rename libresonic-main/src/main/{webapp/WEB-INF => resources}/applicationContext-sonos.xml (100%) rename libresonic-main/src/main/{webapp/WEB-INF => resources}/libresonic-servlet.xml (100%) diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 949a389a..df895f37 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -30,23 +30,23 @@ ${project.version} - + io.dropwizard.metrics metrics-core ${metrics.version} test + - + org.springframework.boot spring-boot-starter-web - - javax.servlet - jstl - org.springframework.boot spring-boot-starter-tomcat @@ -69,7 +69,20 @@ org.springframework.security spring-security-ldap + + + + javax.servlet + jstl + 1.2 + + + taglibs + string + 1.1.0 + + org.apache.lucene diff --git a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java index 56c1633a..297e3e6d 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java +++ b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java @@ -4,8 +4,16 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; @SpringBootApplication +@Configuration +@ImportResource(value = {"classpath:/applicationContext-service.xml", + "classpath:/applicationContext-cache.xml", + "classpath:/applicationContext-sonos.xml", + "classpath:/applicationContext-security.xml", + "classpath:/libresonic-servlet.xml"}) public class Application extends SpringBootServletInitializer { @Override diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-cache.xml b/libresonic-main/src/main/resources/applicationContext-cache.xml similarity index 100% rename from libresonic-main/src/main/webapp/WEB-INF/applicationContext-cache.xml rename to libresonic-main/src/main/resources/applicationContext-cache.xml diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml b/libresonic-main/src/main/resources/applicationContext-security.xml similarity index 73% rename from libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml rename to libresonic-main/src/main/resources/applicationContext-security.xml index e8fe29a1..2bb5347a 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml +++ b/libresonic-main/src/main/resources/applicationContext-security.xml @@ -8,21 +8,21 @@ http://www.springframework.org/schema/security/spring-security.xsd"> - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -55,7 +55,7 @@ - + diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-service.xml b/libresonic-main/src/main/resources/applicationContext-service.xml similarity index 100% rename from libresonic-main/src/main/webapp/WEB-INF/applicationContext-service.xml rename to libresonic-main/src/main/resources/applicationContext-service.xml diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-sonos.xml b/libresonic-main/src/main/resources/applicationContext-sonos.xml similarity index 100% rename from libresonic-main/src/main/webapp/WEB-INF/applicationContext-sonos.xml rename to libresonic-main/src/main/resources/applicationContext-sonos.xml diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml similarity index 100% rename from libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml rename to libresonic-main/src/main/resources/libresonic-servlet.xml From 88ab70117e4ee044fdf4a12123ee78588773dd1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Wed, 14 Dec 2016 21:01:16 +0100 Subject: [PATCH 05/50] Change version to 6.2.beta1.springboot --- libresonic-assembly/pom.xml | 2 +- libresonic-booter/pom.xml | 2 +- libresonic-installer-debian/pom.xml | 2 +- libresonic-installer-mac/pom.xml | 2 +- libresonic-installer-rpm/pom.xml | 2 +- libresonic-installer-windows/pom.xml | 2 +- libresonic-main/pom.xml | 2 +- libresonic-rest-api/pom.xml | 2 +- libresonic-sonos-api/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libresonic-assembly/pom.xml b/libresonic-assembly/pom.xml index d77e8e89..e6245cad 100644 --- a/libresonic-assembly/pom.xml +++ b/libresonic-assembly/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.beta1.spring4 + 6.2.beta1.springboot diff --git a/libresonic-booter/pom.xml b/libresonic-booter/pom.xml index 8831c500..abaf4dc4 100644 --- a/libresonic-booter/pom.xml +++ b/libresonic-booter/pom.xml @@ -8,7 +8,7 @@ org.libresonic.player libresonic - 6.2.beta1.spring4 + 6.2.beta1.springboot diff --git a/libresonic-installer-debian/pom.xml b/libresonic-installer-debian/pom.xml index 39baa5f9..0cef0e1c 100644 --- a/libresonic-installer-debian/pom.xml +++ b/libresonic-installer-debian/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.beta1.spring4 + 6.2.beta1.springboot diff --git a/libresonic-installer-mac/pom.xml b/libresonic-installer-mac/pom.xml index a20abb07..da9f1c39 100644 --- a/libresonic-installer-mac/pom.xml +++ b/libresonic-installer-mac/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.beta1.spring4 + 6.2.beta1.springboot diff --git a/libresonic-installer-rpm/pom.xml b/libresonic-installer-rpm/pom.xml index 794d29b3..a9c5b6ed 100644 --- a/libresonic-installer-rpm/pom.xml +++ b/libresonic-installer-rpm/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.beta1.spring4 + 6.2.beta1.springboot diff --git a/libresonic-installer-windows/pom.xml b/libresonic-installer-windows/pom.xml index b213a361..72f293c5 100644 --- a/libresonic-installer-windows/pom.xml +++ b/libresonic-installer-windows/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.beta1.spring4 + 6.2.beta1.springboot diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 9a28397e..4d7120f8 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.beta1.spring4 + 6.2.beta1.springboot diff --git a/libresonic-rest-api/pom.xml b/libresonic-rest-api/pom.xml index e95a1a8d..dd9bab02 100644 --- a/libresonic-rest-api/pom.xml +++ b/libresonic-rest-api/pom.xml @@ -8,7 +8,7 @@ org.libresonic.player libresonic - 6.2.beta1.spring4 + 6.2.beta1.springboot diff --git a/libresonic-sonos-api/pom.xml b/libresonic-sonos-api/pom.xml index 1012b990..8c9cdbf8 100644 --- a/libresonic-sonos-api/pom.xml +++ b/libresonic-sonos-api/pom.xml @@ -8,7 +8,7 @@ org.libresonic.player libresonic - 6.2.beta1.spring4 + 6.2.beta1.springboot diff --git a/pom.xml b/pom.xml index 7d64bd46..391fce3e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.libresonic.player libresonic - 6.2.beta1.spring4 + 6.2.beta1.springboot Libresonic pom From cab1ee9b6ed6855cf394a0d67b0ec0ac4fccbfac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Wed, 14 Dec 2016 22:55:21 +0100 Subject: [PATCH 06/50] Spring Boot : make login form work again. --- libresonic-main/pom.xml | 4 ++ .../player/controller/ControllerUtils.java | 35 +++++++++++++ .../player/controller/IndexController.java | 50 +++++++++++++++++++ .../player/controller/LoginController.java | 2 +- .../player/controller/MultiController.java | 35 +------------ .../resources/applicationContext-security.xml | 6 ++- .../src/main/webapp/WEB-INF/jsp/include.jsp | 1 + .../src/main/webapp/WEB-INF/jsp/login.jsp | 4 +- pom.xml | 1 - 9 files changed, 99 insertions(+), 39 deletions(-) create mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/ControllerUtils.java create mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/IndexController.java diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 4d7120f8..bd0fe70b 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -69,6 +69,10 @@ org.springframework.security spring-security-ldap + + org.springframework.security + spring-security-taglibs + diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ControllerUtils.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ControllerUtils.java new file mode 100644 index 00000000..7f08f919 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ControllerUtils.java @@ -0,0 +1,35 @@ +package org.libresonic.player.controller; + +import org.apache.commons.lang.ObjectUtils; +import org.libresonic.player.service.SettingsService; + +import javax.servlet.http.HttpServletRequest; + +/** + * This class has been created to refactor code previously present + * in the MultiController. + */ +public class ControllerUtils { + + public static void updatePortAndContextPath(HttpServletRequest request, SettingsService settingsService) { + + int port = Integer.parseInt(System.getProperty("libresonic.port", String.valueOf(request.getLocalPort()))); + int httpsPort = Integer.parseInt(System.getProperty("libresonic.httpsPort", "0")); + + String contextPath = request.getContextPath().replace("/", ""); + + if (settingsService.getPort() != port) { + settingsService.setPort(port); + settingsService.save(); + } + if (settingsService.getHttpsPort() != httpsPort) { + settingsService.setHttpsPort(httpsPort); + settingsService.save(); + } + if (!ObjectUtils.equals(settingsService.getUrlRedirectContextPath(), contextPath)) { + settingsService.setUrlRedirectContextPath(contextPath); + settingsService.save(); + } + } + +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/IndexController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/IndexController.java new file mode 100644 index 00000000..003b364f --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/IndexController.java @@ -0,0 +1,50 @@ +package org.libresonic.player.controller; + +import org.libresonic.player.Logger; +import org.libresonic.player.domain.User; +import org.libresonic.player.domain.UserSettings; +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; + +@Controller +@RequestMapping("/index") +public class IndexController { + + + private static final Logger LOG = Logger.getLogger(IndexController.class); + + @Autowired + private SecurityService securityService; + @Autowired + private SettingsService settingsService; + + @RequestMapping(method = { RequestMethod.GET}) + public ModelAndView index(HttpServletRequest request) { + ControllerUtils.updatePortAndContextPath(request,settingsService); + UserSettings userSettings = settingsService.getUserSettings(securityService.getCurrentUsername(request)); + + Map map = new HashMap(); + map.put("showRight", userSettings.isShowNowPlayingEnabled() || userSettings.isShowChatEnabled()); + map.put("autoHidePlayQueue", userSettings.isAutoHidePlayQueue()); + map.put("listReloadDelay", userSettings.getListReloadDelay()); + map.put("keyboardShortcutsEnabled", userSettings.isKeyboardShortcutsEnabled()); + map.put("showSideBar", userSettings.isShowSideBar()); + map.put("brand", settingsService.getBrand()); + return new ModelAndView("index", "model", map); + } + + +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java index 1c74da4d..46aea3d6 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java @@ -43,7 +43,7 @@ public class LoginController { if (username != null && password != null) { username = StringUtil.urlEncode(username); password = StringUtil.urlEncode(password); - return new ModelAndView(new RedirectView("/j_spring_security_check?"+ + return new ModelAndView(new RedirectView("/login?"+ UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY+"=" + username + "&"+UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY+"=" + password )); diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java index 31dd871d..e472eb94 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java @@ -189,7 +189,7 @@ public class MultiController extends MultiActionController { } public ModelAndView gettingStarted(HttpServletRequest request, HttpServletResponse response) { - updatePortAndContextPath(request); + ControllerUtils.updatePortAndContextPath(request,settingsService); if (request.getParameter("hide") != null) { settingsService.setGettingStartedEnabled(false); @@ -202,19 +202,6 @@ public class MultiController extends MultiActionController { return new ModelAndView("gettingStarted", "model", map); } - public ModelAndView index(HttpServletRequest request, HttpServletResponse response) { - updatePortAndContextPath(request); - UserSettings userSettings = settingsService.getUserSettings(securityService.getCurrentUsername(request)); - - Map map = new HashMap(); - map.put("showRight", userSettings.isShowNowPlayingEnabled() || userSettings.isShowChatEnabled()); - map.put("autoHidePlayQueue", userSettings.isAutoHidePlayQueue()); - map.put("listReloadDelay", userSettings.getListReloadDelay()); - map.put("keyboardShortcutsEnabled", userSettings.isKeyboardShortcutsEnabled()); - map.put("showSideBar", userSettings.isShowSideBar()); - map.put("brand", settingsService.getBrand()); - return new ModelAndView("index", "model", map); - } public ModelAndView exportPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -232,26 +219,6 @@ public class MultiController extends MultiActionController { return null; } - private void updatePortAndContextPath(HttpServletRequest request) { - - int port = Integer.parseInt(System.getProperty("libresonic.port", String.valueOf(request.getLocalPort()))); - int httpsPort = Integer.parseInt(System.getProperty("libresonic.httpsPort", "0")); - - String contextPath = request.getContextPath().replace("/", ""); - - if (settingsService.getPort() != port) { - settingsService.setPort(port); - settingsService.save(); - } - if (settingsService.getHttpsPort() != httpsPort) { - settingsService.setHttpsPort(httpsPort); - settingsService.save(); - } - if (!ObjectUtils.equals(settingsService.getUrlRedirectContextPath(), contextPath)) { - settingsService.setUrlRedirectContextPath(contextPath); - settingsService.save(); - } - } public ModelAndView test(HttpServletRequest request, HttpServletResponse response) { return new ModelAndView("test"); diff --git a/libresonic-main/src/main/resources/applicationContext-security.xml b/libresonic-main/src/main/resources/applicationContext-security.xml index f1903e76..58756ca9 100644 --- a/libresonic-main/src/main/resources/applicationContext-security.xml +++ b/libresonic-main/src/main/resources/applicationContext-security.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security - http://www.springframework.org/schema/security/spring-security.xsd"> + http://www.springframework.org/schema/security/spring-security-4.1.xsd"> @@ -59,7 +59,9 @@ + always-use-default-target="true" + username-parameter="j_username" + password-parameter="j_password"/> diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/include.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/include.jsp index 5bb93d52..a92579c9 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/include.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/include.jsp @@ -4,5 +4,6 @@ <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> <%@ taglib prefix="sub" uri="http://libresonic.org/taglib/sub" %> <%@ taglib prefix="str" uri="http://jakarta.apache.org/taglibs/string-1.1" %> diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/login.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/login.jsp index 4218a07a..d3081ef7 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/login.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/login.jsp @@ -12,7 +12,9 @@ -
" method="POST"> + + +
diff --git a/pom.xml b/pom.xml index 391fce3e..9fba80a9 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,6 @@ true iso-8859-1 3.1.8 - 3.2.9.RELEASE From a51389a8d752b7899d25f6f63c9e61dda49dd02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Wed, 14 Dec 2016 23:57:12 +0100 Subject: [PATCH 07/50] import clean up --- .../java/org/libresonic/player/controller/LoginController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java index 46aea3d6..11c5a86f 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java @@ -2,7 +2,6 @@ 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; From 78022e34c36249f2a9dc9018f110a4faaf19bad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 15 Dec 2016 21:38:18 +0100 Subject: [PATCH 08/50] make index frameset work again. --- .../player/controller/HomeController.java | 98 ++++++------------- .../player/controller/LeftController.java | 78 +++++---------- .../controller/NowPlayingController.java | 40 ++++---- .../controller/PlayQueueController.java | 34 ++++--- .../player/controller/RightController.java | 46 ++++----- .../player/controller/TopController.java | 43 ++++---- .../resources/applicationContext-security.xml | 5 + .../src/main/resources/libresonic-servlet.xml | 49 ---------- 8 files changed, 137 insertions(+), 256 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/HomeController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/HomeController.java index c6b0ef68..61967d87 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/HomeController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/HomeController.java @@ -19,35 +19,18 @@ */ package org.libresonic.player.controller; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import org.libresonic.player.domain.*; +import org.libresonic.player.service.*; +import org.springframework.beans.factory.annotation.Autowired; +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.mvc.ParameterizableViewController; import org.springframework.web.servlet.view.RedirectView; -import org.libresonic.player.domain.AlbumListType; -import org.libresonic.player.domain.CoverArtScheme; -import org.libresonic.player.domain.Genre; -import org.libresonic.player.domain.MediaFile; -import org.libresonic.player.domain.MusicFolder; -import org.libresonic.player.domain.User; -import org.libresonic.player.domain.UserSettings; -import org.libresonic.player.service.MediaFileService; -import org.libresonic.player.service.MediaScannerService; -import org.libresonic.player.service.RatingService; -import org.libresonic.player.service.SearchService; -import org.libresonic.player.service.SecurityService; -import org.libresonic.player.service.SettingsService; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.util.*; import static org.springframework.web.bind.ServletRequestUtils.getIntParameter; import static org.springframework.web.bind.ServletRequestUtils.getStringParameter; @@ -57,18 +40,27 @@ import static org.springframework.web.bind.ServletRequestUtils.getStringParamete * * @author Sindre Mehus */ -public class HomeController extends ParameterizableViewController { +@Controller +@RequestMapping("/home") +public class HomeController { private static final int LIST_SIZE = 40; + @Autowired private SettingsService settingsService; + @Autowired private MediaScannerService mediaScannerService; + @Autowired private RatingService ratingService; + @Autowired private SecurityService securityService; + @Autowired private MediaFileService mediaFileService; + @Autowired private SearchService searchService; - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { + @RequestMapping(method = RequestMethod.GET) + protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception { User user = securityService.getCurrentUser(request); if (user.isAdminRole() && settingsService.isGettingStartedEnabled()) { @@ -85,7 +77,7 @@ public class HomeController extends ParameterizableViewController { List musicFolders = settingsService.getMusicFoldersForUser(user.getUsername(), selectedMusicFolder == null ? null : selectedMusicFolder.getId()); - Map map = new HashMap(); + Map map = new HashMap<>(); List albums = Collections.emptyList(); switch (listType) { case HIGHEST: @@ -142,13 +134,11 @@ public class HomeController extends ParameterizableViewController { map.put("musicFolder", selectedMusicFolder); map.put("listReloadDelay", userSettings.getListReloadDelay()); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("home","model",map); } private List getHighestRated(int offset, int count, List musicFolders) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (MediaFile mediaFile : ratingService.getHighestRatedAlbums(offset, count, musicFolders)) { Album album = createAlbum(mediaFile); album.setRating((int) Math.round(ratingService.getAverageRating(mediaFile) * 10.0D)); @@ -158,7 +148,7 @@ public class HomeController extends ParameterizableViewController { } private List getMostFrequent(int offset, int count, List musicFolders) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (MediaFile mediaFile : mediaFileService.getMostFrequentlyPlayedAlbums(offset, count, musicFolders)) { Album album = createAlbum(mediaFile); album.setPlayCount(mediaFile.getPlayCount()); @@ -168,7 +158,7 @@ public class HomeController extends ParameterizableViewController { } private List getMostRecent(int offset, int count, List musicFolders) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (MediaFile mediaFile : mediaFileService.getMostRecentlyPlayedAlbums(offset, count, musicFolders)) { Album album = createAlbum(mediaFile); album.setLastPlayed(mediaFile.getLastPlayed()); @@ -178,7 +168,7 @@ public class HomeController extends ParameterizableViewController { } private List getNewest(int offset, int count, List musicFolders) throws IOException { - List result = new ArrayList(); + List result = new ArrayList<>(); for (MediaFile file : mediaFileService.getNewestAlbums(offset, count, musicFolders)) { Album album = createAlbum(file); Date created = file.getCreated(); @@ -192,7 +182,7 @@ public class HomeController extends ParameterizableViewController { } private List getStarred(int offset, int count, String username, List musicFolders) throws IOException { - List result = new ArrayList(); + List result = new ArrayList<>(); for (MediaFile file : mediaFileService.getStarredAlbums(offset, count, username, musicFolders)) { result.add(createAlbum(file)); } @@ -200,7 +190,7 @@ public class HomeController extends ParameterizableViewController { } private List getRandom(int count, List musicFolders) throws IOException { - List result = new ArrayList(); + List result = new ArrayList<>(); for (MediaFile file : searchService.getRandomAlbums(count, musicFolders)) { result.add(createAlbum(file)); } @@ -208,7 +198,7 @@ public class HomeController extends ParameterizableViewController { } private List getAlphabetical(int offset, int count, boolean byArtist, List musicFolders) throws IOException { - List result = new ArrayList(); + List result = new ArrayList<>(); for (MediaFile file : mediaFileService.getAlphabeticalAlbums(offset, count, byArtist, musicFolders)) { result.add(createAlbum(file)); } @@ -216,7 +206,7 @@ public class HomeController extends ParameterizableViewController { } private List getByYear(int offset, int count, int fromYear, int toYear, List musicFolders) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (MediaFile file : mediaFileService.getAlbumsByYear(offset, count, fromYear, toYear, musicFolders)) { Album album = createAlbum(file); album.setYear(file.getYear()); @@ -226,7 +216,7 @@ public class HomeController extends ParameterizableViewController { } private List createDecades() { - List result = new ArrayList(); + List result = new ArrayList<>(); int decade = Calendar.getInstance().get(Calendar.YEAR) / 10; for (int i = 0; i < 10; i++) { result.add((decade - i) * 10); @@ -235,7 +225,7 @@ public class HomeController extends ParameterizableViewController { } private List getByGenre(int offset, int count, String genre, List musicFolders) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (MediaFile file : mediaFileService.getAlbumsByGenre(offset, count, genre, musicFolders)) { result.add(createAlbum(file)); } @@ -252,30 +242,6 @@ public class HomeController extends ParameterizableViewController { return album; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setMediaScannerService(MediaScannerService mediaScannerService) { - this.mediaScannerService = mediaScannerService; - } - - public void setRatingService(RatingService ratingService) { - this.ratingService = ratingService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } - - public void setSearchService(SearchService searchService) { - this.searchService = searchService; - } - /** * Contains info for a single album. */ diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/LeftController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/LeftController.java index c78490b5..8542fe44 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/LeftController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/LeftController.java @@ -19,41 +19,31 @@ */ package org.libresonic.player.controller; -import java.io.File; -import java.util.Arrays; -import java.util.Calendar; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import org.libresonic.player.domain.*; +import org.libresonic.player.service.*; +import org.libresonic.player.util.FileUtil; +import org.libresonic.player.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.ParameterizableViewController; import org.springframework.web.servlet.support.RequestContextUtils; -import org.libresonic.player.domain.InternetRadio; -import org.libresonic.player.domain.MediaLibraryStatistics; -import org.libresonic.player.domain.MusicFolder; -import org.libresonic.player.domain.MusicFolderContent; -import org.libresonic.player.domain.UserSettings; -import org.libresonic.player.service.MediaScannerService; -import org.libresonic.player.service.MusicIndexService; -import org.libresonic.player.service.PlayerService; -import org.libresonic.player.service.SecurityService; -import org.libresonic.player.service.SettingsService; -import org.libresonic.player.util.FileUtil; -import org.libresonic.player.util.StringUtil; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.util.*; /** * Controller for the left index frame. * * @author Sindre Mehus */ -public class LeftController extends ParameterizableViewController { +@Controller +@RequestMapping("/left") +public class LeftController { // Update this time if you want to force a refresh in clients. private static final Calendar LAST_COMPATIBILITY_TIME = Calendar.getInstance(); @@ -62,17 +52,22 @@ public class LeftController extends ParameterizableViewController { LAST_COMPATIBILITY_TIME.set(Calendar.MILLISECOND, 0); } + @Autowired private MediaScannerService mediaScannerService; + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; + @Autowired private MusicIndexService musicIndexService; + @Autowired private PlayerService playerService; /** * Note: This class intentionally does not implement org.springframework.web.servlet.mvc.LastModified * as we don't need browser-side caching of left.jsp. This method is only used by RESTController. */ - public long getLastModified(HttpServletRequest request) { + long getLastModified(HttpServletRequest request) { saveSelectedMusicFolder(request); if (mediaScannerService.isScanning()) { @@ -115,10 +110,10 @@ public class LeftController extends ParameterizableViewController { return lastModified; } - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { boolean musicFolderChanged = saveSelectedMusicFolder(request); - Map map = new HashMap(); + Map map = new HashMap<>(); MediaLibraryStatistics statistics = mediaScannerService.getStatistics(); Locale locale = RequestContextUtils.getLocale(request); @@ -131,7 +126,7 @@ public class LeftController extends ParameterizableViewController { String username = securityService.getCurrentUsername(request); List allMusicFolders = settingsService.getMusicFoldersForUser(username); MusicFolder selectedMusicFolder = settingsService.getSelectedMusicFolder(username); - List musicFoldersToUse = selectedMusicFolder == null ? allMusicFolders : Arrays.asList(selectedMusicFolder); + List musicFoldersToUse = selectedMusicFolder == null ? allMusicFolders : Collections.singletonList(selectedMusicFolder); UserSettings userSettings = settingsService.getUserSettings(username); MusicFolderContent musicFolderContent = musicIndexService.getMusicFolderContent(musicFoldersToUse, refresh); @@ -158,9 +153,7 @@ public class LeftController extends ParameterizableViewController { map.put("indexes", musicFolderContent.getIndexedArtists().keySet()); map.put("user", securityService.getCurrentUser(request)); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("left","model",map); } private boolean saveSelectedMusicFolder(HttpServletRequest request) { @@ -177,25 +170,4 @@ public class LeftController extends ParameterizableViewController { return true; } - - public void setMediaScannerService(MediaScannerService mediaScannerService) { - this.mediaScannerService = mediaScannerService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setMusicIndexService(MusicIndexService musicIndexService) { - this.musicIndexService = musicIndexService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/NowPlayingController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/NowPlayingController.java index 1a634bde..f3c6a01e 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/NowPlayingController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/NowPlayingController.java @@ -19,34 +19,40 @@ */ package org.libresonic.player.controller; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; -import org.springframework.web.servlet.view.RedirectView; - import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.Player; import org.libresonic.player.domain.TransferStatus; import org.libresonic.player.service.MediaFileService; import org.libresonic.player.service.PlayerService; import org.libresonic.player.service.StatusService; +import org.springframework.beans.factory.annotation.Autowired; +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.List; /** * Controller for showing what's currently playing. * * @author Sindre Mehus */ -public class NowPlayingController extends AbstractController { +@Controller +@RequestMapping("/nowPlaying") +public class NowPlayingController { + @Autowired private PlayerService playerService; + @Autowired private StatusService statusService; + @Autowired private MediaFileService mediaFileService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Player player = playerService.getPlayer(request, response); @@ -64,16 +70,4 @@ public class NowPlayingController extends AbstractController { return new ModelAndView(new RedirectView(url)); } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setStatusService(StatusService statusService) { - this.statusService = statusService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayQueueController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayQueueController.java index 069660e4..3d2e0e05 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayQueueController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayQueueController.java @@ -19,41 +19,47 @@ */ package org.libresonic.player.controller; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; - import org.libresonic.player.domain.Player; import org.libresonic.player.domain.User; import org.libresonic.player.domain.UserSettings; import org.libresonic.player.service.PlayerService; import org.libresonic.player.service.SecurityService; import org.libresonic.player.service.SettingsService; +import org.springframework.beans.factory.annotation.Autowired; +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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; /** * Controller for the playlist frame. * * @author Sindre Mehus */ -public class PlayQueueController extends ParameterizableViewController { +@Controller +@RequestMapping("/playQueue") +public class PlayQueueController { + @Autowired private PlayerService playerService; + @Autowired private SecurityService securityService; + @Autowired private SettingsService settingsService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { User user = securityService.getCurrentUser(request); UserSettings userSettings = settingsService.getUserSettings(user.getUsername()); Player player = playerService.getPlayer(request, response); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("user", user); map.put("player", player); map.put("players", playerService.getPlayersForUserAndClientId(user.getUsername(), null)); @@ -62,9 +68,7 @@ public class PlayQueueController extends ParameterizableViewController { map.put("notify", userSettings.isSongNotificationEnabled()); map.put("autoHide", userSettings.isAutoHidePlayQueue()); map.put("licenseInfo", settingsService.getLicenseInfo()); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("playQueue","model",map); } public void setPlayerService(PlayerService playerService) { diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/RightController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/RightController.java index 769765e0..31a39925 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/RightController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/RightController.java @@ -19,35 +19,40 @@ */ package org.libresonic.player.controller; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; - import org.libresonic.player.domain.UserSettings; -import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.SecurityService; +import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.VersionService; +import org.springframework.beans.factory.annotation.Autowired; +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 javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; /** * Controller for the right frame. * * @author Sindre Mehus */ -public class RightController extends ParameterizableViewController { +@Controller +@RequestMapping("/right") +public class RightController { + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; + @Autowired private VersionService versionService; - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); - ModelAndView result = super.handleRequestInternal(request, response); + @RequestMapping(method = RequestMethod.GET) + protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception { + Map map = new HashMap<>(); + ModelAndView result = new ModelAndView("right"); UserSettings userSettings = settingsService.getUserSettings(securityService.getCurrentUsername(request)); if (userSettings.isFinalVersionNotificationEnabled() && versionService.isNewFinalVersionAvailable()) { @@ -69,15 +74,4 @@ public class RightController extends ParameterizableViewController { return result; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setVersionService(VersionService versionService) { - this.versionService = versionService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/TopController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/TopController.java index 3d1a5360..0aabaa6b 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/TopController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/TopController.java @@ -19,33 +19,39 @@ */ package org.libresonic.player.controller; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; - import org.libresonic.player.domain.AvatarScheme; import org.libresonic.player.domain.User; import org.libresonic.player.domain.UserSettings; import org.libresonic.player.service.SecurityService; import org.libresonic.player.service.SettingsService; +import org.springframework.beans.factory.annotation.Autowired; +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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; /** * Controller for the top frame. * * @author Sindre Mehus */ -public class TopController extends ParameterizableViewController { +@Controller +@RequestMapping("/top") +public class TopController { + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + @RequestMapping(method = RequestMethod.GET) + protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception { + Map map = new HashMap<>(); User user = securityService.getCurrentUser(request); UserSettings userSettings = settingsService.getUserSettings(user.getUsername()); @@ -53,17 +59,6 @@ public class TopController extends ParameterizableViewController { map.put("user", user); map.put("showSideBar", userSettings.isShowSideBar()); map.put("showAvatar", userSettings.getAvatarScheme() != AvatarScheme.NONE); - - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; + return new ModelAndView("top","model", map); } } diff --git a/libresonic-main/src/main/resources/applicationContext-security.xml b/libresonic-main/src/main/resources/applicationContext-security.xml index 58756ca9..d5b193ab 100644 --- a/libresonic-main/src/main/resources/applicationContext-security.xml +++ b/libresonic-main/src/main/resources/applicationContext-security.xml @@ -8,6 +8,11 @@ http://www.springframework.org/schema/security/spring-security-4.1.xsd"> + + + + + diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 2a8fd8cc..7f1cfe91 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,20 +15,6 @@ - - - - - - - - - - - - - - @@ -58,11 +44,6 @@ - - - - - @@ -148,11 +129,6 @@ - - - - - @@ -196,26 +172,11 @@ - - - - - - - - - - - - - - - @@ -338,8 +299,6 @@ playlistsController helpController lyricsController - leftController - rightController statusController moreController uploadController @@ -348,20 +307,14 @@ setMusicFileInfoController shareManagementController setRatingController - topController randomPlayQueueController changeCoverArtController - multiController multiController multiController multiController multiController videoPlayerController - nowPlayingController starredController settingsController dlnaSettingsController @@ -371,9 +324,7 @@ internetRadioSettingsController avatarUploadController allmusicController - homeController editTagsController - playQueueController coverArtController avatarController proxyController From adfde5dae0f3e94f19744957cb6ad94adf0607ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 15 Dec 2016 21:47:18 +0100 Subject: [PATCH 09/50] New GettingStarted controller --- .../controller/GettingStartedController.java | 61 +++++++++++++++++++ .../player/controller/MultiController.java | 13 ---- .../src/main/resources/libresonic-servlet.xml | 1 - 3 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/GettingStartedController.java diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/GettingStartedController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/GettingStartedController.java new file mode 100644 index 00000000..673966c7 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/GettingStartedController.java @@ -0,0 +1,61 @@ +/* + This file is part of Libresonic. + + Libresonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Libresonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Libresonic. If not, see . + + Copyright 2016 (C) Libresonic Authors + Based upon Subsonic, Copyright 2009 (C) Sindre Mehus + */ +package org.libresonic.player.controller; + +import org.libresonic.player.domain.AvatarScheme; +import org.libresonic.player.domain.User; +import org.libresonic.player.domain.UserSettings; +import org.libresonic.player.service.SecurityService; +import org.libresonic.player.service.SettingsService; +import org.springframework.beans.factory.annotation.Autowired; +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; + +@Controller +@RequestMapping("/gettingStarted") +public class GettingStartedController { + + @Autowired + private SettingsService settingsService; + + @RequestMapping(method = RequestMethod.GET) + public ModelAndView gettingStarted(HttpServletRequest request) { + ControllerUtils.updatePortAndContextPath(request,settingsService); + + if (request.getParameter("hide") != null) { + settingsService.setGettingStartedEnabled(false); + settingsService.save(); + return new ModelAndView(new RedirectView("home.view")); + } + + Map map = new HashMap<>();; + map.put("runningAsRoot", "root".equals(System.getProperty("user.name"))); + return new ModelAndView("gettingStarted", "model", map); + } + +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java index e472eb94..896c9e13 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java @@ -188,19 +188,6 @@ public class MultiController extends MultiActionController { return new ModelAndView("notFound"); } - public ModelAndView gettingStarted(HttpServletRequest request, HttpServletResponse response) { - ControllerUtils.updatePortAndContextPath(request,settingsService); - - if (request.getParameter("hide") != null) { - settingsService.setGettingStartedEnabled(false); - settingsService.save(); - return new ModelAndView(new RedirectView("home.view")); - } - - Map map = new HashMap(); - map.put("runningAsRoot", "root".equals(System.getProperty("user.name"))); - return new ModelAndView("gettingStarted", "model", map); - } public ModelAndView exportPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception { diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 7f1cfe91..d056d2e7 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -312,7 +312,6 @@ multiController multiController multiController - multiController multiController videoPlayerController starredController From 5b8e2b94c15012f57295e7fd401506efea021e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 15 Dec 2016 23:06:05 +0100 Subject: [PATCH 10/50] Controllers migration. --- .../player/controller/CoverArtController.java | 117 ++++++------------ .../player/controller/MainController.java | 98 +++++---------- .../MusicFolderSettingsController.java | 7 +- .../player/controller/SettingsController.java | 34 ++--- .../resources/applicationContext-security.xml | 52 ++++---- .../src/main/resources/libresonic-servlet.xml | 23 ---- 6 files changed, 120 insertions(+), 211 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/CoverArtController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/CoverArtController.java index 239bc225..7e8d59ab 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/CoverArtController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/CoverArtController.java @@ -19,62 +19,45 @@ */ package org.libresonic.player.controller; -import java.awt.Color; -import java.awt.Font; -import java.awt.GradientPaint; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Semaphore; - -import javax.imageio.ImageIO; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; -import org.springframework.web.bind.ServletRequestUtils; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.Controller; -import org.springframework.web.servlet.mvc.LastModified; - import org.libresonic.player.Logger; import org.libresonic.player.dao.AlbumDao; import org.libresonic.player.dao.ArtistDao; -import org.libresonic.player.domain.Album; -import org.libresonic.player.domain.Artist; -import org.libresonic.player.domain.CoverArtScheme; -import org.libresonic.player.domain.MediaFile; -import org.libresonic.player.domain.Playlist; -import org.libresonic.player.domain.PodcastChannel; -import org.libresonic.player.domain.Transcoding; -import org.libresonic.player.domain.VideoTranscodingSettings; -import org.libresonic.player.service.MediaFileService; -import org.libresonic.player.service.PlaylistService; -import org.libresonic.player.service.PodcastService; -import org.libresonic.player.service.SettingsService; -import org.libresonic.player.service.TranscodingService; +import org.libresonic.player.domain.*; +import org.libresonic.player.service.*; import org.libresonic.player.service.metadata.JaudiotaggerParser; import org.libresonic.player.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.ServletRequestUtils; +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.mvc.LastModified; + +import javax.annotation.PostConstruct; +import javax.imageio.ImageIO; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.*; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.Semaphore; /** * Controller which produces cover art images. * * @author Sindre Mehus */ -public class CoverArtController implements Controller, LastModified { +@Controller +@RequestMapping("/coverArt") +public class CoverArtController implements LastModified { public static final String ALBUM_COVERART_PREFIX = "al-"; public static final String ARTIST_COVERART_PREFIX = "ar-"; @@ -83,26 +66,34 @@ public class CoverArtController implements Controller, LastModified { private static final Logger LOG = Logger.getLogger(CoverArtController.class); + @Autowired private MediaFileService mediaFileService; + @Autowired private TranscodingService transcodingService; + @Autowired private SettingsService settingsService; + @Autowired private PlaylistService playlistService; + @Autowired private PodcastService podcastService; + @Autowired private ArtistDao artistDao; + @Autowired private AlbumDao albumDao; private Semaphore semaphore; + @PostConstruct public void init() { semaphore = new Semaphore(settingsService.getCoverArtConcurrency()); } public long getLastModified(HttpServletRequest request) { CoverArtRequest coverArtRequest = createCoverArtRequest(request); - long result = coverArtRequest.lastModified(); -// LOG.info("getLastModified - " + coverArtRequest + ": " + new Date(result)); - return result; + // LOG.info("getLastModified - " + coverArtRequest + ": " + new Date(result)); + return coverArtRequest.lastModified(); } + @RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { CoverArtRequest coverArtRequest = createCoverArtRequest(request); @@ -341,33 +332,6 @@ public class CoverArtController implements Controller, LastModified { return thumb; } - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } - - public void setArtistDao(ArtistDao artistDao) { - this.artistDao = artistDao; - } - - public void setAlbumDao(AlbumDao albumDao) { - this.albumDao = albumDao; - } - - public void setTranscodingService(TranscodingService transcodingService) { - this.transcodingService = transcodingService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } - - public void setPodcastService(PodcastService podcastService) { - this.podcastService = podcastService; - } private abstract class CoverArtRequest { @@ -551,7 +515,7 @@ public class CoverArtController implements Controller, LastModified { albums.add(album); } } - return new ArrayList(albums); + return new ArrayList<>(albums); } } @@ -559,7 +523,7 @@ public class CoverArtController implements Controller, LastModified { private final PodcastChannel channel; - public PodcastCoverArtRequest(PodcastChannel channel) { + PodcastCoverArtRequest(PodcastChannel channel) { this.channel = channel; } @@ -633,7 +597,8 @@ public class CoverArtController implements Controller, LastModified { @Override public BufferedImage createImage(int size) { - int height = size; + int height; + height = size; int width = height * 16 / 9; InputStream in = null; try { @@ -687,7 +652,7 @@ public class CoverArtController implements Controller, LastModified { private final int height; private final Color color; - public AutoCover(Graphics2D graphics, String key, String artist, String album, int width, int height) { + AutoCover(Graphics2D graphics, String key, String artist, String album, int width, int height) { this.graphics = graphics; this.artist = artist; this.album = album; diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/MainController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/MainController.java index 68217c85..29511e23 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/MainController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/MainController.java @@ -19,54 +19,47 @@ */ package org.libresonic.player.controller; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import org.libresonic.player.domain.*; +import org.libresonic.player.service.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.AbstractController; import org.springframework.web.servlet.view.RedirectView; -import org.libresonic.player.domain.CoverArtScheme; -import org.libresonic.player.domain.MediaFile; -import org.libresonic.player.domain.MediaFileComparator; -import org.libresonic.player.domain.MusicFolder; -import org.libresonic.player.domain.Player; -import org.libresonic.player.domain.UserSettings; -import org.libresonic.player.service.AdService; -import org.libresonic.player.service.MediaFileService; -import org.libresonic.player.service.PlayerService; -import org.libresonic.player.service.RatingService; -import org.libresonic.player.service.SecurityService; -import org.libresonic.player.service.SettingsService; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; /** * Controller for the main page. * * @author Sindre Mehus */ -public class MainController extends AbstractController { +@Controller +@RequestMapping("/main") +public class MainController { + @Autowired private SecurityService securityService; + @Autowired private PlayerService playerService; + @Autowired private SettingsService settingsService; + @Autowired private RatingService ratingService; + @Autowired private MediaFileService mediaFileService; + @Autowired private AdService adService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); Player player = playerService.getPlayer(request, response); List mediaFiles = getMediaFiles(request); @@ -91,8 +84,8 @@ public class MainController extends AbstractController { } List children = mediaFiles.size() == 1 ? mediaFileService.getChildrenOf(dir, true, true, true) : getMultiFolderChildren(mediaFiles); - List files = new ArrayList(); - List subDirs = new ArrayList(); + List files = new ArrayList<>(); + List subDirs = new ArrayList<>(); for (MediaFile child : children) { if (child.isFile()) { files.add(child); @@ -159,9 +152,7 @@ public class MainController extends AbstractController { view = "artistMain"; } - ModelAndView result = new ModelAndView(view); - result.addObject("model", map); - return result; + return new ModelAndView(view,"model",map); } private boolean isViewAsList(HttpServletRequest request, UserSettings userSettings) { @@ -188,7 +179,7 @@ public class MainController extends AbstractController { } private List getMediaFiles(HttpServletRequest request) { - List mediaFiles = new ArrayList(); + List mediaFiles = new ArrayList<>(); for (String path : ServletRequestUtils.getStringParameters(request, "path")) { MediaFile mediaFile = mediaFileService.getMediaFile(path); if (mediaFile != null) { @@ -223,18 +214,18 @@ public class MainController extends AbstractController { } private List getMultiFolderChildren(List mediaFiles) throws IOException { - SortedSet result = new TreeSet(new MediaFileComparator(settingsService.isSortAlbumsByYear())); + SortedSet result = new TreeSet<>(new MediaFileComparator(settingsService.isSortAlbumsByYear())); for (MediaFile mediaFile : mediaFiles) { if (mediaFile.isFile()) { mediaFile = mediaFileService.getParentOf(mediaFile); } result.addAll(mediaFileService.getChildrenOf(mediaFile, true, true, true)); } - return new ArrayList(result); + return new ArrayList<>(result); } private List getAncestors(MediaFile dir) throws IOException { - LinkedList result = new LinkedList(); + LinkedList result = new LinkedList<>(); try { MediaFile parent = mediaFileService.getParentOf(dir); @@ -249,41 +240,14 @@ public class MainController extends AbstractController { } private List getSieblingAlbums(MediaFile dir) { - List result = new ArrayList(); + List result = new ArrayList<>(); MediaFile parent = mediaFileService.getParentOf(dir); if (!mediaFileService.isRoot(parent)) { List sieblings = mediaFileService.getChildrenOf(parent, false, true, true); - for (MediaFile siebling : sieblings) { - if (siebling.isAlbum() && !siebling.equals(dir)) { - result.add(siebling); - } - } + result.addAll(sieblings.stream().filter(siebling -> siebling.isAlbum() && !siebling.equals(dir)).collect(Collectors.toList())); } return result; } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setRatingService(RatingService ratingService) { - this.ratingService = ratingService; - } - - public void setAdService(AdService adService) { - this.adService = adService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/MusicFolderSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/MusicFolderSettingsController.java index 47a66562..96bebde1 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/MusicFolderSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/MusicFolderSettingsController.java @@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestParam; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * Controller for the page used to administrate the set of music folders. @@ -97,11 +98,7 @@ public class MusicFolderSettingsController { } private List wrap(List musicFolders) { - ArrayList result = new ArrayList(); - for (MusicFolder musicFolder : musicFolders) { - result.add(new MusicFolderSettingsCommand.MusicFolderInfo(musicFolder)); - } - return result; + return musicFolders.stream().map(MusicFolderSettingsCommand.MusicFolderInfo::new).collect(Collectors.toCollection(ArrayList::new)); } @RequestMapping(method = RequestMethod.POST) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SettingsController.java index ce4910bf..647d3145 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SettingsController.java @@ -19,35 +19,41 @@ */ package org.libresonic.player.controller; -import org.libresonic.player.domain.*; -import org.libresonic.player.service.*; -import org.springframework.web.servlet.*; -import org.springframework.web.servlet.view.*; -import org.springframework.web.servlet.mvc.*; - -import javax.servlet.http.*; +import org.libresonic.player.domain.User; +import org.libresonic.player.service.SecurityService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestAttribute; +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.mvc.AbstractController; +import org.springframework.web.servlet.view.RedirectView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; /** * Controller for the main settings page. * * @author Sindre Mehus */ -public class SettingsController extends AbstractController { +@Controller +@RequestMapping("/settings") +public class SettingsController { + @Autowired private SecurityService securityService; - - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { +@RequestMapping(method = RequestMethod.GET) + protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception { User user = securityService.getCurrentUser(request); // Redirect to music folder settings if admin. - String view = user.isAdminRole() ? "musicFolderSettings.view" : "personalSettings.view"; + String view = user.isAdminRole() ? "musicFolderSettings" : "personalSettings"; return new ModelAndView(new RedirectView(view)); } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } } diff --git a/libresonic-main/src/main/resources/applicationContext-security.xml b/libresonic-main/src/main/resources/applicationContext-security.xml index d5b193ab..442c9c9c 100644 --- a/libresonic-main/src/main/resources/applicationContext-security.xml +++ b/libresonic-main/src/main/resources/applicationContext-security.xml @@ -29,35 +29,35 @@ - - - - - + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index d056d2e7..a61f71e5 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -19,14 +19,6 @@ - - - - - - - - @@ -137,9 +129,6 @@ - - - @@ -177,15 +166,6 @@ - - - - - - - - - @@ -294,7 +274,6 @@ - mainController playlistController playlistsController helpController @@ -315,7 +294,6 @@ multiController videoPlayerController starredController - settingsController dlnaSettingsController sonosSettingsController shareSettingsController @@ -324,7 +302,6 @@ avatarUploadController allmusicController editTagsController - coverArtController avatarController proxyController statusChartController From 627a8a934156444d6d8440cf99e430fced0781fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 15 Dec 2016 23:16:20 +0100 Subject: [PATCH 11/50] Controllers migration. --- .../player/controller/PodcastController.java | 36 ++++++++----------- .../src/main/resources/libresonic-servlet.xml | 7 ---- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastController.java index 929f679e..4c0abe8f 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastController.java @@ -25,37 +25,42 @@ 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.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.mvc.ParameterizableViewController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; /** * Controller for the page used to generate the Podcast XML file. * * @author Sindre Mehus */ -public class PodcastController extends ParameterizableViewController { +@Controller +@RequestMapping("/podcast") +public class PodcastController { private static final DateFormat RSS_DATE_FORMAT = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US); + @Autowired private PlaylistService playlistService; + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String url = request.getRequestURL().toString(); String username = securityService.getCurrentUsername(request); List playlists = playlistService.getReadablePlaylistsForUser(username); - List podcasts = new ArrayList(); + List podcasts = new ArrayList<>(); for (Playlist playlist : playlists) { @@ -85,27 +90,16 @@ public class PodcastController extends ParameterizableViewController { podcasts.add(new Podcast(playlist.getName(), publishDate, enclosureUrl, length, type)); } - Map map = new HashMap(); + Map map = new HashMap<>(); - ModelAndView result = super.handleRequestInternal(request, response); map.put("url", url); map.put("podcasts", podcasts); - result.addObject("model", map); - return result; + return new ModelAndView("podcast","model",map); } - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } /** * Contains information about a single Podcast. diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index a61f71e5..33f062f2 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -62,12 +62,6 @@ - - - - - - @@ -312,7 +306,6 @@ podcastChannelsController podcastChannelController podcastReceiverAdminController - podcastController podcastController downloadController wapController From 010815a57813489e13728ce9f8a76191d6dff32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Fri, 16 Dec 2016 00:02:02 +0100 Subject: [PATCH 12/50] Controllers migration. --- .../player/controller/HelpController.java | 28 +++++++-------- .../controller/ImportPlaylistController.java | 22 ++++++------ .../player/controller/PlaylistController.java | 34 ++++++++---------- .../controller/PlaylistsController.java | 19 +++++----- .../player/controller/StatusController.java | 35 +++++++++---------- .../src/main/resources/libresonic-servlet.xml | 32 ----------------- 6 files changed, 64 insertions(+), 106 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/HelpController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/HelpController.java index 24f0c27a..d46dabb7 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/HelpController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/HelpController.java @@ -25,6 +25,10 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +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.mvc.ParameterizableViewController; @@ -38,15 +42,20 @@ import org.libresonic.player.service.VersionService; * * @author Sindre Mehus */ -public class HelpController extends ParameterizableViewController { +@Controller +@RequestMapping("/help") +public class HelpController { + @Autowired private VersionService versionService; + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); if (versionService.isNewFinalVersionAvailable()) { map.put("newVersionAvailable", true); @@ -75,20 +84,9 @@ public class HelpController extends ParameterizableViewController { map.put("logEntries", Logger.getLatestLogEntries()); map.put("logFile", Logger.getLogFile()); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("help","model",map); } - public void setVersionService(VersionService versionService) { - this.versionService = versionService; - } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ImportPlaylistController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ImportPlaylistController.java index 3f44959a..b379e081 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ImportPlaylistController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ImportPlaylistController.java @@ -32,6 +32,10 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +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.mvc.ParameterizableViewController; @@ -42,14 +46,18 @@ import org.libresonic.player.service.SecurityService; /** * @author Sindre Mehus */ -public class ImportPlaylistController extends ParameterizableViewController { +@Controller +@RequestMapping("/importPlaylist") +public class ImportPlaylistController { private static final long MAX_PLAYLIST_SIZE_MB = 5L; + @Autowired private SecurityService securityService; + @Autowired private PlaylistService playlistService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -79,16 +87,8 @@ public class ImportPlaylistController extends ParameterizableViewController { map.put("error", e.getMessage()); } - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("importPlaylist","model",map); } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java index 138ba550..aa950fd3 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java @@ -27,7 +27,11 @@ import org.libresonic.player.service.PlayerService; import org.libresonic.player.service.PlaylistService; import org.libresonic.player.service.SecurityService; import org.libresonic.player.service.SettingsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.ParameterizableViewController; import org.springframework.web.servlet.view.RedirectView; @@ -42,16 +46,22 @@ import java.util.Map; * * @author Sindre Mehus */ -public class PlaylistController extends ParameterizableViewController { +@Controller +@RequestMapping("/playlist") +public class PlaylistController { + @Autowired private SecurityService securityService; + @Autowired private PlaylistService playlistService; + @Autowired private SettingsService settingsService; + @Autowired private PlayerService playerService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); User user = securityService.getCurrentUser(request); @@ -60,7 +70,7 @@ public class PlaylistController extends ParameterizableViewController { Player player = playerService.getPlayer(request, response); Playlist playlist = playlistService.getPlaylist(id); if (playlist == null) { - return new ModelAndView(new RedirectView("notFound.view")); + return new ModelAndView(new RedirectView("notFound")); } map.put("playlist", playlist); @@ -69,24 +79,10 @@ public class PlaylistController extends ParameterizableViewController { map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username)); map.put("partyMode", userSettings.isPartyModeEnabled()); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("playList","model",map); } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistsController.java index 3afbb1f1..daa19cfb 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistsController.java @@ -25,7 +25,10 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.ParameterizableViewController; import org.springframework.web.servlet.view.RedirectView; @@ -44,29 +47,25 @@ import org.libresonic.player.service.SettingsService; * * @author Sindre Mehus */ +@Controller +@RequestMapping("/playlists") public class PlaylistsController extends ParameterizableViewController { + @Autowired private SecurityService securityService; + @Autowired private PlaylistService playlistService; @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); User user = securityService.getCurrentUser(request); List playlists = playlistService.getReadablePlaylistsForUser(user.getUsername()); map.put("playlists", playlists); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("playlists","model",map); } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/StatusController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/StatusController.java index 5cf59354..a0eff1c9 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/StatusController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/StatusController.java @@ -24,37 +24,39 @@ import org.libresonic.player.domain.TransferStatus; import org.libresonic.player.service.StatusService; import org.libresonic.player.util.FileUtil; import org.libresonic.player.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +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.mvc.ParameterizableViewController; import org.springframework.web.servlet.support.RequestContextUtils; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; /** * Controller for the status page. * * @author Sindre Mehus */ -public class StatusController extends ParameterizableViewController { +@Controller +@RequestMapping("/status") +public class StatusController { + @Autowired private StatusService statusService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); List streamStatuses = statusService.getAllStreamStatuses(); List downloadStatuses = statusService.getAllDownloadStatuses(); List uploadStatuses = statusService.getAllUploadStatuses(); Locale locale = RequestContextUtils.getLocale(request); - List transferStatuses = new ArrayList(); + List transferStatuses = new ArrayList<>(); for (int i = 0; i < streamStatuses.size(); i++) { long minutesAgo = streamStatuses.get(i).getMillisSinceLastUpdate() / 1000L / 60L; @@ -73,16 +75,11 @@ public class StatusController extends ParameterizableViewController { map.put("chartWidth", StatusChartController.IMAGE_WIDTH); map.put("chartHeight", StatusChartController.IMAGE_HEIGHT); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("status","model",map); } - public void setStatusService(StatusService statusService) { - this.statusService = statusService; - } - public static class TransferStatusHolder { + private static class TransferStatusHolder { private TransferStatus transferStatus; private boolean isStream; private boolean isDownload; @@ -90,8 +87,8 @@ public class StatusController extends ParameterizableViewController { private int index; private Locale locale; - public TransferStatusHolder(TransferStatus transferStatus, boolean isStream, boolean isDownload, boolean isUpload, - int index, Locale locale) { + TransferStatusHolder(TransferStatus transferStatus, boolean isStream, boolean isDownload, boolean isUpload, + int index, Locale locale) { this.transferStatus = transferStatus; this.isStream = isStream; this.isDownload = isDownload; diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index cb12d7ad..089916bf 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,33 +15,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -249,14 +222,9 @@ - playlistController - playlistsController - helpController lyricsController - statusController moreController uploadController - importPlaylistController multiController setMusicFileInfoController shareManagementController From 8231a440894baf59b822d354d6afd3f68f6dc8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 17 Dec 2016 14:11:47 +0100 Subject: [PATCH 13/50] Controllers migration. --- .../player/controller/LyricsController.java | 14 ++-- .../player/controller/MoreController.java | 54 ++++++-------- .../player/controller/UploadController.java | 73 ++++++++++--------- .../src/main/resources/libresonic-servlet.xml | 20 ----- 4 files changed, 71 insertions(+), 90 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/LyricsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/LyricsController.java index 838dcae0..2a3c5698 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/LyricsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/LyricsController.java @@ -19,6 +19,9 @@ */ package org.libresonic.player.controller; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.mvc.ParameterizableViewController; import org.springframework.web.servlet.ModelAndView; @@ -32,16 +35,17 @@ import java.util.HashMap; * * @author Sindre Mehus */ -public class LyricsController extends ParameterizableViewController { +@Controller +@RequestMapping("/lyrics") +public class LyricsController { + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("artist", request.getParameter("artist")); map.put("song", request.getParameter("song")); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("lyrics","model",map); } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/MoreController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/MoreController.java index 5b7a3c99..cae21dff 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/MoreController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/MoreController.java @@ -19,18 +19,6 @@ */ package org.libresonic.player.controller; -import java.io.File; -import java.util.Calendar; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; - import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.domain.Player; import org.libresonic.player.domain.User; @@ -39,21 +27,41 @@ import org.libresonic.player.service.PlayerService; 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.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Controller for the "more" page. * * @author Sindre Mehus */ -public class MoreController extends ParameterizableViewController { +@Controller +@RequestMapping("/more") +public class MoreController { + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; + @Autowired private PlayerService playerService; + @Autowired private MediaFileService mediaFileService; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); User user = securityService.getCurrentUser(request); @@ -72,7 +80,7 @@ public class MoreController extends ParameterizableViewController { } Player player = playerService.getPlayer(request, response); - ModelAndView result = super.handleRequestInternal(request, response); + ModelAndView result = new ModelAndView(); result.addObject("model", map); map.put("user", user); map.put("uploadDirectory", uploadDirectory); @@ -84,20 +92,4 @@ public class MoreController extends ParameterizableViewController { map.put("jamstashUrl", jamstashUrl); return result; } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/UploadController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/UploadController.java index 19dc60bd..921d9076 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/UploadController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/UploadController.java @@ -19,20 +19,33 @@ */ package org.libresonic.player.controller; -import org.libresonic.player.*; -import org.libresonic.player.domain.*; -import org.libresonic.player.upload.*; -import org.libresonic.player.service.*; -import org.libresonic.player.util.*; -import org.apache.commons.fileupload.*; -import org.apache.commons.fileupload.servlet.*; -import org.apache.commons.io.*; -import org.apache.tools.zip.*; -import org.springframework.web.servlet.*; -import org.springframework.web.servlet.mvc.*; - -import javax.servlet.http.*; -import java.io.*; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.FileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.io.IOUtils; +import org.apache.tools.zip.ZipEntry; +import org.apache.tools.zip.ZipFile; +import org.libresonic.player.Logger; +import org.libresonic.player.domain.TransferStatus; +import org.libresonic.player.domain.User; +import org.libresonic.player.service.PlayerService; +import org.libresonic.player.service.SecurityService; +import org.libresonic.player.service.SettingsService; +import org.libresonic.player.service.StatusService; +import org.libresonic.player.upload.MonitoredDiskFileItemFactory; +import org.libresonic.player.upload.UploadListener; +import org.libresonic.player.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; import java.util.*; /** @@ -40,22 +53,28 @@ import java.util.*; * * @author Sindre Mehus */ -public class UploadController extends ParameterizableViewController { +@org.springframework.stereotype.Controller +@RequestMapping("/upload") +public class UploadController { private static final Logger LOG = Logger.getLogger(UploadController.class); + @Autowired private SecurityService securityService; + @Autowired private PlayerService playerService; + @Autowired private StatusService statusService; + @Autowired private SettingsService settingsService; public static final String UPLOAD_STATUS = "uploadStatus"; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); - List uploadedFiles = new ArrayList(); - List unzippedFiles = new ArrayList(); + Map map = new HashMap<>(); + List uploadedFiles = new ArrayList<>(); + List unzippedFiles = new ArrayList<>(); TransferStatus status = null; try { @@ -139,9 +158,7 @@ public class UploadController extends ParameterizableViewController { map.put("uploadedFiles", uploadedFiles); map.put("unzippedFiles", unzippedFiles); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("upload","model",map); } private void unzip(File file, List unzippedFiles) throws Exception { @@ -196,21 +213,9 @@ public class UploadController extends ParameterizableViewController { } } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - public void setStatusService(StatusService statusService) { - this.statusService = statusService; - } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } /** * Receives callbacks as the file upload progresses. diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 089916bf..16194673 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,23 +15,6 @@ - - - - - - - - - - - - - - - - - @@ -222,9 +205,6 @@ - lyricsController - moreController - uploadController multiController setMusicFileInfoController shareManagementController From 2c63e287df7b439d95fb2546c39c6b842aaa5670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 17 Dec 2016 14:15:27 +0100 Subject: [PATCH 14/50] Controllers migration. --- .../player/controller/AllmusicController.java | 14 ++++++++++---- .../src/main/resources/libresonic-servlet.xml | 4 ---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/AllmusicController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/AllmusicController.java index ec1d1012..d259a612 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/AllmusicController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/AllmusicController.java @@ -19,8 +19,11 @@ */ package org.libresonic.player.controller; -import org.springframework.web.servlet.*; -import org.springframework.web.servlet.mvc.*; + +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 javax.servlet.http.*; @@ -29,10 +32,13 @@ import javax.servlet.http.*; * * @author Sindre Mehus */ -public class AllmusicController extends ParameterizableViewController { +@Controller +@RequestMapping("/allmusic") +public class AllmusicController { + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - ModelAndView result = super.handleRequestInternal(request, response); + ModelAndView result = new ModelAndView(); result.addObject("album", request.getParameter("album")); return result; } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 16194673..763adc54 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,9 +15,6 @@ - - - @@ -222,7 +219,6 @@ transcodingSettingsController internetRadioSettingsController avatarUploadController - allmusicController editTagsController avatarController proxyController From 1ac243b49b45543d59439ecc8cd3b5184051725b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 17 Dec 2016 17:05:02 +0100 Subject: [PATCH 15/50] Controllers migration. --- .../controller/PodcastChannelsController.java | 49 +++++++++---------- .../src/main/resources/libresonic-servlet.xml | 7 --- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastChannelsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastChannelsController.java index 1dff8955..eeb898a2 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastChannelsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastChannelsController.java @@ -18,43 +18,49 @@ */ package org.libresonic.player.controller; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; - import org.libresonic.player.domain.PodcastChannel; import org.libresonic.player.domain.PodcastEpisode; import org.libresonic.player.service.PodcastService; import org.libresonic.player.service.SecurityService; import org.libresonic.player.service.SettingsService; +import org.springframework.beans.factory.annotation.Autowired; +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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; /** * Controller for the "Podcast channels" page. * * @author Sindre Mehus */ -public class PodcastChannelsController extends ParameterizableViewController { +@Controller +@RequestMapping("/podcastChannels") +public class PodcastChannelsController { + @Autowired private PodcastService podcastService; + @Autowired private SecurityService securityService; + @Autowired private SettingsService settingsService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); - ModelAndView result = super.handleRequestInternal(request, response); + Map map = new HashMap<>(); + ModelAndView result = new ModelAndView(); result.addObject("model", map); - Map> channels = new LinkedHashMap>(); - Map channelMap = new HashMap(); + Map> channels = new LinkedHashMap<>(); + Map channelMap = new HashMap<>(); for (PodcastChannel channel : podcastService.getAllChannels()) { channels.put(channel, podcastService.getEpisodes(channel.getId())); channelMap.put(channel.getId(), channel); @@ -68,15 +74,6 @@ public class PodcastChannelsController extends ParameterizableViewController { return result; } - public void setPodcastService(PodcastService podcastService) { - this.podcastService = podcastService; - } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 763adc54..f23195ec 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,12 +15,6 @@ - - - - - - @@ -227,7 +221,6 @@ downloadController dbController multiController - podcastChannelsController podcastChannelController podcastReceiverAdminController podcastController From caac4561719141f2a4f07a2c7704c945bf7bbc4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 17 Dec 2016 19:11:32 +0100 Subject: [PATCH 16/50] Controllers migration. --- .../controller/PodcastChannelController.java | 38 +++++++++---------- .../src/main/resources/libresonic-servlet.xml | 6 --- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastChannelController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastChannelController.java index 8ddbb583..4bd8c089 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastChannelController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastChannelController.java @@ -19,34 +19,39 @@ package org.libresonic.player.controller; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import org.libresonic.player.service.PodcastService; +import org.libresonic.player.service.SecurityService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.ParameterizableViewController; -import org.libresonic.player.service.PodcastService; -import org.libresonic.player.service.SecurityService; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; /** * Controller for the "Podcast channel" page. * * @author Sindre Mehus */ -public class PodcastChannelController extends ParameterizableViewController { +@Controller +@RequestMapping("/podcastChannel") +public class PodcastChannelController { + @Autowired private PodcastService podcastService; + @Autowired private SecurityService securityService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); - ModelAndView result = super.handleRequestInternal(request, response); + Map map = new HashMap<>(); + ModelAndView result = new ModelAndView(); result.addObject("model", map); int channelId = ServletRequestUtils.getRequiredIntParameter(request, "id"); @@ -57,11 +62,4 @@ public class PodcastChannelController extends ParameterizableViewController { return result; } - public void setPodcastService(PodcastService podcastService) { - this.podcastService = podcastService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index f23195ec..814eca82 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,11 +15,6 @@ - - - - - @@ -221,7 +216,6 @@ downloadController dbController multiController - podcastChannelController podcastReceiverAdminController podcastController downloadController From 97be70531e53fff7ce7e539bd95b27d03fcb048b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 17 Dec 2016 19:15:00 +0100 Subject: [PATCH 17/50] Controllers migration. --- .../PodcastReceiverAdminController.java | 20 +++++++++---------- .../src/main/resources/libresonic-servlet.xml | 4 ---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastReceiverAdminController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastReceiverAdminController.java index 7c7858c2..f3b19093 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastReceiverAdminController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastReceiverAdminController.java @@ -19,32 +19,35 @@ */ package org.libresonic.player.controller; +import org.apache.commons.lang.StringUtils; import org.libresonic.player.domain.PodcastEpisode; import org.libresonic.player.domain.PodcastStatus; import org.libresonic.player.service.PodcastService; import org.libresonic.player.util.StringUtil; -import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.AbstractController; import org.springframework.web.servlet.view.RedirectView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; /** * Controller for the "Podcast receiver" page. * * @author Sindre Mehus */ -public class PodcastReceiverAdminController extends AbstractController { +@Controller +@RequestMapping("/podcastReceiverAdmin") +public class PodcastReceiverAdminController { + @Autowired private PodcastService podcastService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Integer channelId = ServletRequestUtils.getIntParameter(request, "channelId"); @@ -93,7 +96,4 @@ public class PodcastReceiverAdminController extends AbstractController { } } - public void setPodcastService(PodcastService podcastService) { - this.podcastService = podcastService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 814eca82..fc15cd5b 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,9 +15,6 @@ - - - @@ -216,7 +213,6 @@ downloadController dbController multiController - podcastReceiverAdminController podcastController downloadController wapController From f90de5e31007b837806865e221cbf59bc93e28a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 18 Dec 2016 00:08:05 +0100 Subject: [PATCH 18/50] Controllers migration. --- .../SetMusicFileInfoController.java | 26 ++++++++++--------- .../src/main/resources/libresonic-servlet.xml | 4 --- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SetMusicFileInfoController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SetMusicFileInfoController.java index d7edb47d..5a54e271 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SetMusicFileInfoController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SetMusicFileInfoController.java @@ -19,28 +19,33 @@ */ package org.libresonic.player.controller; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import org.libresonic.player.domain.MediaFile; +import org.libresonic.player.service.MediaFileService; +import org.libresonic.player.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.AbstractController; import org.springframework.web.servlet.view.RedirectView; -import org.libresonic.player.domain.MediaFile; -import org.libresonic.player.service.MediaFileService; -import org.libresonic.player.util.StringUtil; +import javax.servlet.http.HttpServletRequest; /** * Controller for updating music file metadata. * * @author Sindre Mehus */ -public class SetMusicFileInfoController extends AbstractController { +@Controller +@RequestMapping("/setMusicFileInfo") +public class SetMusicFileInfoController { + @Autowired private MediaFileService mediaFileService; - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { + @RequestMapping(method = RequestMethod.GET) + protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); String action = request.getParameter("action"); @@ -55,7 +60,4 @@ public class SetMusicFileInfoController extends AbstractController { return new ModelAndView(new RedirectView(url)); } - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index fc15cd5b..d8692963 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,9 +15,6 @@ - - - @@ -189,7 +186,6 @@ multiController - setMusicFileInfoController shareManagementController setRatingController changeCoverArtController From 70ed378ae09763b7134adae265589f3bd183cbd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 18 Dec 2016 00:12:16 +0100 Subject: [PATCH 19/50] Controllers migration. --- .../controller/ShareManagementController.java | 54 ++++++------------- .../src/main/resources/libresonic-servlet.xml | 9 ---- 2 files changed, 17 insertions(+), 46 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ShareManagementController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ShareManagementController.java index f1bab574..aad11bdd 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ShareManagementController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ShareManagementController.java @@ -23,39 +23,42 @@ import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.PlayQueue; import org.libresonic.player.domain.Player; import org.libresonic.player.domain.Share; -import org.libresonic.player.service.MediaFileService; -import org.libresonic.player.service.PlayerService; -import org.libresonic.player.service.PlaylistService; -import org.libresonic.player.service.SecurityService; -import org.libresonic.player.service.SettingsService; -import org.libresonic.player.service.ShareService; +import org.libresonic.player.service.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.multiaction.MultiActionController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Controller for sharing music on Twitter, Facebook etc. * * @author Sindre Mehus */ -public class ShareManagementController extends MultiActionController { +@Controller +@RequestMapping("/createShare") +public class ShareManagementController { + @Autowired private MediaFileService mediaFileService; + @Autowired private SettingsService settingsService; + @Autowired private ShareService shareService; + @Autowired private PlayerService playerService; + @Autowired private PlaylistService playlistService; + @Autowired private SecurityService securityService; + @RequestMapping(method = RequestMethod.GET) public ModelAndView createShare(HttpServletRequest request, HttpServletResponse response) throws Exception { List files = getMediaFiles(request); @@ -95,7 +98,7 @@ public class ShareManagementController extends MultiActionController { String playerId = request.getParameter("player"); Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist"); - List result = new ArrayList(); + List result = new ArrayList<>(); if (id != null) { MediaFile album = mediaFileService.getMediaFile(id); @@ -122,27 +125,4 @@ public class ShareManagementController extends MultiActionController { return result; } - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setShareService(ShareService shareService) { - this.shareService = shareService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index d8692963..f26e2ccd 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,14 +15,6 @@ - - - - - - - - @@ -186,7 +178,6 @@ multiController - shareManagementController setRatingController changeCoverArtController multiController From 42709b0e0d3ad6e63dbb894efb85e1c92d61f3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 18 Dec 2016 01:07:35 +0100 Subject: [PATCH 20/50] Controllers migration. --- .../controller/ChangeCoverArtController.java | 16 ++++---- .../controller/SetRatingController.java | 39 ++++++++----------- .../src/main/resources/libresonic-servlet.xml | 11 ------ 3 files changed, 24 insertions(+), 42 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java index 9e977ea2..fed59892 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java @@ -25,7 +25,10 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.ParameterizableViewController; @@ -37,11 +40,13 @@ import org.libresonic.player.service.MediaFileService; * * @author Sindre Mehus */ -public class ChangeCoverArtController extends ParameterizableViewController { +@Controller +@RequestMapping("/changeCoverArt") +public class ChangeCoverArtController { + @Autowired private MediaFileService mediaFileService; - @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); @@ -61,13 +66,8 @@ public class ChangeCoverArtController extends ParameterizableViewController { map.put("artist", artist); map.put("album", album); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("changeCoverArt","model",map); } - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java index d7962dfc..091e23ad 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java @@ -19,53 +19,46 @@ */ package org.libresonic.player.controller; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.bind.ServletRequestUtils; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; -import org.springframework.web.servlet.view.RedirectView; - import org.libresonic.player.domain.MediaFile; import org.libresonic.player.service.MediaFileService; import org.libresonic.player.service.RatingService; import org.libresonic.player.service.SecurityService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.view.RedirectView; + +import javax.servlet.http.HttpServletRequest; /** * Controller for updating music file ratings. * * @author Sindre Mehus */ -public class SetRatingController extends AbstractController { +@Controller +@RequestMapping("/setRating") +public class SetRatingController { + @Autowired private RatingService ratingService; + @Autowired private SecurityService securityService; + @Autowired private MediaFileService mediaFileService; - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { + + protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); Integer rating = ServletRequestUtils.getIntParameter(request, "rating"); if (rating == 0) { rating = null; } - MediaFile mediaFile = mediaFileService.getMediaFile(id); String username = securityService.getCurrentUsername(request); ratingService.setRatingForUser(username, mediaFile, rating); return new ModelAndView(new RedirectView("main.view?id=" + id)); } - - public void setRatingService(RatingService ratingService) { - this.ratingService = ratingService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index f26e2ccd..7d3c42bf 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,15 +15,6 @@ - - - - - - - - - @@ -178,8 +169,6 @@ multiController - setRatingController - changeCoverArtController multiController multiController multiController From 2767d06731d1d41629e8b94123be2b630f83085a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 18 Dec 2016 01:14:33 +0100 Subject: [PATCH 21/50] Controllers migration. --- .../controller/ChangeCoverArtController.java | 19 ++++--- .../controller/SetRatingController.java | 2 + .../player/controller/StarredController.java | 52 +++++++------------ .../src/main/resources/libresonic-servlet.xml | 9 ---- 4 files changed, 29 insertions(+), 53 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java index fed59892..6a021d17 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java @@ -19,21 +19,19 @@ */ package org.libresonic.player.controller; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import org.libresonic.player.domain.MediaFile; +import org.libresonic.player.service.MediaFileService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; 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.mvc.ParameterizableViewController; -import org.libresonic.player.domain.MediaFile; -import org.libresonic.player.service.MediaFileService; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; /** * Controller for changing cover art. @@ -47,6 +45,7 @@ public class ChangeCoverArtController { @Autowired private MediaFileService mediaFileService; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); @@ -61,7 +60,7 @@ public class ChangeCoverArtController { album = dir.getAlbumName(); } - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("id", id); map.put("artist", artist); map.put("album", album); diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java index 091e23ad..9ac974cc 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; 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; @@ -49,6 +50,7 @@ public class SetRatingController { private MediaFileService mediaFileService; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); Integer rating = ServletRequestUtils.getIntParameter(request, "rating"); diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/StarredController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/StarredController.java index 20818b97..147cd3b5 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/StarredController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/StarredController.java @@ -20,21 +20,19 @@ package org.libresonic.player.controller; import org.libresonic.player.dao.MediaFileDao; -import org.libresonic.player.domain.CoverArtScheme; -import org.libresonic.player.domain.MediaFile; -import org.libresonic.player.domain.MusicFolder; -import org.libresonic.player.domain.User; -import org.libresonic.player.domain.UserSettings; +import org.libresonic.player.domain.*; import org.libresonic.player.service.MediaFileService; import org.libresonic.player.service.PlayerService; import org.libresonic.player.service.SecurityService; import org.libresonic.player.service.SettingsService; +import org.springframework.beans.factory.annotation.Autowired; +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.mvc.ParameterizableViewController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -45,17 +43,24 @@ import java.util.Map; * * @author Sindre Mehus */ -public class StarredController extends ParameterizableViewController { +@Controller +@RequestMapping("/starred") +public class StarredController { + @Autowired private PlayerService playerService; + @Autowired private MediaFileDao mediaFileDao; + @Autowired private SecurityService securityService; + @Autowired private SettingsService settingsService; + @Autowired private MediaFileService mediaFileService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); + Map map = new HashMap<>(); User user = securityService.getCurrentUser(request); String username = user.getUsername(); @@ -69,8 +74,8 @@ public class StarredController extends ParameterizableViewController { mediaFileService.populateStarredDate(albums, username); mediaFileService.populateStarredDate(files, username); - List songs = new ArrayList(); - List videos = new ArrayList(); + List songs = new ArrayList<>(); + List videos = new ArrayList<>(); for (MediaFile file : files) { (file.isVideo() ? videos : songs).add(file); } @@ -83,28 +88,7 @@ public class StarredController extends ParameterizableViewController { map.put("albums", albums); map.put("songs", songs); map.put("videos", videos); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; + return new ModelAndView("starred","model",map); } - public void setMediaFileDao(MediaFileDao mediaFileDao) { - this.mediaFileDao = mediaFileDao; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 7d3c42bf..ab2adc2d 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,14 +15,6 @@ - - - - - - - - @@ -174,7 +166,6 @@ multiController multiController videoPlayerController - starredController dlnaSettingsController sonosSettingsController shareSettingsController From 449f6a906abe2a8a9ba353d8a79676d97bbf1dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 18 Dec 2016 01:31:39 +0100 Subject: [PATCH 22/50] Controllers migration. --- .../controller/AvatarUploadController.java | 22 +++++----- .../controller/DLNASettingsController.java | 22 +++++----- .../player/controller/EditTagsController.java | 43 +++++++++--------- .../InternetRadioSettingsController.java | 19 ++++---- .../controller/ShareSettingsController.java | 33 ++++++-------- .../controller/SonosSettingsController.java | 23 +++++----- .../TranscodingSettingsController.java | 23 +++++----- .../src/main/resources/libresonic-servlet.xml | 44 ------------------- 8 files changed, 87 insertions(+), 142 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarUploadController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarUploadController.java index 1c829ba9..b20d469c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarUploadController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarUploadController.java @@ -30,6 +30,10 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +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.mvc.ParameterizableViewController; @@ -50,15 +54,19 @@ import java.util.Map; * * @author Sindre Mehus */ -public class AvatarUploadController extends ParameterizableViewController { +@Controller +@RequestMapping("/avatarUpload") +public class AvatarUploadController { private static final Logger LOG = Logger.getLogger(AvatarUploadController.class); private static final int MAX_AVATAR_SIZE = 64; + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String username = securityService.getCurrentUsername(request); @@ -93,9 +101,7 @@ public class AvatarUploadController extends ParameterizableViewController { map.put("username", username); map.put("avatar", settingsService.getCustomAvatar(username)); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("avatarUploadResult","model",map); } private void createAvatar(String fileName, byte[] data, String username, Map map) throws IOException { @@ -132,11 +138,5 @@ public class AvatarUploadController extends ParameterizableViewController { } } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/DLNASettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/DLNASettingsController.java index 8995c462..4b1deaca 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/DLNASettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/DLNASettingsController.java @@ -25,7 +25,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.ParameterizableViewController; @@ -37,12 +41,16 @@ import org.libresonic.player.service.UPnPService; * * @author Sindre Mehus */ -public class DLNASettingsController extends ParameterizableViewController { +@Controller +@RequestMapping("/dlnaSettings") +public class DLNASettingsController { + @Autowired private UPnPService upnpService; + @Autowired private SettingsService settingsService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -52,13 +60,11 @@ public class DLNASettingsController extends ParameterizableViewController { map.put("toast", true); } - ModelAndView result = super.handleRequestInternal(request, response); map.put("dlnaEnabled", settingsService.isDlnaEnabled()); map.put("dlnaServerName", settingsService.getDlnaServerName()); map.put("licenseInfo", settingsService.getLicenseInfo()); - result.addObject("model", map); - return result; + return new ModelAndView("dlnaSettings","model",map); } /** @@ -85,11 +91,5 @@ public class DLNASettingsController extends ParameterizableViewController { upnpService.setMediaServerEnabled(dlnaEnabled); } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - public void setUpnpService(UPnPService upnpService) { - this.upnpService = upnpService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/EditTagsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/EditTagsController.java index 19f5365d..1edacc7c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/EditTagsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/EditTagsController.java @@ -19,35 +19,41 @@ */ package org.libresonic.player.controller; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.io.FilenameUtils; -import org.springframework.web.bind.ServletRequestUtils; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; - import org.libresonic.player.domain.MediaFile; import org.libresonic.player.service.MediaFileService; import org.libresonic.player.service.metadata.JaudiotaggerParser; import org.libresonic.player.service.metadata.MetaDataParser; import org.libresonic.player.service.metadata.MetaDataParserFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Controller for the page used to edit MP3 tags. * * @author Sindre Mehus */ -public class EditTagsController extends ParameterizableViewController { +@Controller +@RequestMapping("/editTags") +public class EditTagsController { + @Autowired private MetaDataParserFactory metaDataParserFactory; + @Autowired private MediaFileService mediaFileService; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); @@ -70,9 +76,7 @@ public class EditTagsController extends ParameterizableViewController { map.put("id", id); map.put("songs", songs); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("editTags","model",map); } private Song createSong(MediaFile file, int index) { @@ -92,13 +96,6 @@ public class EditTagsController extends ParameterizableViewController { return song; } - public void setMetaDataParserFactory(MetaDataParserFactory metaDataParserFactory) { - this.metaDataParserFactory = metaDataParserFactory; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } /** * Contains information about a single song. diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/InternetRadioSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/InternetRadioSettingsController.java index 649605b9..3ae969bd 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/InternetRadioSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/InternetRadioSettingsController.java @@ -22,6 +22,10 @@ package org.libresonic.player.controller; import org.libresonic.player.domain.InternetRadio; import org.libresonic.player.service.SettingsService; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +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.mvc.ParameterizableViewController; @@ -37,11 +41,14 @@ import java.util.Map; * * @author Sindre Mehus */ -public class InternetRadioSettingsController extends ParameterizableViewController { +@Controller +@RequestMapping("/internetRadioSettings") +public class InternetRadioSettingsController { + @Autowired private SettingsService settingsService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -54,11 +61,8 @@ public class InternetRadioSettingsController extends ParameterizableViewControll } } - ModelAndView result = super.handleRequestInternal(request, response); map.put("internetRadios", settingsService.getAllInternetRadios(true)); - - result.addObject("model", map); - return result; + return new ModelAndView("internetRadioSettings","model",map); } /** @@ -116,8 +120,5 @@ public class InternetRadioSettingsController extends ParameterizableViewControll return StringUtils.trimToNull(request.getParameter(name + "[" + id + "]")); } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ShareSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ShareSettingsController.java index 19113a73..b753b743 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ShareSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ShareSettingsController.java @@ -30,7 +30,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.ParameterizableViewController; @@ -48,14 +52,20 @@ import org.libresonic.player.service.ShareService; * * @author Sindre Mehus */ -public class ShareSettingsController extends ParameterizableViewController { +@Controller +@RequestMapping("/shareSettings") +public class ShareSettingsController { + @Autowired private ShareService shareService; + @Autowired private SecurityService securityService; + @Autowired private MediaFileService mediaFileService; + @Autowired private SettingsService settingsService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -65,14 +75,12 @@ public class ShareSettingsController extends ParameterizableViewController { map.put("toast", true); } - ModelAndView result = super.handleRequestInternal(request, response); map.put("shareBaseUrl", shareService.getShareBaseUrl()); map.put("shareInfos", getShareInfos(request)); map.put("user", securityService.getCurrentUser(request)); map.put("licenseInfo", settingsService.getLicenseInfo()); - result.addObject("model", map); - return result; + return new ModelAndView("shareSettings","model",map); } /** @@ -148,21 +156,6 @@ public class ShareSettingsController extends ParameterizableViewController { return calendar.getTime(); } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setShareService(ShareService shareService) { - this.shareService = shareService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } public static class ShareInfo { private final Share share; diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SonosSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SonosSettingsController.java index eb8226b6..36cc02e8 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SonosSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SonosSettingsController.java @@ -25,7 +25,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.ParameterizableViewController; @@ -37,12 +41,16 @@ import org.libresonic.player.service.SonosService; * * @author Sindre Mehus */ -public class SonosSettingsController extends ParameterizableViewController { +@Controller +@RequestMapping("/sonosSettings") +public class SonosSettingsController { + @Autowired private SettingsService settingsService; + @Autowired private SonosService sonosService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -52,13 +60,11 @@ public class SonosSettingsController extends ParameterizableViewController { map.put("toast", true); } - ModelAndView result = super.handleRequestInternal(request, response); map.put("sonosEnabled", settingsService.isSonosEnabled()); map.put("sonosServiceName", settingsService.getSonosServiceName()); map.put("licenseInfo", settingsService.getLicenseInfo()); - result.addObject("model", map); - return result; + return new ModelAndView("sonosSettings","model",map); } /** @@ -86,11 +92,4 @@ public class SonosSettingsController extends ParameterizableViewController { sonosService.setMusicServiceEnabled(sonosEnabled); } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setSonosService(SonosService sonosService) { - this.sonosService = sonosService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/TranscodingSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/TranscodingSettingsController.java index bd28e172..68b1dfb6 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/TranscodingSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/TranscodingSettingsController.java @@ -23,6 +23,10 @@ import org.libresonic.player.domain.Transcoding; import org.libresonic.player.service.TranscodingService; import org.libresonic.player.service.SettingsService; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +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.mvc.ParameterizableViewController; @@ -36,12 +40,16 @@ import java.util.Map; * * @author Sindre Mehus */ -public class TranscodingSettingsController extends ParameterizableViewController { +@Controller +@RequestMapping("/transcodingSettings") +public class TranscodingSettingsController { + @Autowired private TranscodingService transcodingService; + @Autowired private SettingsService settingsService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -51,15 +59,13 @@ public class TranscodingSettingsController extends ParameterizableViewController map.put("toast", true); } - ModelAndView result = super.handleRequestInternal(request, response); map.put("transcodings", transcodingService.getAllTranscodings()); map.put("transcodeDirectory", transcodingService.getTranscodeDirectory()); map.put("downsampleCommand", settingsService.getDownsamplingCommand()); map.put("hlsCommand", settingsService.getHlsCommand()); map.put("brand", settingsService.getBrand()); - result.addObject("model", map); - return result; + return new ModelAndView("transcodingSettings","model",map); } /** @@ -136,11 +142,4 @@ public class TranscodingSettingsController extends ParameterizableViewController return StringUtils.trimToNull(request.getParameter(name + "[" + id + "]")); } - public void setTranscodingService(TranscodingService transcodingService) { - this.transcodingService = transcodingService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index ab2adc2d..e19ca95e 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,43 +15,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -166,13 +129,6 @@ multiController multiController videoPlayerController - dlnaSettingsController - sonosSettingsController - shareSettingsController - transcodingSettingsController - internetRadioSettingsController - avatarUploadController - editTagsController avatarController proxyController statusChartController From 2bb026b96849b3ac4ee033b2c91884b55e1e9e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 22 Dec 2016 21:47:31 +0100 Subject: [PATCH 23/50] Controller migration --- .../player/controller/AvatarController.java | 14 +++++++++----- .../src/main/resources/libresonic-servlet.xml | 4 ---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarController.java index a8f10951..18ba9f3f 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/AvatarController.java @@ -22,9 +22,12 @@ package org.libresonic.player.controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.Controller; import org.springframework.web.servlet.mvc.LastModified; import org.libresonic.player.domain.Avatar; @@ -37,8 +40,11 @@ import org.libresonic.player.service.SettingsService; * * @author Sindre Mehus */ -public class AvatarController implements Controller, LastModified { +@Controller +@RequestMapping("/avatar") +public class AvatarController implements LastModified { + @Autowired private SettingsService settingsService; public long getLastModified(HttpServletRequest request) { @@ -54,6 +60,7 @@ public class AvatarController implements Controller, LastModified { return result; } + @RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { Avatar avatar = getAvatar(request); @@ -87,7 +94,4 @@ public class AvatarController implements Controller, LastModified { return settingsService.getSystemAvatar(userSettings.getSystemAvatarId()); } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index e19ca95e..00671755 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,9 +15,6 @@ - - - @@ -129,7 +126,6 @@ multiController multiController videoPlayerController - avatarController proxyController statusChartController userChartController From 217caba28f0fbade140a6f2cecca2862e2d9d366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 22 Dec 2016 21:49:44 +0100 Subject: [PATCH 24/50] Controller migration --- .../player/controller/ProxyController.java | 18 +++++++++++------- .../src/main/resources/libresonic-servlet.xml | 2 -- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ProxyController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ProxyController.java index 552aae50..4ced7605 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ProxyController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ProxyController.java @@ -19,11 +19,6 @@ */ package org.libresonic.player.controller; -import java.io.InputStream; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.io.IOUtils; import org.apache.http.HttpStatus; import org.apache.http.client.config.RequestConfig; @@ -31,17 +26,26 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.Controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; /** * A proxy for external HTTP requests. * * @author Sindre Mehus */ -public class ProxyController implements Controller { +@Controller +@RequestMapping("/proxy") +public class ProxyController { + @RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String url = ServletRequestUtils.getRequiredStringParameter(request, "url"); diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 00671755..aaacd4ca 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,7 +15,6 @@ - @@ -126,7 +125,6 @@ multiController multiController videoPlayerController - proxyController statusChartController userChartController downloadController From 8c81778f5a8e7fedb6107a88c56ecd3d943b4012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 22 Dec 2016 21:54:12 +0100 Subject: [PATCH 25/50] Controller migration --- .../player/controller/AbstractChartController.java | 2 +- .../player/controller/StatusChartController.java | 11 ++++++++--- .../player/controller/UserChartController.java | 11 ++++++++--- .../src/main/resources/libresonic-servlet.xml | 8 -------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/AbstractChartController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/AbstractChartController.java index eb5f9eed..28fa58cc 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/AbstractChartController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/AbstractChartController.java @@ -32,7 +32,7 @@ import java.util.*; * * @author Sindre Mehus */ -public abstract class AbstractChartController implements Controller { +public abstract class AbstractChartController { /** * Returns the chart background color for the current theme. diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/StatusChartController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/StatusChartController.java index bd0366dd..be555e63 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/StatusChartController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/StatusChartController.java @@ -27,6 +27,10 @@ import org.jfree.chart.plot.*; import org.jfree.chart.renderer.xy.*; import org.jfree.data.*; import org.jfree.data.time.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.*; import javax.servlet.http.*; @@ -39,13 +43,17 @@ import java.util.List; * * @author Sindre Mehus */ +@Controller +@RequestMapping("/statusChart") public class StatusChartController extends AbstractChartController { + @Autowired private StatusService statusService; public static final int IMAGE_WIDTH = 350; public static final int IMAGE_HEIGHT = 150; + @RequestMapping(method = RequestMethod.GET) public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String type = request.getParameter("type"); int index = Integer.parseInt(request.getParameter("index")); @@ -144,7 +152,4 @@ public class StatusChartController extends AbstractChartController { return null; } - public void setStatusService(StatusService statusService) { - this.statusService = statusService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/UserChartController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/UserChartController.java index cdb00a7c..812ae823 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/UserChartController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/UserChartController.java @@ -39,6 +39,10 @@ import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; +import org.springframework.beans.factory.annotation.Autowired; +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.libresonic.player.domain.User; @@ -49,14 +53,18 @@ import org.libresonic.player.service.SecurityService; * * @author Sindre Mehus */ +@Controller +@RequestMapping("/userChart") public class UserChartController extends AbstractChartController { + @Autowired private SecurityService securityService; public static final int IMAGE_WIDTH = 400; public static final int IMAGE_MIN_HEIGHT = 200; private static final long BYTES_PER_MB = 1024L * 1024L; + @RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String type = request.getParameter("type"); CategoryDataset dataset = createDataset(type); @@ -140,7 +148,4 @@ public class UserChartController extends AbstractChartController { return chart; } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index aaacd4ca..e2cafc86 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,12 +15,6 @@ - - - - - - @@ -125,8 +119,6 @@ multiController multiController videoPlayerController - statusChartController - userChartController downloadController dbController multiController From b8ade50810f87e46f5ee09b53f9622fbc5f282cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 22 Dec 2016 21:58:46 +0100 Subject: [PATCH 26/50] Controller migration --- .../player/controller/M3UController.java | 40 +++++++++---------- .../src/main/resources/libresonic-servlet.xml | 6 --- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/M3UController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/M3UController.java index e04cd4ad..b11cc354 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/M3UController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/M3UController.java @@ -19,16 +19,6 @@ */ package org.libresonic.player.controller; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.Controller; - import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.PlayQueue; import org.libresonic.player.domain.Player; @@ -36,18 +26,35 @@ import org.libresonic.player.service.PlayerService; import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.TranscodingService; import org.libresonic.player.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; /** * Controller which produces the M3U playlist. * * @author Sindre Mehus */ -public class M3UController implements Controller { +@Controller +@RequestMapping("/play.m3u") +public class M3UController { + @Autowired private PlayerService playerService; + @Autowired private SettingsService settingsService; + @Autowired private TranscodingService transcodingService; + @RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("audio/x-mpegurl"); response.setCharacterEncoding(StringUtil.ENCODING_UTF8); @@ -115,15 +122,4 @@ public class M3UController implements Controller { return playQueue.isEmpty() ? null : transcodingService.getSuffix(player, playQueue.getFile(0), null); } - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setTranscodingService(TranscodingService transcodingService) { - this.transcodingService = transcodingService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index e2cafc86..6a9618fb 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,11 +15,6 @@ - - - - - @@ -126,7 +121,6 @@ downloadController wapController restController - m3uController streamController hlsController externalPlayerController From b2dd04e864b0bfd3e951b9c0d472814b298370d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 22 Dec 2016 22:17:48 +0100 Subject: [PATCH 27/50] Controller migration --- .../controller/AccessDeniedController.java | 28 ++++ .../controller/ExportPlayListController.java | 51 +++++++ .../player/controller/NotFoundController.java | 28 ++++ ...Controller.java => RecoverController.java} | 131 +++++------------- .../player/controller/TestController.java | 28 ++++ .../src/main/resources/libresonic-servlet.xml | 11 -- 6 files changed, 169 insertions(+), 108 deletions(-) create mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/AccessDeniedController.java create mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/ExportPlayListController.java create mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/NotFoundController.java rename libresonic-main/src/main/java/org/libresonic/player/controller/{MultiController.java => RecoverController.java} (65%) create mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/TestController.java diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/AccessDeniedController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/AccessDeniedController.java new file mode 100644 index 00000000..f36fd526 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/AccessDeniedController.java @@ -0,0 +1,28 @@ +package org.libresonic.player.controller; + +import org.libresonic.player.Logger; +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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Spring MVC Controller that serves the login page. + */ +@Controller +@RequestMapping("/accessDenied") +public class AccessDeniedController { + + + private static final Logger LOG = Logger.getLogger(AccessDeniedController.class); + + @RequestMapping(method = {RequestMethod.GET}) + public ModelAndView accessDenied(HttpServletRequest request, HttpServletResponse response) { + return new ModelAndView("accessDenied"); + } + + +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ExportPlayListController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ExportPlayListController.java new file mode 100644 index 00000000..b03a5afb --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ExportPlayListController.java @@ -0,0 +1,51 @@ +package org.libresonic.player.controller; + +import org.libresonic.player.Logger; +import org.libresonic.player.domain.Playlist; +import org.libresonic.player.service.PlaylistService; +import org.libresonic.player.service.SecurityService; +import org.libresonic.player.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Spring MVC Controller that serves the login page. + */ +@Controller +@RequestMapping("/exportPlaylist") +public class ExportPlayListController { + + + private static final Logger LOG = Logger.getLogger(ExportPlayListController.class); + + @Autowired + private PlaylistService playlistService; + @Autowired + private SecurityService securityService; + + @RequestMapping(method = { RequestMethod.GET }) + public ModelAndView exportPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception { + + int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); + Playlist playlist = playlistService.getPlaylist(id); + if (!playlistService.isReadAllowed(playlist, securityService.getCurrentUsername(request))) { + response.sendError(HttpServletResponse.SC_FORBIDDEN); + return null; + + } + response.setContentType("application/x-download"); + response.setHeader("Content-Disposition", "attachment; filename=\"" + StringUtil.fileSystemSafe(playlist.getName()) + ".m3u8\""); + + playlistService.exportPlaylist(id, response.getOutputStream()); + return null; + } + + +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/NotFoundController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/NotFoundController.java new file mode 100644 index 00000000..fd1d13cd --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/NotFoundController.java @@ -0,0 +1,28 @@ +package org.libresonic.player.controller; + +import org.libresonic.player.Logger; +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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Spring MVC Controller that serves the login page. + */ +@Controller +@RequestMapping("/notFound") +public class NotFoundController { + + + private static final Logger LOG = Logger.getLogger(NotFoundController.class); + + @RequestMapping(method = {RequestMethod.GET}) + public ModelAndView notFound(HttpServletRequest request, HttpServletResponse response) { + return new ModelAndView("notFound"); + } + + +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/RecoverController.java similarity index 65% rename from libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java rename to libresonic-main/src/main/java/org/libresonic/player/controller/RecoverController.java index 896c9e13..26abeae7 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/RecoverController.java @@ -1,69 +1,48 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ package org.libresonic.player.controller; -import javax.mail.Message; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import net.tanesha.recaptcha.ReCaptcha; import net.tanesha.recaptcha.ReCaptchaFactory; import net.tanesha.recaptcha.ReCaptchaResponse; -import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.StringUtils; import org.libresonic.player.Logger; -import org.libresonic.player.domain.Playlist; import org.libresonic.player.domain.User; -import org.libresonic.player.domain.UserSettings; -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.security.web.authentication.UsernamePasswordAuthenticationFilter; -import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.beans.factory.annotation.Autowired; +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.mvc.multiaction.MultiActionController; -import org.springframework.web.servlet.view.RedirectView; +import javax.mail.Message; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Properties; /** - * Multi-controller used for simple pages. - * - * @author Sindre Mehus + * Spring MVC Controller that serves the login page. */ -public class MultiController extends MultiActionController { +@Controller +@RequestMapping("/recover") +public class RecoverController { - private static final Logger LOG = Logger.getLogger(MultiController.class); - private SecurityService securityService; + private static final Logger LOG = Logger.getLogger(RecoverController.class); + + @Autowired private SettingsService settingsService; - private PlaylistService playlistService; + @Autowired + private SecurityService securityService; + @RequestMapping(method = {RequestMethod.GET}) public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -107,9 +86,20 @@ public class MultiController extends MultiActionController { return new ModelAndView("recover", "model", map); } + private User getUserByUsernameOrEmail(String usernameOrEmail) { + if (usernameOrEmail != null) { + User user = securityService.getUserByName(usernameOrEmail); + if (user != null) { + return user; + } + return securityService.getUserByEmail(usernameOrEmail); + } + return null; + } + /* - * e-mail user new password via configured Smtp server - */ + * e-mail user new password via configured Smtp server + */ private boolean emailPassword(String password, String username, String email) { /* Default to protocol smtp when SmtpEncryption is set to "None" */ String prot = "smtp"; @@ -169,57 +159,4 @@ public class MultiController extends MultiActionController { } } - private User getUserByUsernameOrEmail(String usernameOrEmail) { - if (usernameOrEmail != null) { - User user = securityService.getUserByName(usernameOrEmail); - if (user != null) { - return user; - } - return securityService.getUserByEmail(usernameOrEmail); - } - return null; - } - - public ModelAndView accessDenied(HttpServletRequest request, HttpServletResponse response) { - return new ModelAndView("accessDenied"); - } - - public ModelAndView notFound(HttpServletRequest request, HttpServletResponse response) { - return new ModelAndView("notFound"); - } - - - - public ModelAndView exportPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception { - - int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); - Playlist playlist = playlistService.getPlaylist(id); - if (!playlistService.isReadAllowed(playlist, securityService.getCurrentUsername(request))) { - response.sendError(HttpServletResponse.SC_FORBIDDEN); - return null; - - } - response.setContentType("application/x-download"); - response.setHeader("Content-Disposition", "attachment; filename=\"" + StringUtil.fileSystemSafe(playlist.getName()) + ".m3u8\""); - - playlistService.exportPlaylist(id, response.getOutputStream()); - return null; - } - - - public ModelAndView test(HttpServletRequest request, HttpServletResponse response) { - return new ModelAndView("test"); - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/TestController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/TestController.java new file mode 100644 index 00000000..85609368 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/TestController.java @@ -0,0 +1,28 @@ +package org.libresonic.player.controller; + +import org.libresonic.player.Logger; +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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Spring MVC Controller that serves the login page. + */ +@Controller +@RequestMapping("/test") +public class TestController { + + + private static final Logger LOG = Logger.getLogger(TestController.class); + + @RequestMapping(method = {RequestMethod.GET}) + public ModelAndView test(HttpServletRequest request, HttpServletResponse response) { + return new ModelAndView("test"); + } + + +} diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 6a9618fb..d3d25ccf 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -53,11 +53,6 @@ - - - - - @@ -108,15 +103,9 @@ - multiController - multiController - multiController - multiController - multiController videoPlayerController downloadController dbController - multiController podcastController downloadController wapController From d8919d9cb97d334e65f0239f977adf7afee6c4c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 22 Dec 2016 23:57:15 +0100 Subject: [PATCH 28/50] Fix after merge. --- .../libresonic/player/controller/ChangeCoverArtController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java index f8ffa7f5..7206e5d1 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java @@ -19,6 +19,7 @@ */ package org.libresonic.player.controller; +import org.apache.commons.lang.StringUtils; import org.libresonic.player.domain.MediaFile; import org.libresonic.player.service.MediaFileService; import org.springframework.beans.factory.annotation.Autowired; From ed7758acabca62118e4b883b01bb4293d0adbae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Fri, 23 Dec 2016 01:31:29 +0100 Subject: [PATCH 29/50] registration of dwr servlet --- .../java/org/libresonic/player/boot/Application.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java index 297e3e6d..28b75c8e 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java +++ b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java @@ -1,9 +1,12 @@ package org.libresonic.player.boot; +import org.directwebremoting.servlet.DwrServlet; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; @@ -16,6 +19,14 @@ import org.springframework.context.annotation.ImportResource; "classpath:/libresonic-servlet.xml"}) public class Application extends SpringBootServletInitializer { + @Bean + public ServletRegistrationBean dwrServletRegistrationBean() { + ServletRegistrationBean servlet = new ServletRegistrationBean(new DwrServlet(), "/dwr/*"); + servlet.addInitParameter("crossDomainSessionSecurity","false"); + return servlet; + } + + @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { // Customize the application or call application.sources(...) to add sources From b7b42ea4cbdd63aa29ba2d32f0d40bd015c034d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Fri, 23 Dec 2016 02:48:46 +0100 Subject: [PATCH 30/50] Exclude /dwr urls from csrf validation. --- .../security/CsrfSecurityRequestMatcher.java | 38 +++++++++++++++++++ .../resources/applicationContext-security.xml | 3 ++ .../src/main/resources/libresonic-servlet.xml | 4 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 libresonic-main/src/main/java/org/libresonic/player/security/CsrfSecurityRequestMatcher.java diff --git a/libresonic-main/src/main/java/org/libresonic/player/security/CsrfSecurityRequestMatcher.java b/libresonic-main/src/main/java/org/libresonic/player/security/CsrfSecurityRequestMatcher.java new file mode 100644 index 00000000..c2b78676 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/security/CsrfSecurityRequestMatcher.java @@ -0,0 +1,38 @@ +package org.libresonic.player.security; + +import org.springframework.security.web.util.matcher.RegexRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.util.regex.Pattern; + +/** + * See + * + * http://blogs.sourceallies.com/2014/04/customizing-csrf-protection-in-spring-security/ + * https://docs.spring.io/spring-security/site/docs/current/reference/html/appendix-namespace.html#nsa-csrf + * + * + */ +@Component +public class CsrfSecurityRequestMatcher implements RequestMatcher { + private Pattern allowedMethods = Pattern.compile("^(GET|HEAD|TRACE|OPTIONS)$"); + private RegexRequestMatcher dwrRequestMatcher = new RegexRequestMatcher("/dwr/.*\\.dwr", "POST"); + + @Override + public boolean matches(HttpServletRequest request) { + + boolean requireCsrfToken = true; + + if(allowedMethods.matcher(request.getMethod()).matches()){ + requireCsrfToken = false; + } else { + if (dwrRequestMatcher.matches(request)) { + requireCsrfToken = false; + } + } + + return requireCsrfToken; + } +} \ No newline at end of file diff --git a/libresonic-main/src/main/resources/applicationContext-security.xml b/libresonic-main/src/main/resources/applicationContext-security.xml index 442c9c9c..d7850d46 100644 --- a/libresonic-main/src/main/resources/applicationContext-security.xml +++ b/libresonic-main/src/main/resources/applicationContext-security.xml @@ -9,6 +9,9 @@ + + + diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index d3d25ccf..766057d3 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -13,7 +13,9 @@ http://www.springframework.org/schema/mvc/spring-mvc.xsd"> - + From a0f7966163e932f0323d28609795fa0510dc6596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Fri, 23 Dec 2016 02:59:32 +0100 Subject: [PATCH 31/50] StreamController migration --- .../player/controller/StreamController.java | 54 ++++++------------- .../src/main/resources/libresonic-servlet.xml | 12 ----- 2 files changed, 17 insertions(+), 49 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/StreamController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/StreamController.java index fe73fd1a..da518ad8 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/StreamController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/StreamController.java @@ -30,10 +30,13 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.Controller; import org.libresonic.player.Logger; import org.libresonic.player.domain.MediaFile; @@ -65,20 +68,32 @@ import org.libresonic.player.util.Util; * * @author Sindre Mehus */ -public class StreamController implements Controller { +@Controller +@RequestMapping("/stream/**") +public class StreamController { private static final Logger LOG = Logger.getLogger(StreamController.class); + @Autowired private StatusService statusService; + @Autowired private PlayerService playerService; + @Autowired private PlaylistService playlistService; + @Autowired private SecurityService securityService; + @Autowired private SettingsService settingsService; + @Autowired private TranscodingService transcodingService; + @Autowired private AudioScrobblerService audioScrobblerService; + @Autowired private MediaFileService mediaFileService; + @Autowired private SearchService searchService; + @RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { TransferStatus status = null; @@ -410,39 +425,4 @@ public class StreamController implements Controller { out.flush(); } - public void setStatusService(StatusService statusService) { - this.statusService = statusService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setTranscodingService(TranscodingService transcodingService) { - this.transcodingService = transcodingService; - } - - public void setAudioScrobblerService(AudioScrobblerService audioScrobblerService) { - this.audioScrobblerService = audioScrobblerService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } - - public void setSearchService(SearchService searchService) { - this.searchService = searchService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 766057d3..791a6229 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -17,17 +17,6 @@ org.libresonic.player.validator, org.libresonic.player.security"/> - - - - - - - - - - - @@ -112,7 +101,6 @@ downloadController wapController restController - streamController hlsController externalPlayerController From cf8a0f6d701aa711cd04109e84351c285734be81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 24 Dec 2016 11:47:46 +0100 Subject: [PATCH 32/50] Controller migration --- .../player/controller/HLSController.java | 26 +++++++++---------- .../src/main/resources/libresonic-servlet.xml | 6 ----- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/HLSController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/HLSController.java index 04cf4f52..e481afd1 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/HLSController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/HLSController.java @@ -30,9 +30,12 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.Controller; import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.Player; @@ -47,15 +50,21 @@ import org.libresonic.player.util.StringUtil; * * @author Sindre Mehus */ -public class HLSController implements Controller { +@Controller +@RequestMapping("/hls/**") +public class HLSController { private static final int SEGMENT_DURATION = 10; private static final Pattern BITRATE_PATTERN = Pattern.compile("(\\d+)(@(\\d+)x(\\d+))?"); + @Autowired private PlayerService playerService; + @Autowired private MediaFileService mediaFileService; + @Autowired private SecurityService securityService; + @RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setHeader("Access-Control-Allow-Origin", "*"); @@ -72,7 +81,7 @@ public class HLSController implements Controller { if (username != null && !securityService.isFolderAccessAllowed(mediaFile, username)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, - "Access to file " + mediaFile.getId() + " is forbidden for user " + username); + "Access to file " + mediaFile.getId() + " is forbidden for user " + username); return null; } @@ -188,15 +197,4 @@ public class HLSController implements Controller { return contextPath; } - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 791a6229..89eb1b8c 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -17,11 +17,6 @@ org.libresonic.player.validator, org.libresonic.player.security"/> - - - - - @@ -101,7 +96,6 @@ downloadController wapController restController - hlsController externalPlayerController From 24996c628ecd1a1a5d198eab949f194f54f638b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 24 Dec 2016 11:53:59 +0100 Subject: [PATCH 33/50] Controller migration --- .../player/controller/DownloadController.java | 57 +++++++------------ .../src/main/resources/libresonic-servlet.xml | 9 --- 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/DownloadController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/DownloadController.java index 86650bfb..9dc0a11e 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/DownloadController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/DownloadController.java @@ -38,10 +38,13 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.ServletRequestUtils; +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.mvc.Controller; import org.springframework.web.servlet.mvc.LastModified; import org.libresonic.player.Logger; @@ -69,15 +72,23 @@ import org.libresonic.player.util.Util; * * @author Sindre Mehus */ -public class DownloadController implements Controller, LastModified { +@Controller +@RequestMapping("/download") +public class DownloadController implements LastModified { private static final Logger LOG = Logger.getLogger(DownloadController.class); + @Autowired private PlayerService playerService; + @Autowired private StatusService statusService; + @Autowired private SecurityService securityService; + @Autowired private PlaylistService playlistService; + @Autowired private SettingsService settingsService; + @Autowired private MediaFileService mediaFileService; public long getLastModified(HttpServletRequest request) { @@ -92,6 +103,7 @@ public class DownloadController implements Controller, LastModified { } } + @RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { User user = securityService.getCurrentUser(request); @@ -120,7 +132,7 @@ public class DownloadController implements Controller, LastModified { if (mediaFile != null) { if (!securityService.isFolderAccessAllowed(mediaFile, user.getUsername())) { response.sendError(HttpServletResponse.SC_FORBIDDEN, - "Access to file " + mediaFile.getId() + " is forbidden for user " + user.getUsername()); + "Access to file " + mediaFile.getId() + " is forbidden for user " + user.getUsername()); return null; } @@ -163,7 +175,6 @@ public class DownloadController implements Controller, LastModified { /** * Downloads a single file. * - * * @param response The HTTP response. * @param status The download status. * @param file The file to download. @@ -205,14 +216,13 @@ public class DownloadController implements Controller, LastModified { * Downloads the given files. The files are packed together in an * uncompressed zip-file. * - * - * @param response The HTTP response. - * @param status The download status. - * @param files The files to download. - * @param indexes Only download songs at these indexes. May be null. + * @param response The HTTP response. + * @param status The download status. + * @param files The files to download. + * @param indexes Only download songs at these indexes. May be null. * @param coverArtFile The cover art file to include, may be {@code null}. - *@param range The byte range, may be null. - * @param zipFileName The name of the resulting zip file. @throws IOException If an I/O error occurs. + * @param range The byte range, may be null. + * @param zipFileName The name of the resulting zip file. @throws IOException If an I/O error occurs. */ private void downloadFiles(HttpServletResponse response, TransferStatus status, List files, int[] indexes, File coverArtFile, HttpRange range, String zipFileName) throws IOException { if (indexes != null && indexes.length == 1) { @@ -253,7 +263,6 @@ public class DownloadController implements Controller, LastModified { /** * Utility method for writing the content of a given file to a given output stream. * - * * @param file The file to copy. * @param out The output stream to write to. * @param status The download status. @@ -317,7 +326,6 @@ public class DownloadController implements Controller, LastModified { * Writes a file or a directory structure to a zip output stream. File entries in the zip file are relative * to the given root. * - * * @param out The zip output stream. * @param root The root of the directory structure. Used to create path information in the zip file. * @param file The file or directory to zip. @@ -389,27 +397,4 @@ public class DownloadController implements Controller, LastModified { return crc.getValue(); } - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setStatusService(StatusService statusService) { - this.statusService = statusService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 89eb1b8c..2a3bad65 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -31,14 +31,6 @@ - - - - - - - - @@ -90,7 +82,6 @@ videoPlayerController - downloadController dbController podcastController downloadController From b2d58fee47f865a55e5b598c3f0cd06b88ec8d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 24 Dec 2016 12:08:42 +0100 Subject: [PATCH 34/50] Controller migration --- .../player/controller/HLSController.java | 2 +- .../controller/VideoPlayerController.java | 52 ++++++++----------- .../src/main/resources/libresonic-servlet.xml | 8 --- 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/HLSController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/HLSController.java index e481afd1..c34d447a 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/HLSController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/HLSController.java @@ -50,7 +50,7 @@ import org.libresonic.player.util.StringUtil; * * @author Sindre Mehus */ -@Controller +@Controller(value = "hlsController") @RequestMapping("/hls/**") public class HLSController { diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/VideoPlayerController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/VideoPlayerController.java index 4cc8b3f1..47f48a06 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/VideoPlayerController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/VideoPlayerController.java @@ -19,17 +19,6 @@ */ package org.libresonic.player.controller; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.bind.ServletRequestUtils; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; - import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.User; import org.libresonic.player.service.MediaFileService; @@ -37,23 +26,41 @@ import org.libresonic.player.service.PlayerService; 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.stereotype.Controller; +import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; /** * Controller for the page used to play videos. * * @author Sindre Mehus */ -public class VideoPlayerController extends ParameterizableViewController { +@Controller +@RequestMapping("/videoPlayer") +public class VideoPlayerController { public static final int DEFAULT_BIT_RATE = 2000; public static final int[] BIT_RATES = {200, 300, 400, 500, 700, 1000, 1200, 1500, 2000, 3000, 5000}; + @Autowired private MediaFileService mediaFileService; + @Autowired private SettingsService settingsService; + @Autowired private PlayerService playerService; + @Autowired private SecurityService securityService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { User user = securityService.getCurrentUser(request); @@ -87,9 +94,7 @@ public class VideoPlayerController extends ParameterizableViewController { map.put("defaultBitRate", DEFAULT_BIT_RATE); map.put("user", user); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("videoPlayer", "model", map); } public static Map createSkipOffsets(int durationSeconds) { @@ -100,19 +105,4 @@ public class VideoPlayerController extends ParameterizableViewController { return result; } - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 2a3bad65..c74f7cd0 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -17,13 +17,6 @@ org.libresonic.player.validator, org.libresonic.player.security"/> - - - - - - - @@ -81,7 +74,6 @@ - videoPlayerController dbController podcastController downloadController From 376f98d670120184f453901fb8b8805ea2262927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 24 Dec 2016 12:20:20 +0100 Subject: [PATCH 35/50] Controller migration --- libresonic-main/src/main/webapp/WEB-INF/jsp/videoPlayer.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/videoPlayer.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/videoPlayer.jsp index 4bccfae8..a9820af6 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/videoPlayer.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/videoPlayer.jsp @@ -64,7 +64,7 @@ - +

" From f76470537fdd0cb7087ecbe1cb95e1e694f340af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 24 Dec 2016 19:45:44 +0100 Subject: [PATCH 36/50] Controller migration --- .../player/controller/DBController.java | 20 +++---- .../controller/ExternalPlayerController.java | 52 +++++++------------ .../src/main/resources/libresonic-servlet.xml | 13 ----- 3 files changed, 30 insertions(+), 55 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/DBController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/DBController.java index 594221f8..ae508e5c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/DBController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/DBController.java @@ -19,12 +19,15 @@ */ package org.libresonic.player.controller; -import org.libresonic.player.dao.DaoHelper; import org.apache.commons.lang.exception.ExceptionUtils; +import org.libresonic.player.dao.DaoHelper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.ColumnMapRowMapper; +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.mvc.ParameterizableViewController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -37,10 +40,14 @@ import java.util.Map; * * @author Sindre Mehus */ -public class DBController extends ParameterizableViewController { +@Controller +@RequestMapping("/db") +public class DBController { + @Autowired private DaoHelper daoHelper; + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -56,12 +63,7 @@ public class DBController extends ParameterizableViewController { } } - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("db","model",map); } - public void setDaoHelper(DaoHelper daoHelper) { - this.daoHelper = daoHelper; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ExternalPlayerController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ExternalPlayerController.java index a58dbe5d..71389a95 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ExternalPlayerController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ExternalPlayerController.java @@ -19,19 +19,6 @@ */ package org.libresonic.player.controller; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.ParameterizableViewController; - import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.domain.Player; @@ -40,20 +27,36 @@ import org.libresonic.player.service.MediaFileService; import org.libresonic.player.service.PlayerService; import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.ShareService; +import org.springframework.beans.factory.annotation.Autowired; +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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.*; /** * Controller for the page used to play shared music (Twitter, Facebook etc). * * @author Sindre Mehus */ -public class ExternalPlayerController extends ParameterizableViewController { +@Controller +@RequestMapping("/share/**") +public class ExternalPlayerController { + @Autowired private SettingsService settingsService; + @Autowired private PlayerService playerService; + @Autowired private ShareService shareService; + @Autowired private MediaFileService mediaFileService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); @@ -84,9 +87,7 @@ public class ExternalPlayerController extends ParameterizableViewController { map.put("redirectUrl", settingsService.getUrlRedirectUrl()); map.put("player", player.getId()); - ModelAndView result = super.handleRequestInternal(request, response); - result.addObject("model", map); - return result; + return new ModelAndView("externalPlayer", "model", map); } private List getSongs(Share share, String username) throws IOException { @@ -108,19 +109,4 @@ public class ExternalPlayerController extends ParameterizableViewController { return result; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setShareService(ShareService shareService) { - this.shareService = shareService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index c74f7cd0..1de4c524 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -17,13 +17,6 @@ org.libresonic.player.validator, org.libresonic.player.security"/> - - - - - - - @@ -65,21 +58,15 @@ - - - - - dbController podcastController downloadController wapController restController - externalPlayerController From e301f2363ff42a1b22cb0d6bcebf4928265a8891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 24 Dec 2016 22:03:57 +0100 Subject: [PATCH 37/50] Start RestController migration. --- .../player/controller/RESTController.java | 273 ++++-------------- .../resources/applicationContext-security.xml | 1 + .../src/main/resources/libresonic-servlet.xml | 33 --- .../libresonic-rest-api-soapui-project.xml | 19 ++ 4 files changed, 74 insertions(+), 252 deletions(-) create mode 100755 libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java index a61b7fb7..7b0dbec4 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java @@ -19,124 +19,46 @@ */ package org.libresonic.player.controller; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.concurrent.ConcurrentHashMap; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.lang.StringUtils; -import org.springframework.web.bind.ServletRequestUtils; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.multiaction.MultiActionController; -import org.libresonic.restapi.AlbumID3; -import org.libresonic.restapi.AlbumList; -import org.libresonic.restapi.AlbumList2; -import org.libresonic.restapi.AlbumWithSongsID3; -import org.libresonic.restapi.ArtistID3; -import org.libresonic.restapi.ArtistInfo; -import org.libresonic.restapi.ArtistInfo2; -import org.libresonic.restapi.ArtistWithAlbumsID3; -import org.libresonic.restapi.ArtistsID3; -import org.libresonic.restapi.Bookmarks; -import org.libresonic.restapi.ChatMessage; -import org.libresonic.restapi.ChatMessages; -import org.libresonic.restapi.Child; -import org.libresonic.restapi.Directory; -import org.libresonic.restapi.Genres; -import org.libresonic.restapi.Index; -import org.libresonic.restapi.IndexID3; -import org.libresonic.restapi.Indexes; -import org.libresonic.restapi.InternetRadioStation; -import org.libresonic.restapi.InternetRadioStations; -import org.libresonic.restapi.JukeboxPlaylist; -import org.libresonic.restapi.JukeboxStatus; -import org.libresonic.restapi.Lyrics; -import org.libresonic.restapi.MediaType; -import org.libresonic.restapi.MusicFolders; -import org.libresonic.restapi.NewestPodcasts; -import org.libresonic.restapi.NowPlaying; -import org.libresonic.restapi.NowPlayingEntry; -import org.libresonic.restapi.PlaylistWithSongs; -import org.libresonic.restapi.Playlists; -import org.libresonic.restapi.PodcastStatus; -import org.libresonic.restapi.Podcasts; -import org.libresonic.restapi.Response; -import org.libresonic.restapi.SearchResult2; -import org.libresonic.restapi.SearchResult3; -import org.libresonic.restapi.Shares; -import org.libresonic.restapi.SimilarSongs; -import org.libresonic.restapi.SimilarSongs2; -import org.libresonic.restapi.Songs; -import org.libresonic.restapi.Starred; -import org.libresonic.restapi.Starred2; -import org.libresonic.restapi.TopSongs; -import org.libresonic.restapi.Users; -import org.libresonic.restapi.Videos; - import org.libresonic.player.Logger; import org.libresonic.player.ajax.ChatService; import org.libresonic.player.ajax.LyricsInfo; import org.libresonic.player.ajax.LyricsService; import org.libresonic.player.ajax.PlayQueueService; import org.libresonic.player.command.UserSettingsCommand; -import org.libresonic.player.dao.AlbumDao; -import org.libresonic.player.dao.ArtistDao; -import org.libresonic.player.dao.BookmarkDao; -import org.libresonic.player.dao.MediaFileDao; -import org.libresonic.player.dao.PlayQueueDao; -import org.libresonic.player.domain.Album; +import org.libresonic.player.dao.*; +import org.libresonic.player.domain.*; import org.libresonic.player.domain.Artist; -import org.libresonic.player.domain.ArtistBio; import org.libresonic.player.domain.Bookmark; import org.libresonic.player.domain.Genre; -import org.libresonic.player.domain.InternetRadio; -import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.MusicFolder; -import org.libresonic.player.domain.MusicFolderContent; -import org.libresonic.player.domain.MusicIndex; import org.libresonic.player.domain.PlayQueue; -import org.libresonic.player.domain.PlayStatus; -import org.libresonic.player.domain.Player; -import org.libresonic.player.domain.PlayerTechnology; import org.libresonic.player.domain.Playlist; import org.libresonic.player.domain.PodcastChannel; import org.libresonic.player.domain.PodcastEpisode; -import org.libresonic.player.domain.RandomSearchCriteria; -import org.libresonic.player.domain.SavedPlayQueue; -import org.libresonic.player.domain.SearchCriteria; import org.libresonic.player.domain.SearchResult; import org.libresonic.player.domain.Share; -import org.libresonic.player.domain.TranscodeScheme; import org.libresonic.player.domain.User; -import org.libresonic.player.domain.UserSettings; -import org.libresonic.player.service.AudioScrobblerService; -import org.libresonic.player.service.JukeboxService; -import org.libresonic.player.service.LastFmService; -import org.libresonic.player.service.MediaFileService; -import org.libresonic.player.service.MusicIndexService; -import org.libresonic.player.service.PlayerService; -import org.libresonic.player.service.PlaylistService; -import org.libresonic.player.service.PodcastService; -import org.libresonic.player.service.RatingService; -import org.libresonic.player.service.SearchService; -import org.libresonic.player.service.SecurityService; -import org.libresonic.player.service.SettingsService; -import org.libresonic.player.service.ShareService; -import org.libresonic.player.service.StatusService; -import org.libresonic.player.service.TranscodingService; +import org.libresonic.player.service.*; import org.libresonic.player.util.Pair; import org.libresonic.player.util.StringUtil; import org.libresonic.player.util.Util; +import org.libresonic.restapi.*; +import org.libresonic.restapi.Genres; +import org.libresonic.restapi.PodcastStatus; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import javax.annotation.PostConstruct; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import static org.libresonic.player.security.RESTRequestParameterProcessingFilter.decrypt; import static org.springframework.web.bind.ServletRequestUtils.*; @@ -150,44 +72,76 @@ import static org.springframework.web.bind.ServletRequestUtils.*; * * @author Sindre Mehus */ -public class RESTController extends MultiActionController { +@Controller +public class RESTController { private static final Logger LOG = Logger.getLogger(RESTController.class); + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; + @Autowired private PlayerService playerService; + @Autowired private MediaFileService mediaFileService; + @Autowired private LastFmService lastFmService; + @Autowired private MusicIndexService musicIndexService; + @Autowired private TranscodingService transcodingService; + @Autowired private DownloadController downloadController; + @Autowired private CoverArtController coverArtController; + @Autowired private AvatarController avatarController; + @Autowired private UserSettingsController userSettingsController; + @Autowired private LeftController leftController; + @Autowired private StatusService statusService; + @Autowired private StreamController streamController; + @Autowired private HLSController hlsController; + @Autowired private ShareService shareService; + @Autowired private PlaylistService playlistService; + @Autowired private ChatService chatService; + @Autowired private LyricsService lyricsService; + @Autowired private PlayQueueService playQueueService; + @Autowired private JukeboxService jukeboxService; + @Autowired private AudioScrobblerService audioScrobblerService; + @Autowired private PodcastService podcastService; + @Autowired private RatingService ratingService; + @Autowired private SearchService searchService; + @Autowired private MediaFileDao mediaFileDao; + @Autowired private ArtistDao artistDao; + @Autowired private AlbumDao albumDao; + @Autowired private BookmarkDao bookmarkDao; + @Autowired private PlayQueueDao playQueueDao; private final Map bookmarkCache = new ConcurrentHashMap(); private final JAXBWriter jaxbWriter = new JAXBWriter(); + @PostConstruct public void init() { refreshBookmarkCache(); } @@ -199,7 +153,7 @@ public class RESTController extends MultiActionController { } } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/ping", method = RequestMethod.GET) public void ping(HttpServletRequest request, HttpServletResponse response) throws Exception { Response res = createResponse(); jaxbWriter.writeResponse(request, response, res); @@ -1066,7 +1020,7 @@ public class RESTController extends MultiActionController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getAlbumList", method = RequestMethod.GET) public void getAlbumList(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -2342,125 +2296,6 @@ public class RESTController extends MultiActionController { return !players.isEmpty() ? players.get(0).getId() : null; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setTranscodingService(TranscodingService transcodingService) { - this.transcodingService = transcodingService; - } - - public void setDownloadController(DownloadController downloadController) { - this.downloadController = downloadController; - } - - public void setCoverArtController(CoverArtController coverArtController) { - this.coverArtController = coverArtController; - } - - public void setUserSettingsController(UserSettingsController userSettingsController) { - this.userSettingsController = userSettingsController; - } - - public void setLeftController(LeftController leftController) { - this.leftController = leftController; - } - - public void setStatusService(StatusService statusService) { - this.statusService = statusService; - } - - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } - - public void setStreamController(StreamController streamController) { - this.streamController = streamController; - } - - public void setHlsController(HLSController hlsController) { - this.hlsController = hlsController; - } - - public void setChatService(ChatService chatService) { - this.chatService = chatService; - } - - public void setLyricsService(LyricsService lyricsService) { - this.lyricsService = lyricsService; - } - - public void setPlayQueueService(PlayQueueService playQueueService) { - this.playQueueService = playQueueService; - } - - public void setJukeboxService(JukeboxService jukeboxService) { - this.jukeboxService = jukeboxService; - } - - public void setAudioScrobblerService(AudioScrobblerService audioScrobblerService) { - this.audioScrobblerService = audioScrobblerService; - } - - public void setPodcastService(PodcastService podcastService) { - this.podcastService = podcastService; - } - - public void setRatingService(RatingService ratingService) { - this.ratingService = ratingService; - } - - public void setSearchService(SearchService searchService) { - this.searchService = searchService; - } - - public void setShareService(ShareService shareService) { - this.shareService = shareService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } - - public void setAvatarController(AvatarController avatarController) { - this.avatarController = avatarController; - } - - public void setArtistDao(ArtistDao artistDao) { - this.artistDao = artistDao; - } - - public void setAlbumDao(AlbumDao albumDao) { - this.albumDao = albumDao; - } - - public void setMediaFileDao(MediaFileDao mediaFileDao) { - this.mediaFileDao = mediaFileDao; - } - - public void setMusicIndexService(MusicIndexService musicIndexService) { - this.musicIndexService = musicIndexService; - } - - public void setBookmarkDao(BookmarkDao bookmarkDao) { - this.bookmarkDao = bookmarkDao; - } - - public void setLastFmService(LastFmService lastFmService) { - this.lastFmService = lastFmService; - } - - public void setPlayQueueDao(PlayQueueDao playQueueDao) { - this.playQueueDao = playQueueDao; - } public enum ErrorCode { diff --git a/libresonic-main/src/main/resources/applicationContext-security.xml b/libresonic-main/src/main/resources/applicationContext-security.xml index d7850d46..7831aa7b 100644 --- a/libresonic-main/src/main/resources/applicationContext-security.xml +++ b/libresonic-main/src/main/resources/applicationContext-security.xml @@ -24,6 +24,7 @@ + diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 1de4c524..8576ae81 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -26,38 +26,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -66,7 +34,6 @@ podcastController downloadController wapController - restController diff --git a/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml b/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml new file mode 100755 index 00000000..8bb18c1a --- /dev/null +++ b/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml @@ -0,0 +1,19 @@ + +http://localhost:8080/uadminQUERYadminpadminQUERYadminv1.12.0QUERY1.12.0csoapuiQUERYsoapuiuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuitext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data0data0data0datatext/html;charset=utf-8200htmltext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://localhost/rest/ping.viewNo AuthorizationujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyapptext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data0data0data0data<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/ping.viewNo Authorization + + +upvcujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyappincludeEpisodesQUERYuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyappincludeEpisodesfalseQUERYfalsetext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/ping.viewNo Authorization + + + +upvcincludeEpisodesuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyappincludeEpisodestrueQUERYtrueidQUERYtext/xml; charset=utf-8200res:subsonic-response<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getPodcasts.viewNo Authorization<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getPodcasts.viewNo AuthorizationuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuitypeQUERYsizeQUERYoffsetQUERYfromYearQUERYtoYearQUERYgenreQUERYmusicFolderIdQUERYapplication/json;charset=UTF-8500get:Fault<xml-fragment/>http://localhost:8080/http://localhost/rest/getAlbumList.viewNo Authorization + + +uremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0csoapuiQUERYsoapuisizeQUERYgenreQUERYfromYearQUERYtoYearQUERYmusicFolderIdQUERYuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyapptypeQUERYsizeQUERYoffsetQUERYfromYearQUERYtoYearQUERYgenreQUERYmusicFolderIdQUERYtext/xml; charset=utf-8200res:subsonic-response0data<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getAlbumList.viewNo Authorization + + +upvctypesizeoffsetfromYeartoYeargenremusicFolderIduremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0csoapuiQUERYsoapuiidQUERYtext/xml; charset=utf-8200res:subsonic-response<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getAlbum.viewNo AuthorizationujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyappgenreQUERYcountQUERYoffsetQUERYmusicFolderIdQUERYtext/xml; charset=utf-8200res:subsonic-response0data0data0data0data0datatext/html; charset=iso-8859-1503html0data0data0data0data<xml-fragment/>http://localhost:8080/testResthttp://192.168.0.11/rest/getSongsByGenre.viewNo Authorization + + + +http://localhost:8080/ \ No newline at end of file From 87a9cb1c12c7ec2784407ea679bc82e380743f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 24 Dec 2016 23:36:54 +0100 Subject: [PATCH 38/50] RESTRequestParameterProcessingFilter moved to annotated bean. --- .../RESTRequestParameterProcessingFilter.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/security/RESTRequestParameterProcessingFilter.java b/libresonic-main/src/main/java/org/libresonic/player/security/RESTRequestParameterProcessingFilter.java index f5274148..dd974919 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/security/RESTRequestParameterProcessingFilter.java +++ b/libresonic-main/src/main/java/org/libresonic/player/security/RESTRequestParameterProcessingFilter.java @@ -29,11 +29,13 @@ import org.libresonic.player.domain.Version; 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.authentication.ProviderManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; @@ -51,14 +53,19 @@ import java.io.IOException; * * @author Sindre Mehus */ +@Component(value = "restRequestParameterProcessingFilter") public class RESTRequestParameterProcessingFilter implements Filter { private static final Logger LOG = Logger.getLogger(RESTRequestParameterProcessingFilter.class); private final JAXBWriter jaxbWriter = new JAXBWriter(); + @Autowired private ProviderManager authenticationManager; + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; + @Autowired private LoginFailureLogger loginFailureLogger; public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { @@ -185,19 +192,4 @@ public class RESTRequestParameterProcessingFilter implements Filter { public void destroy() { } - public void setAuthenticationManager(ProviderManager authenticationManager) { - this.authenticationManager = authenticationManager; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setLoginFailureLogger(LoginFailureLogger loginFailureLogger) { - this.loginFailureLogger = loginFailureLogger; - } } From 97f3607b1ceb45d65fc701042fadfffff74e87d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 24 Dec 2016 23:39:14 +0100 Subject: [PATCH 39/50] Register REST Filter --- .../libresonic/player/boot/Application.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java index 28b75c8e..e9caf628 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java +++ b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java @@ -1,9 +1,12 @@ package org.libresonic.player.boot; import org.directwebremoting.servlet.DwrServlet; +import org.libresonic.player.filter.RESTFilter; +import org.libresonic.player.security.RESTRequestParameterProcessingFilter; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.context.annotation.Bean; @@ -19,6 +22,11 @@ import org.springframework.context.annotation.ImportResource; "classpath:/libresonic-servlet.xml"}) public class Application extends SpringBootServletInitializer { + /** + * Registers the DWR servlet. + * + * @return a registration bean. + */ @Bean public ServletRegistrationBean dwrServletRegistrationBean() { ServletRegistrationBean servlet = new ServletRegistrationBean(new DwrServlet(), "/dwr/*"); @@ -26,6 +34,21 @@ public class Application extends SpringBootServletInitializer { return servlet; } + /** + * Registers the rest servlet filter. + * + * @return a registration bean. + */ + @Bean + public FilterRegistrationBean restFilterRegistration() { + FilterRegistrationBean registration = new FilterRegistrationBean(); + registration.setFilter(new RESTFilter()); + registration.addUrlPatterns("/rest/*"); + registration.setName("RESTFilter"); + return registration; + } + + @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { From fc01f8f83ce4c7866f89a12a3e1a019783eb7ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Fri, 30 Dec 2016 19:29:01 +0100 Subject: [PATCH 40/50] Spring security configuration has moved to java. --- .../libresonic/player/boot/Application.java | 19 ---- .../player/security/LoginFailureLogger.java | 2 + .../RESTRequestParameterProcessingFilter.java | 46 +++++++--- .../player/security/WebSecurityConfig.java | 92 +++++++++++++++++++ .../resources/applicationContext-security.xml | 80 ---------------- .../src/main/webapp/WEB-INF/jsp/login.jsp | 2 +- 6 files changed, 130 insertions(+), 111 deletions(-) create mode 100644 libresonic-main/src/main/java/org/libresonic/player/security/WebSecurityConfig.java delete mode 100644 libresonic-main/src/main/resources/applicationContext-security.xml diff --git a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java index e9caf628..dfb807f6 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java +++ b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java @@ -1,12 +1,9 @@ package org.libresonic.player.boot; import org.directwebremoting.servlet.DwrServlet; -import org.libresonic.player.filter.RESTFilter; -import org.libresonic.player.security.RESTRequestParameterProcessingFilter; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.context.annotation.Bean; @@ -18,7 +15,6 @@ import org.springframework.context.annotation.ImportResource; @ImportResource(value = {"classpath:/applicationContext-service.xml", "classpath:/applicationContext-cache.xml", "classpath:/applicationContext-sonos.xml", - "classpath:/applicationContext-security.xml", "classpath:/libresonic-servlet.xml"}) public class Application extends SpringBootServletInitializer { @@ -34,21 +30,6 @@ public class Application extends SpringBootServletInitializer { return servlet; } - /** - * Registers the rest servlet filter. - * - * @return a registration bean. - */ - @Bean - public FilterRegistrationBean restFilterRegistration() { - FilterRegistrationBean registration = new FilterRegistrationBean(); - registration.setFilter(new RESTFilter()); - registration.addUrlPatterns("/rest/*"); - registration.setName("RESTFilter"); - return registration; - } - - @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { diff --git a/libresonic-main/src/main/java/org/libresonic/player/security/LoginFailureLogger.java b/libresonic-main/src/main/java/org/libresonic/player/security/LoginFailureLogger.java index 0e7b056e..2fce8bcd 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/security/LoginFailureLogger.java +++ b/libresonic-main/src/main/java/org/libresonic/player/security/LoginFailureLogger.java @@ -20,6 +20,7 @@ package org.libresonic.player.security; import org.libresonic.player.Logger; +import org.springframework.stereotype.Component; /** * Logs login failures. Can be used by tools like fail2ban for blocking IP addresses. @@ -27,6 +28,7 @@ import org.libresonic.player.Logger; * @author Sindre Mehus * @version $Id$ */ +@Component public class LoginFailureLogger { private static final Logger LOG = Logger.getLogger(LoginFailureLogger.class); diff --git a/libresonic-main/src/main/java/org/libresonic/player/security/RESTRequestParameterProcessingFilter.java b/libresonic-main/src/main/java/org/libresonic/player/security/RESTRequestParameterProcessingFilter.java index dd974919..5e99b1f5 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/security/RESTRequestParameterProcessingFilter.java +++ b/libresonic-main/src/main/java/org/libresonic/player/security/RESTRequestParameterProcessingFilter.java @@ -27,15 +27,14 @@ import org.libresonic.player.controller.RESTController; import org.libresonic.player.domain.User; import org.libresonic.player.domain.Version; 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.authentication.ProviderManager; +import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Component; +import org.springframework.security.web.util.matcher.RegexRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; @@ -53,21 +52,22 @@ import java.io.IOException; * * @author Sindre Mehus */ -@Component(value = "restRequestParameterProcessingFilter") public class RESTRequestParameterProcessingFilter implements Filter { private static final Logger LOG = Logger.getLogger(RESTRequestParameterProcessingFilter.class); private final JAXBWriter jaxbWriter = new JAXBWriter(); - @Autowired - private ProviderManager authenticationManager; - @Autowired - private SettingsService settingsService; - @Autowired + private AuthenticationManager authenticationManager; private SecurityService securityService; - @Autowired private LoginFailureLogger loginFailureLogger; + private static RequestMatcher requiresAuthenticationRequestMatcher = new RegexRequestMatcher("/rest/.+\\.view\\??.*",null); + + protected boolean requiresAuthentication(HttpServletRequest request, + HttpServletResponse response) { + return requiresAuthenticationRequestMatcher.matches(request); + } + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { throw new ServletException("Can only process HttpServletRequest"); @@ -79,6 +79,13 @@ public class RESTRequestParameterProcessingFilter implements Filter { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; + if (!requiresAuthentication(httpRequest, httpResponse)) { + chain.doFilter(request, response); + + return; + } + + String username = StringUtils.trimToNull(httpRequest.getParameter("u")); String password = decrypt(StringUtils.trimToNull(httpRequest.getParameter("p"))); String salt = StringUtils.trimToNull(httpRequest.getParameter("s")); @@ -192,4 +199,21 @@ public class RESTRequestParameterProcessingFilter implements Filter { public void destroy() { } + + public void setAuthenticationManager(AuthenticationManager authenticationManager) { + this.authenticationManager = authenticationManager; + } + + public SecurityService getSecurityService() { + return securityService; + } + + public void setSecurityService(SecurityService securityService) { + this.securityService = securityService; + } + + + public void setLoginFailureLogger(LoginFailureLogger loginFailureLogger) { + this.loginFailureLogger = loginFailureLogger; + } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/security/WebSecurityConfig.java b/libresonic-main/src/main/java/org/libresonic/player/security/WebSecurityConfig.java new file mode 100644 index 00000000..890c527d --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/security/WebSecurityConfig.java @@ -0,0 +1,92 @@ +package org.libresonic.player.security; + +import org.libresonic.player.service.SecurityService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +@Configuration +@EnableWebSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private SecurityService securityService; + @Autowired + private CsrfSecurityRequestMatcher csrfSecurityRequestMatcher; + @Autowired + LoginFailureLogger loginFailureLogger; + + @Override + @Bean(name = "authenticationManager") + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(securityService); + } + + + @Override + protected void configure(HttpSecurity http) throws Exception { + + RESTRequestParameterProcessingFilter restAuthenticationFilter = new RESTRequestParameterProcessingFilter(); + restAuthenticationFilter.setAuthenticationManager((AuthenticationManager) getApplicationContext().getBean("authenticationManager")); + restAuthenticationFilter.setSecurityService(securityService); + restAuthenticationFilter.setLoginFailureLogger(loginFailureLogger); + http = http.addFilterBefore(restAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); + + http + .csrf() + .requireCsrfProtectionMatcher(csrfSecurityRequestMatcher) + .and().headers() + .frameOptions() + .sameOrigin() + .and().authorizeRequests() + .antMatchers("recover.view", "accessDenied.view", + "coverArt.view", "/hls/**", "/stream/**", "/ws/**", + "/share/**", "/style/**", "/icons/**", + "/flash/**", "/script/**", "/sonos/**", "/crossdomain.xml") + .permitAll() + .antMatchers("/personalSettings.view", "/passwordSettings.view", + "/playerSettings.view", "/shareSettings.view") + .hasRole("SETTINGS") + .antMatchers("/generalSettings.view","/advancedSettings.view","/userSettings.view", + "/musicFolderSettings.view","/networkSettings.view") + .hasRole("ADMIN") + .antMatchers("/deletePlaylist.view","/savePlaylist.view") + .hasRole("PLAYLIST") + .antMatchers("/download.view") + .hasRole("DOWNLOAD") + .antMatchers("/upload.view") + .hasRole("UPLOAD") + .antMatchers("/createShare.view") + .hasRole("SHARE") + .antMatchers("/changeCoverArt.view","/editTags.view") + .hasRole("COVERART") + .antMatchers("/setMusicFileInfo.view") + .hasRole("COMMENT") + .antMatchers("/podcastReceiverAdmin.view") + .hasRole("PODCAST") + .antMatchers("/**") + .hasRole("USER") + .anyRequest().authenticated() + .and().formLogin() + .loginPage("/login") + .permitAll() + .defaultSuccessUrl("/index.view") + .failureUrl("/login?error=1") + .usernameParameter("j_username") + .passwordParameter("j_password") + .and().rememberMe().userDetailsService(securityService).key("libresonic"); + + } +} \ No newline at end of file diff --git a/libresonic-main/src/main/resources/applicationContext-security.xml b/libresonic-main/src/main/resources/applicationContext-security.xml deleted file mode 100644 index 7831aa7b..00000000 --- a/libresonic-main/src/main/resources/applicationContext-security.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/login.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/login.jsp index d3081ef7..16acce0a 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/login.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/login.jsp @@ -12,7 +12,7 @@ - +
From 473902cdcaad9977904002febead03c3bcfffa48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Fri, 30 Dec 2016 19:54:23 +0100 Subject: [PATCH 41/50] applicationContext-db must move to resources/classes --- .../{webapp/WEB-INF => resources}/applicationContext-db-embed.xml | 0 .../{webapp/WEB-INF => resources}/applicationContext-db-jndi.xml | 0 .../WEB-INF => resources}/applicationContext-db-legacy.xml | 0 .../main/{webapp/WEB-INF => resources}/applicationContext-db.xml | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename libresonic-main/src/main/{webapp/WEB-INF => resources}/applicationContext-db-embed.xml (100%) rename libresonic-main/src/main/{webapp/WEB-INF => resources}/applicationContext-db-jndi.xml (100%) rename libresonic-main/src/main/{webapp/WEB-INF => resources}/applicationContext-db-legacy.xml (100%) rename libresonic-main/src/main/{webapp/WEB-INF => resources}/applicationContext-db.xml (100%) diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-embed.xml b/libresonic-main/src/main/resources/applicationContext-db-embed.xml similarity index 100% rename from libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-embed.xml rename to libresonic-main/src/main/resources/applicationContext-db-embed.xml diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-jndi.xml b/libresonic-main/src/main/resources/applicationContext-db-jndi.xml similarity index 100% rename from libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-jndi.xml rename to libresonic-main/src/main/resources/applicationContext-db-jndi.xml diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-legacy.xml b/libresonic-main/src/main/resources/applicationContext-db-legacy.xml similarity index 100% rename from libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-legacy.xml rename to libresonic-main/src/main/resources/applicationContext-db-legacy.xml diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db.xml b/libresonic-main/src/main/resources/applicationContext-db.xml similarity index 100% rename from libresonic-main/src/main/webapp/WEB-INF/applicationContext-db.xml rename to libresonic-main/src/main/resources/applicationContext-db.xml From c28fb87a1f533ece410032578effda57f39ecaf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 31 Dec 2016 02:22:50 +0100 Subject: [PATCH 42/50] applicationContext clean up --- .../src/main/resources/applicationContext-db-embed.xml | 5 +---- .../src/main/resources/applicationContext-db-legacy.xml | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/libresonic-main/src/main/resources/applicationContext-db-embed.xml b/libresonic-main/src/main/resources/applicationContext-db-embed.xml index 5ee2f378..4ba2e7ed 100644 --- a/libresonic-main/src/main/resources/applicationContext-db-embed.xml +++ b/libresonic-main/src/main/resources/applicationContext-db-embed.xml @@ -1,10 +1,7 @@ diff --git a/libresonic-main/src/main/resources/applicationContext-db-legacy.xml b/libresonic-main/src/main/resources/applicationContext-db-legacy.xml index 862a228b..892ac0b0 100644 --- a/libresonic-main/src/main/resources/applicationContext-db-legacy.xml +++ b/libresonic-main/src/main/resources/applicationContext-db-legacy.xml @@ -1,10 +1,7 @@ Date: Sat, 31 Dec 2016 02:23:32 +0100 Subject: [PATCH 43/50] Register of AdditionalPropertySourceConfigurer previously present in web.xml. --- .../main/java/org/libresonic/player/boot/Application.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java index dfb807f6..86f40157 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java +++ b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java @@ -1,6 +1,7 @@ package org.libresonic.player.boot; import org.directwebremoting.servlet.DwrServlet; +import org.libresonic.player.spring.AdditionalPropertySourceConfigurer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; @@ -40,7 +41,9 @@ public class Application extends SpringBootServletInitializer { } public static void main(String[] args) { - SpringApplication.run(Application.class, args); + SpringApplication springApplication = new SpringApplication(Application.class); + springApplication.addInitializers(new AdditionalPropertySourceConfigurer()); + springApplication.run(args); } } \ No newline at end of file From edd5cc9dd12aadd3aff1abff04d31c9cb8d2a559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 31 Dec 2016 02:47:45 +0100 Subject: [PATCH 44/50] Packages to scan listed in spring boot application rather than in xml file. --- .../src/main/java/org/libresonic/player/boot/Application.java | 2 +- libresonic-main/src/main/resources/libresonic-servlet.xml | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java index 86f40157..701d597c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java +++ b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java @@ -11,7 +11,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "org.libresonic.player.controller,org.libresonic.player.validator,org.libresonic.player.security") @Configuration @ImportResource(value = {"classpath:/applicationContext-service.xml", "classpath:/applicationContext-cache.xml", diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 8576ae81..7ba83af4 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -13,9 +13,6 @@ http://www.springframework.org/schema/mvc/spring-mvc.xsd"> - From e51e2e8b10dd82b9775f3f8c668744e577d94382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 31 Dec 2016 02:51:03 +0100 Subject: [PATCH 45/50] delete wap controller. --- .../player/controller/WapController.java | 252 ------------------ .../src/main/resources/libresonic-servlet.xml | 11 - 2 files changed, 263 deletions(-) delete mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/WapController.java diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/WapController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/WapController.java deleted file mode 100644 index 967808b8..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/WapController.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.controller; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedMap; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.bind.ServletRequestUtils; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.multiaction.MultiActionController; - -import org.libresonic.player.domain.MediaFile; -import org.libresonic.player.domain.MusicFolder; -import org.libresonic.player.domain.MusicIndex; -import org.libresonic.player.domain.PlayQueue; -import org.libresonic.player.domain.Player; -import org.libresonic.player.domain.RandomSearchCriteria; -import org.libresonic.player.domain.SearchCriteria; -import org.libresonic.player.domain.SearchResult; -import org.libresonic.player.domain.User; -import org.libresonic.player.service.MediaFileService; -import org.libresonic.player.service.MusicIndexService; -import org.libresonic.player.service.PlayerService; -import org.libresonic.player.service.PlaylistService; -import org.libresonic.player.service.SearchService; -import org.libresonic.player.service.SecurityService; -import org.libresonic.player.service.SettingsService; - -/** - * Multi-controller used for wap pages. - * - * @author Sindre Mehus - */ -public class WapController extends MultiActionController { - - private SettingsService settingsService; - private PlayerService playerService; - private PlaylistService playlistService; - private SecurityService securityService; - private MusicIndexService musicIndexService; - private MediaFileService mediaFileService; - private SearchService searchService; - - public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception { - return wap(request, response); - } - - public ModelAndView wap(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); - - String username = securityService.getCurrentUsername(request); - List folders = settingsService.getMusicFoldersForUser(username); - - if (folders.isEmpty()) { - map.put("noMusic", true); - } else { - - SortedMap> allArtists = musicIndexService.getIndexedArtists(folders, false); - - // If an index is given as parameter, only show music files for this index. - String index = request.getParameter("index"); - if (index != null) { - List artists = allArtists.get(new MusicIndex(index)); - if (artists == null) { - map.put("noMusic", true); - } else { - map.put("artists", artists); - } - } - - // Otherwise, list all indexes. - else { - map.put("indexes", allArtists.keySet()); - } - } - - return new ModelAndView("wap/index", "model", map); - } - - public ModelAndView browse(HttpServletRequest request, HttpServletResponse response) throws Exception { - String path = request.getParameter("path"); - MediaFile parent = mediaFileService.getMediaFile(path); - - // Create array of file(s) to display. - List children; - if (parent.isDirectory()) { - children = mediaFileService.getChildrenOf(parent, true, true, true); - } else { - children = new ArrayList(); - children.add(parent); - } - - Map map = new HashMap(); - map.put("parent", parent); - map.put("children", children); - map.put("user", securityService.getCurrentUser(request)); - - return new ModelAndView("wap/browse", "model", map); - } - - public ModelAndView playlist(HttpServletRequest request, HttpServletResponse response) throws Exception { - // Create array of players to control. If the "player" attribute is set for this session, - // only the player with this ID is controlled. Otherwise, all players are controlled. - List players = playerService.getAllPlayers(); - - String playerId = (String) request.getSession().getAttribute("player"); - if (playerId != null) { - Player player = playerService.getPlayerById(playerId); - if (player != null) { - players = Arrays.asList(player); - } - } - - Map map = new HashMap(); - - for (Player player : players) { - PlayQueue playQueue = player.getPlayQueue(); - map.put("playlist", playQueue); - - if (request.getParameter("play") != null) { - MediaFile file = mediaFileService.getMediaFile(request.getParameter("play")); - playQueue.addFiles(false, file); - } else if (request.getParameter("add") != null) { - MediaFile file = mediaFileService.getMediaFile(request.getParameter("add")); - playQueue.addFiles(true, file); - } else if (request.getParameter("skip") != null) { - playQueue.setIndex(Integer.parseInt(request.getParameter("skip"))); - } else if (request.getParameter("clear") != null) { - playQueue.clear(); - } else if (request.getParameter("load") != null) { - List songs = playlistService.getFilesInPlaylist(ServletRequestUtils.getIntParameter(request, "id")); - playQueue.addFiles(false, songs); - } else if (request.getParameter("random") != null) { - List musicFolders = settingsService.getMusicFoldersForUser(securityService.getCurrentUsername(request)); - List randomFiles = searchService.getRandomSongs(new RandomSearchCriteria(20, null, null, null, musicFolders)); - playQueue.addFiles(false, randomFiles); - } - } - - map.put("players", players); - return new ModelAndView("wap/playlist", "model", map); - } - - public ModelAndView loadPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception { - Map map = new HashMap(); - map.put("playlists", playlistService.getReadablePlaylistsForUser(securityService.getCurrentUsername(request))); - return new ModelAndView("wap/loadPlaylist", "model", map); - } - - public ModelAndView search(HttpServletRequest request, HttpServletResponse response) throws Exception { - return new ModelAndView("wap/search"); - } - - public ModelAndView searchResult(HttpServletRequest request, HttpServletResponse response) throws Exception { - String username = securityService.getCurrentUsername(request); - String query = request.getParameter("query"); - - Map map = new HashMap(); - map.put("hits", search(query, username)); - - return new ModelAndView("wap/searchResult", "model", map); - } - - public ModelAndView settings(HttpServletRequest request, HttpServletResponse response) throws Exception { - String playerId = (String) request.getSession().getAttribute("player"); - - List allPlayers = playerService.getAllPlayers(); - User user = securityService.getCurrentUser(request); - List players = new ArrayList(); - Map map = new HashMap(); - - for (Player player : allPlayers) { - // Only display authorized players. - if (user.isAdminRole() || user.getUsername().equals(player.getUsername())) { - players.add(player); - } - - } - map.put("playerId", playerId); - map.put("players", players); - return new ModelAndView("wap/settings", "model", map); - } - - public ModelAndView selectPlayer(HttpServletRequest request, HttpServletResponse response) throws Exception { - request.getSession().setAttribute("player", request.getParameter("playerId")); - return settings(request, response); - } - - private List search(String query, String username) throws IOException { - SearchCriteria criteria = new SearchCriteria(); - criteria.setQuery(query); - criteria.setOffset(0); - criteria.setCount(50); - List musicFolders = settingsService.getMusicFoldersForUser(username); - - SearchResult result = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG); - return result.getMediaFiles(); - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setPlaylistService(PlaylistService playlistService) { - this.playlistService = playlistService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setMusicIndexService(MusicIndexService musicIndexService) { - this.musicIndexService = musicIndexService; - } - - public void setMediaFileService(MediaFileService mediaFileService) { - this.mediaFileService = mediaFileService; - } - - public void setSearchService(SearchService searchService) { - this.searchService = searchService; - } -} diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index 7ba83af4..d3635bea 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -14,23 +14,12 @@ - - - - - - - - - podcastController - downloadController - wapController From 5b2297af968dfe903b45170e8204d81116f1de80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 31 Dec 2016 13:51:22 +0100 Subject: [PATCH 46/50] rest API migration (WIP). --- .../player/controller/RESTController.java | 4 ++-- .../libresonic-rest-api-soapui-project.xml | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java index 7b0dbec4..42c07d7d 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java @@ -543,7 +543,7 @@ public class RESTController { return jaxbPlaylist; } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getAlbum", method = RequestMethod.GET) public void getAlbum(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -1115,7 +1115,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getRandomSongs", method = RequestMethod.GET) public void getRandomSongs(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); diff --git a/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml b/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml index 8bb18c1a..3e1096e4 100755 --- a/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml +++ b/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml @@ -1,19 +1,24 @@ -http://localhost:8080/uadminQUERYadminpadminQUERYadminv1.12.0QUERY1.12.0csoapuiQUERYsoapuiuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuitext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data0data0data0datatext/html;charset=utf-8200htmltext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://localhost/rest/ping.viewNo AuthorizationujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyapptext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data0data0data0data<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/ping.viewNo Authorization +http://localhost:8080/ujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyapptext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data0data0data0data<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/ping.viewNo Authorization -upvcujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyappincludeEpisodesQUERYuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyappincludeEpisodesfalseQUERYfalsetext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/ping.viewNo Authorization +upvcujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyappincludeEpisodesQUERYuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyappincludeEpisodesfalseQUERYfalsetext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/ping.viewNo Authorization -upvcincludeEpisodesuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyappincludeEpisodestrueQUERYtrueidQUERYtext/xml; charset=utf-8200res:subsonic-response<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getPodcasts.viewNo Authorization<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getPodcasts.viewNo AuthorizationuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuitypeQUERYsizeQUERYoffsetQUERYfromYearQUERYtoYearQUERYgenreQUERYmusicFolderIdQUERYapplication/json;charset=UTF-8500get:Fault<xml-fragment/>http://localhost:8080/http://localhost/rest/getAlbumList.viewNo Authorization +upvcincludeEpisodesuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyappincludeEpisodestrueQUERYtrueidQUERYtext/xml; charset=utf-8200res:subsonic-response<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getPodcasts.viewNo Authorization<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getPodcasts.viewNo AuthorizationuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuitypeQUERYsizeQUERYoffsetQUERYfromYearQUERYtoYearQUERYgenreQUERYmusicFolderIdQUERYapplication/json;charset=UTF-8500get:Faulttext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://localhost/rest/getAlbumList.viewNo Authorization -uremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0csoapuiQUERYsoapuisizeQUERYgenreQUERYfromYearQUERYtoYearQUERYmusicFolderIdQUERYuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyapptypeQUERYsizeQUERYoffsetQUERYfromYearQUERYtoYearQUERYgenreQUERYmusicFolderIdQUERYtext/xml; charset=utf-8200res:subsonic-response0data<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getAlbumList.viewNo Authorization +uadmiQUERYadmipadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuisizeQUERYgenreQUERYfromYearQUERYtoYearQUERYmusicFolderIdQUERYuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuitypeQUERYsizeQUERYoffsetQUERYfromYearQUERYtoYearQUERYgenreQUERYmusicFolderIdQUERYtext/xml; charset=utf-8200res:subsonic-response0datatext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://192.168.0.11/rest/getAlbumList.viewNo Authorization -upvctypesizeoffsetfromYeartoYeargenremusicFolderIduremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0csoapuiQUERYsoapuiidQUERYtext/xml; charset=utf-8200res:subsonic-response<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getAlbum.viewNo AuthorizationujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyappgenreQUERYcountQUERYoffsetQUERYmusicFolderIdQUERYtext/xml; charset=utf-8200res:subsonic-response0data0data0data0data0datatext/html; charset=iso-8859-1503html0data0data0data0data<xml-fragment/>http://localhost:8080/testResthttp://192.168.0.11/rest/getSongsByGenre.viewNo Authorization +upvctypesizeoffsetfromYeartoYeargenremusicFolderIdujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyappgenreQUERYcountQUERYoffsetQUERYmusicFolderIdQUERYtext/xml; charset=utf-8200res:subsonic-response0data0data0data0data0datatext/html; charset=iso-8859-1503html0data0data0data0data<xml-fragment/>http://localhost:8080/testResthttp://192.168.0.11/rest/getSongsByGenre.viewNo Authorization -http://localhost:8080/ \ No newline at end of file +uQUERYpQUERYvQUERYcQUERYtext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://localhost/rest/ping.viewNo Authorization + + + + +upvcuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuiidQUERYtext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://localhost/rest/getAlbum.viewNo Authorizationupvcidhttp://localhost:8080/ \ No newline at end of file From 44de72c602d7bf15c18fc6f1482f3a1720c1b919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 31 Dec 2016 19:03:44 +0100 Subject: [PATCH 47/50] revert commit edd5cc9dd12aadd3aff1abff04d31c9cb8d2a559 --- .../src/main/java/org/libresonic/player/boot/Application.java | 2 +- libresonic-main/src/main/resources/libresonic-servlet.xml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java index 701d597c..86f40157 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java +++ b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java @@ -11,7 +11,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; -@SpringBootApplication(scanBasePackages = "org.libresonic.player.controller,org.libresonic.player.validator,org.libresonic.player.security") +@SpringBootApplication @Configuration @ImportResource(value = {"classpath:/applicationContext-service.xml", "classpath:/applicationContext-cache.xml", diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index d3635bea..5ae4d97e 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -13,6 +13,9 @@ http://www.springframework.org/schema/mvc/spring-mvc.xsd"> + From dbda1132df1a90bdbdaf0d2f474ab81090aedc6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 31 Dec 2016 19:55:02 +0100 Subject: [PATCH 48/50] rest API migration (WIP) + fixes. --- .../player/controller/PlaylistController.java | 2 +- .../PodcastReceiverAdminController.java | 2 +- .../player/controller/RESTController.java | 6 ++--- .../webapp/WEB-INF/jsp/podcastChannels.jsp | 4 ++-- .../libresonic-rest-api-soapui-project.xml | 22 ++++++++++++------- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java index aa950fd3..386b36df 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java @@ -79,7 +79,7 @@ public class PlaylistController { map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username)); map.put("partyMode", userSettings.isPartyModeEnabled()); - return new ModelAndView("playList","model",map); + return new ModelAndView("playlist","model",map); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastReceiverAdminController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastReceiverAdminController.java index f3b19093..579ef30a 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastReceiverAdminController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastReceiverAdminController.java @@ -47,7 +47,7 @@ public class PodcastReceiverAdminController { @Autowired private PodcastService podcastService; - @RequestMapping(method = RequestMethod.GET) + @RequestMapping(method = RequestMethod.POST) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Integer channelId = ServletRequestUtils.getIntParameter(request, "channelId"); diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java index 42c07d7d..d9933700 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java @@ -263,7 +263,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getSongsByGenre", method = RequestMethod.GET) public void getSongsByGenre(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -754,7 +754,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getPlaylists", method = RequestMethod.GET) public void getPlaylists(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -1500,7 +1500,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getPodcasts", method = RequestMethod.GET) public void getPodcasts(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/podcastChannels.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/podcastChannels.jsp index 12bf2f18..7445803c 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/podcastChannels.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/podcastChannels.jsp @@ -99,7 +99,7 @@ - + @@ -107,7 +107,7 @@
"/>
- +
diff --git a/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml b/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml index 3e1096e4..09f1625c 100755 --- a/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml +++ b/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml @@ -1,18 +1,24 @@ -http://localhost:8080/ujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyapptext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data0data0data0data<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/ping.viewNo Authorization - - -upvcujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyappincludeEpisodesQUERYuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyappincludeEpisodesfalseQUERYfalsetext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/ping.viewNo Authorization +http://localhost:8080/uadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuitext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0data0data0data0datatext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://192.168.0.11/rest/ping.viewNo AuthorizationupvcuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuiincludeEpisodesQUERYidQUERYuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyappincludeEpisodesfalseQUERYfalsetext/xml; charset=utf-8200res:subsonic-responsetext/html; charset=iso-8859-1404html0datatext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://192.168.0.11/rest/ping.viewNo Authorization + - - -upvcincludeEpisodesuremiQUERYremipMozart*1QUERYMozart*1v1.2.0QUERY1.2.0cmyappQUERYmyappincludeEpisodestrueQUERYtrueidQUERYtext/xml; charset=utf-8200res:subsonic-response<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getPodcasts.viewNo Authorization<xml-fragment/>http://192.168.0.11:4040http://192.168.0.11/rest/getPodcasts.viewNo AuthorizationuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuitypeQUERYsizeQUERYoffsetQUERYfromYearQUERYtoYearQUERYgenreQUERYmusicFolderIdQUERYapplication/json;charset=UTF-8500get:Faulttext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://localhost/rest/getAlbumList.viewNo Authorization + + + +upvcincludeEpisodes<xml-fragment/>http://localhost:8080/http://192.168.0.11/rest/ping.viewNo Authorization + + + + + + +upvcincludeEpisodesuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuitypeQUERYsizeQUERYoffsetQUERYfromYearQUERYtoYearQUERYgenreQUERYmusicFolderIdQUERYapplication/json;charset=UTF-8500get:Faulttext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://localhost/rest/getAlbumList.viewNo Authorization uadmiQUERYadmipadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuisizeQUERYgenreQUERYfromYearQUERYtoYearQUERYmusicFolderIdQUERYuadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuitypeQUERYsizeQUERYoffsetQUERYfromYearQUERYtoYearQUERYgenreQUERYmusicFolderIdQUERYtext/xml; charset=utf-8200res:subsonic-response0datatext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://192.168.0.11/rest/getAlbumList.viewNo Authorization -upvctypesizeoffsetfromYeartoYeargenremusicFolderIdujoeQUERYjoepsesameQUERYsesamev1.12.0QUERY1.12.0cmyappQUERYmyappgenreQUERYcountQUERYoffsetQUERYmusicFolderIdQUERYtext/xml; charset=utf-8200res:subsonic-response0data0data0data0data0datatext/html; charset=iso-8859-1503html0data0data0data0data<xml-fragment/>http://localhost:8080/testResthttp://192.168.0.11/rest/getSongsByGenre.viewNo Authorization +upvctypesizeoffsetfromYeartoYeargenremusicFolderIduadminQUERYadminpadminQUERYadminv1.13.0QUERY1.13.0csoapuiQUERYsoapuigenreQUERYcountQUERYoffsetQUERYmusicFolderIdQUERYtext/xml; charset=utf-8200res:subsonic-response0data0data0data0data0datatext/html; charset=iso-8859-1503html0data0data0data0datatext/xml;charset=UTF-8200res:subsonic-response<xml-fragment/>http://localhost:8080/http://192.168.0.11/rest/getSongsByGenre.viewNo Authorization From 03938ca49772f27f90e880fb48b9b12985ab7cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sat, 31 Dec 2016 20:33:41 +0100 Subject: [PATCH 49/50] rest API migration. --- .../player/controller/RESTController.java | 113 +++++++++--------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java index d9933700..2711ef97 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java @@ -159,7 +159,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getMusicFolders", method = RequestMethod.GET) public void getMusicFolders(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -176,7 +176,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getIndexes", method = RequestMethod.GET) public void getIndexes(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Response res = createResponse(); @@ -246,7 +246,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getGenres", method = RequestMethod.GET) public void getGenres(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Genres genres = new Genres(); @@ -286,7 +286,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getArtists", method = RequestMethod.GET) public void getArtists(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); String username = securityService.getCurrentUsername(request); @@ -311,7 +311,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getSimilarSongs", method = RequestMethod.GET) public void getSimilarSongs(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); String username = securityService.getCurrentUsername(request); @@ -338,7 +338,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getSimilarSongs2", method = RequestMethod.GET) public void getSimilarSongs2(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); String username = securityService.getCurrentUsername(request); @@ -366,7 +366,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getTopSongs", method = RequestMethod.GET) public void getTopSongs(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); String username = securityService.getCurrentUsername(request); @@ -388,7 +388,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getArtistInfo", method = RequestMethod.GET) public void getArtistInfo(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); String username = securityService.getCurrentUsername(request); @@ -424,7 +424,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getArtistInfo2", method = RequestMethod.GET) public void getArtistInfo2(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); String username = securityService.getCurrentUsername(request); @@ -481,6 +481,7 @@ public class RESTController { return result; } + @RequestMapping(value = "/rest/getArtist", method = RequestMethod.GET) public void getArtist(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -566,7 +567,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getSong", method = RequestMethod.GET) public void getSong(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -588,7 +589,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getMusicDirectory", method = RequestMethod.GET) public void getMusicDirectory(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -632,7 +633,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @Deprecated + @RequestMapping(value = "/rest/search", method = RequestMethod.GET) public void search(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -676,7 +677,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/search2", method = RequestMethod.GET) public void search2(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -715,7 +716,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/search3", method = RequestMethod.GET) public void search3(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -780,6 +781,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } + @RequestMapping(value = "/rest/getPlaylist", method = RequestMethod.GET) public void getPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -808,7 +810,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/jukeboxControl", method = RequestMethod.GET) public void jukeboxControl(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request, true); @@ -887,7 +889,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/createPlaylist", method = RequestMethod.GET) public void createPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request, true); String username = securityService.getCurrentUsername(request); @@ -932,7 +934,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/updatePlaylist", method = RequestMethod.GET) public void updatePlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request, true); String username = securityService.getCurrentUsername(request); @@ -1000,7 +1002,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/deletePlaylist", method = RequestMethod.GET) public void deletePlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request, true); String username = securityService.getCurrentUsername(request); @@ -1071,7 +1073,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getAlbumList2", method = RequestMethod.GET) public void getAlbumList2(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -1139,7 +1141,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getVideos", method = RequestMethod.GET) public void getVideos(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -1158,7 +1160,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getNowPlaying", method = RequestMethod.GET) public void getNowPlaying(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); NowPlaying result = new NowPlaying(); @@ -1311,6 +1313,7 @@ public class RESTController { return null; } + @RequestMapping(value = "/rest/download", method = RequestMethod.GET) public ModelAndView download(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -1334,6 +1337,7 @@ public class RESTController { return downloadController.handleRequest(request, response); } + @RequestMapping(value = "/rest/stream", method = RequestMethod.GET) public ModelAndView stream(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -1346,6 +1350,7 @@ public class RESTController { return null; } + @RequestMapping(value = "/rest/hls", method = RequestMethod.GET) public ModelAndView hls(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -1367,7 +1372,7 @@ public class RESTController { return null; } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/scrobble", method = RequestMethod.GET) public void scrobble(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -1400,12 +1405,12 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/star", method = RequestMethod.GET) public void star(HttpServletRequest request, HttpServletResponse response) throws Exception { starOrUnstar(request, response, true); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/unstar", method = RequestMethod.GET) public void unstar(HttpServletRequest request, HttpServletResponse response) throws Exception { starOrUnstar(request, response, false); } @@ -1454,7 +1459,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getStarred", method = RequestMethod.GET) public void getStarred(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -1477,7 +1482,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getStarred2", method = RequestMethod.GET) public void getStarred2(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -1538,7 +1543,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getNewestPodcasts", method = RequestMethod.GET) public void getNewestPodcasts(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -1575,7 +1580,7 @@ public class RESTController { return e; } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/refreshPodcasts", method = RequestMethod.GET) public void refreshPodcasts(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -1587,7 +1592,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/createPodcastChannel", method = RequestMethod.GET) public void createPodcastChannel(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -1601,7 +1606,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/deletePodcastChannel", method = RequestMethod.GET) public void deletePodcastChannel(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -1615,7 +1620,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/deletePodcastEpisode", method = RequestMethod.GET) public void deletePodcastEpisode(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -1629,7 +1634,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/downloadPodcastEpisode", method = RequestMethod.GET) public void downloadPodcastEpisode(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -1649,7 +1654,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getInternetRadioStations", method = RequestMethod.GET) public void getInternetRadioStations(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -1667,7 +1672,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getBookmarks", method = RequestMethod.GET) public void getBookmarks(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -1692,7 +1697,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/createBookmark", method = RequestMethod.GET) public void createBookmark(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); String username = securityService.getCurrentUsername(request); @@ -1707,7 +1712,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/deleteBookmark", method = RequestMethod.GET) public void deleteBookmark(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -1719,7 +1724,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getPlayQueue", method = RequestMethod.GET) public void getPlayQueue(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); String username = securityService.getCurrentUsername(request); @@ -1750,7 +1755,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/savePlayQueue", method = RequestMethod.GET) public void savePlayQueue(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); String username = securityService.getCurrentUsername(request); @@ -1770,7 +1775,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getShares", method = RequestMethod.GET) public void getShares(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -1792,7 +1797,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/createShare", method = RequestMethod.GET) public void createShare(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Player player = playerService.getPlayer(request, response); @@ -1837,7 +1842,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/deleteShare", method = RequestMethod.GET) public void deleteShare(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -1857,7 +1862,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/updateShare", method = RequestMethod.GET) public void updateShare(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -1930,19 +1935,19 @@ public class RESTController { return result; } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getCoverArt", method = RequestMethod.GET) public ModelAndView getCoverArt(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); return coverArtController.handleRequest(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getAvatar", method = RequestMethod.GET) public ModelAndView getAvatar(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); return avatarController.handleRequest(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/changePassword", method = RequestMethod.GET) public void changePassword(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -1966,7 +1971,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getUser", method = RequestMethod.GET) public void getUser(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -1989,7 +1994,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getUsers", method = RequestMethod.GET) public void getUsers(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -2040,7 +2045,7 @@ public class RESTController { return result; } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/createUser", method = RequestMethod.GET) public void createUser(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -2076,7 +2081,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/updateUser", method = RequestMethod.GET) public void updateUser(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -2134,7 +2139,7 @@ public class RESTController { return request.getParameter(name) != null; } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/deleteUser", method = RequestMethod.GET) public void deleteUser(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); User user = securityService.getCurrentUser(request); @@ -2154,7 +2159,7 @@ public class RESTController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getChatMessages", method = RequestMethod.GET) public void getChatMessages(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); long since = getLongParameter(request, "since", 0L); @@ -2175,14 +2180,14 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/addChatMessage", method = RequestMethod.GET) public void addChatMessage(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); chatService.doAddMessage(getRequiredStringParameter(request, "message"), request); writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getLyrics", method = RequestMethod.GET) public void getLyrics(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); String artist = request.getParameter("artist"); @@ -2199,7 +2204,7 @@ public class RESTController { jaxbWriter.writeResponse(request, response, res); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/setRating", method = RequestMethod.GET) public void setRating(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); Integer rating = getRequiredIntParameter(request, "rating"); From d6870f7c7578d5de74575969843bdc20061d0387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 1 Jan 2017 16:23:00 +0100 Subject: [PATCH 50/50] Ignore some dependency analyse errors --- pom.xml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 365a4baf..e0b6a88d 100644 --- a/pom.xml +++ b/pom.xml @@ -173,14 +173,20 @@ ${failOnDependencyWarning} true + + org.springframework:* + org.springframework.security:* + org.springframework.boot:* + org.apache.tomcat.embed:tomcat-embed-core* + - - com.sun.mail:javax.mail* - org.seamless:seamless-http* - - - org.springframework.security:spring-security-config* - + com.sun.mail:javax.mail* + org.seamless:seamless-http* + taglibs:string:jar* + org.seamless:seamless-http* + + org.springframework.security:* + org.springframework.boot:spring-boot*