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 22eefcfe..727a7768 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 9232f483..40ae8b15 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 @@ -30,63 +30,63 @@ ${project.version} - + io.dropwizard.metrics metrics-core ${metrics.version} test + + - org.springframework - spring-core + org.springframework.boot + spring-boot-starter-web - - org.springframework - spring-webmvc + org.springframework.boot + spring-boot-starter-tomcat + provided - - org.springframework - spring-web + org.apache.tomcat.embed + tomcat-embed-jasper + provided - - org.springframework - spring-jdbc + org.springframework.boot + spring-boot-starter-jdbc - - org.springframework - spring-tx + org.springframework.boot + spring-boot-starter-security - - org.springframework - spring-context - - - - org.springframework - spring-beans + org.springframework.security + spring-security-ldap - org.springframework.security - spring-security-core + spring-security-taglibs + + - org.springframework.security - spring-security-web + javax.servlet + jstl + 1.2 - - org.springframework.security - spring-security-config + taglibs + string + 1.1.0 + org.apache.lucene @@ -162,19 +162,6 @@ 1.0-b2 - - log4j - log4j - 1.2.16 - runtime - - - - org.slf4j - slf4j-log4j12 - 1.6.1 - runtime - org.directwebremoting @@ -236,46 +223,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 @@ -386,6 +339,10 @@ full + + org.springframework.boot + spring-boot-maven-plugin + org.codehaus.mojo buildnumber-maven-plugin @@ -410,7 +367,20 @@ libresonic - + + org.springframework.boot + spring-boot-maven-plugin + + org.libresonic.player.boot.Application + + + + + repackage + + + + org.apache.maven.plugins maven-antrun-plugin 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..86f40157 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/boot/Application.java @@ -0,0 +1,49 @@ +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; +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; + +@SpringBootApplication +@Configuration +@ImportResource(value = {"classpath:/applicationContext-service.xml", + "classpath:/applicationContext-cache.xml", + "classpath:/applicationContext-sonos.xml", + "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/*"); + servlet.addInitParameter("crossDomainSessionSecurity","false"); + return servlet; + } + + + @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 springApplication = new SpringApplication(Application.class); + springApplication.addInitializers(new AdditionalPropertySourceConfigurer()); + springApplication.run(args); + } + +} \ No newline at end of file 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/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/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/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/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/ChangeCoverArtController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java index 9047564a..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,30 +19,34 @@ */ 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.apache.commons.lang.StringUtils; +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. * * @author Sindre Mehus */ -public class ChangeCoverArtController extends ParameterizableViewController { +@Controller +@RequestMapping("/changeCoverArt") +public class ChangeCoverArtController { + @Autowired private MediaFileService mediaFileService; - @Override + @RequestMapping(method = RequestMethod.GET) protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); @@ -57,18 +61,13 @@ public class ChangeCoverArtController extends ParameterizableViewController { album = dir.getAlbumName(); } - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("id", id); 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/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/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/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/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/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/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/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/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/HLSController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/HLSController.java index 04cf4f52..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 @@ -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(value = "hlsController") +@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/java/org/libresonic/player/controller/HelpController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/HelpController.java index b4b6d023..67613f4e 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); @@ -74,20 +83,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/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/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/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/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/LoginController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java index 1c74da4d..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; @@ -43,7 +42,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/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/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/java/org/libresonic/player/controller/MainController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/MainController.java index ece27c3d..b9fc3004 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); @@ -158,9 +151,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) { @@ -187,7 +178,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) { @@ -222,18 +213,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); @@ -248,41 +239,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/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/MusicFolderSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/MusicFolderSettingsController.java index 65108f2a..314b88e6 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 @@ -37,6 +37,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; 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. @@ -96,11 +97,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/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/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 f6f5e8cd..11a9d085 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)); @@ -61,9 +67,7 @@ public class PlayQueueController extends ParameterizableViewController { map.put("partyMode", userSettings.isPartyModeEnabled()); map.put("notify", userSettings.isSongNotificationEnabled()); map.put("autoHide", userSettings.isAutoHidePlayQueue()); - 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/PlaylistController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlaylistController.java index 138ba550..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 @@ -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/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/java/org/libresonic/player/controller/PodcastChannelsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastChannelsController.java index 3c4f8376..a01155e1 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); @@ -67,15 +73,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/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/java/org/libresonic/player/controller/PodcastReceiverAdminController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastReceiverAdminController.java index 7c7858c2..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 @@ -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.POST) 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/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/java/org/libresonic/player/controller/RESTController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java index a61b7fb7..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 @@ -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,13 +153,13 @@ 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); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getMusicFolders", method = RequestMethod.GET) public void getMusicFolders(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -222,7 +176,7 @@ public class RESTController extends MultiActionController { 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(); @@ -292,7 +246,7 @@ public class RESTController extends MultiActionController { 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(); @@ -309,7 +263,7 @@ public class RESTController extends MultiActionController { 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); @@ -332,7 +286,7 @@ public class RESTController extends MultiActionController { 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); @@ -357,7 +311,7 @@ public class RESTController extends MultiActionController { 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); @@ -384,7 +338,7 @@ public class RESTController extends MultiActionController { 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); @@ -412,7 +366,7 @@ public class RESTController extends MultiActionController { 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); @@ -434,7 +388,7 @@ public class RESTController extends MultiActionController { 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); @@ -470,7 +424,7 @@ public class RESTController extends MultiActionController { 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); @@ -527,6 +481,7 @@ public class RESTController extends MultiActionController { return result; } + @RequestMapping(value = "/rest/getArtist", method = RequestMethod.GET) public void getArtist(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -589,7 +544,7 @@ public class RESTController extends MultiActionController { 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); @@ -612,7 +567,7 @@ public class RESTController extends MultiActionController { 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); @@ -634,7 +589,7 @@ public class RESTController extends MultiActionController { 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); @@ -678,7 +633,7 @@ public class RESTController extends MultiActionController { 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); @@ -722,7 +677,7 @@ public class RESTController extends MultiActionController { 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); @@ -761,7 +716,7 @@ public class RESTController extends MultiActionController { 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); @@ -800,7 +755,7 @@ public class RESTController extends MultiActionController { 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); @@ -826,6 +781,7 @@ public class RESTController extends MultiActionController { 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); @@ -854,7 +810,7 @@ public class RESTController extends MultiActionController { 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); @@ -933,7 +889,7 @@ public class RESTController extends MultiActionController { 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); @@ -978,7 +934,7 @@ public class RESTController extends MultiActionController { 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); @@ -1046,7 +1002,7 @@ public class RESTController extends MultiActionController { 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); @@ -1066,7 +1022,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); @@ -1117,7 +1073,7 @@ public class RESTController extends MultiActionController { 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); @@ -1161,7 +1117,7 @@ public class RESTController extends MultiActionController { 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); @@ -1185,7 +1141,7 @@ public class RESTController extends MultiActionController { 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); @@ -1204,7 +1160,7 @@ public class RESTController extends MultiActionController { 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(); @@ -1357,6 +1313,7 @@ public class RESTController extends MultiActionController { 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); @@ -1380,6 +1337,7 @@ public class RESTController extends MultiActionController { 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); @@ -1392,6 +1350,7 @@ public class RESTController extends MultiActionController { 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); @@ -1413,7 +1372,7 @@ public class RESTController extends MultiActionController { return null; } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/scrobble", method = RequestMethod.GET) public void scrobble(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -1446,12 +1405,12 @@ public class RESTController extends MultiActionController { 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); } @@ -1500,7 +1459,7 @@ public class RESTController extends MultiActionController { 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); @@ -1523,7 +1482,7 @@ public class RESTController extends MultiActionController { 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); @@ -1546,7 +1505,7 @@ public class RESTController extends MultiActionController { 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); @@ -1584,7 +1543,7 @@ public class RESTController extends MultiActionController { 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); @@ -1621,7 +1580,7 @@ public class RESTController extends MultiActionController { 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); @@ -1633,7 +1592,7 @@ public class RESTController extends MultiActionController { 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); @@ -1647,7 +1606,7 @@ public class RESTController extends MultiActionController { 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); @@ -1661,7 +1620,7 @@ public class RESTController extends MultiActionController { 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); @@ -1675,7 +1634,7 @@ public class RESTController extends MultiActionController { 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); @@ -1695,7 +1654,7 @@ public class RESTController extends MultiActionController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getInternetRadioStations", method = RequestMethod.GET) public void getInternetRadioStations(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -1713,7 +1672,7 @@ public class RESTController extends MultiActionController { 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); @@ -1738,7 +1697,7 @@ public class RESTController extends MultiActionController { 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); @@ -1753,7 +1712,7 @@ public class RESTController extends MultiActionController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/deleteBookmark", method = RequestMethod.GET) public void deleteBookmark(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -1765,7 +1724,7 @@ public class RESTController extends MultiActionController { 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); @@ -1796,7 +1755,7 @@ public class RESTController extends MultiActionController { 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); @@ -1816,7 +1775,7 @@ public class RESTController extends MultiActionController { 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); @@ -1838,7 +1797,7 @@ public class RESTController extends MultiActionController { 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); @@ -1883,7 +1842,7 @@ public class RESTController extends MultiActionController { 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); @@ -1903,7 +1862,7 @@ public class RESTController extends MultiActionController { 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); @@ -1976,19 +1935,19 @@ public class RESTController extends MultiActionController { 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); @@ -2012,7 +1971,7 @@ public class RESTController extends MultiActionController { writeEmptyResponse(request, response); } - @SuppressWarnings("UnusedDeclaration") + @RequestMapping(value = "/rest/getUser", method = RequestMethod.GET) public void getUser(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request); @@ -2035,7 +1994,7 @@ public class RESTController extends MultiActionController { 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); @@ -2086,7 +2045,7 @@ public class RESTController extends MultiActionController { 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); @@ -2122,7 +2081,7 @@ public class RESTController extends MultiActionController { 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); @@ -2180,7 +2139,7 @@ public class RESTController extends MultiActionController { 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); @@ -2200,7 +2159,7 @@ public class RESTController extends MultiActionController { 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); @@ -2221,14 +2180,14 @@ public class RESTController extends MultiActionController { 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"); @@ -2245,7 +2204,7 @@ public class RESTController extends MultiActionController { 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"); @@ -2342,125 +2301,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/java/org/libresonic/player/controller/MultiController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/RecoverController.java similarity index 52% 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 31dd871d..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,103 +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 gettingStarted(HttpServletRequest request, HttpServletResponse response) { - updatePortAndContextPath(request); - - 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 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 { - - 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; - } - - 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"); - } - - 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/RightController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/RightController.java index f042c7f0..42ecb68b 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()) { @@ -68,15 +73,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; - } } 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/java/org/libresonic/player/controller/SetRatingController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java index d7962dfc..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 @@ -19,53 +19,48 @@ */ 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.bind.annotation.RequestMethod; +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 { + + @RequestMapping(method = RequestMethod.GET) + 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/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/java/org/libresonic/player/controller/ShareManagementController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ShareManagementController.java index 30f7a8e7..4305906d 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); @@ -94,7 +97,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); @@ -121,27 +124,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; - } } 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/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/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/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/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/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/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/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/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/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/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/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 f5274148..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,13 +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.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.security.web.util.matcher.RegexRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; @@ -56,11 +57,17 @@ public class RESTRequestParameterProcessingFilter implements Filter { private static final Logger LOG = Logger.getLogger(RESTRequestParameterProcessingFilter.class); private final JAXBWriter jaxbWriter = new JAXBWriter(); - private ProviderManager authenticationManager; - private SettingsService settingsService; + private AuthenticationManager authenticationManager; private SecurityService securityService; 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"); @@ -72,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")); @@ -185,18 +199,20 @@ public class RESTRequestParameterProcessingFilter implements Filter { public void destroy() { } - public void setAuthenticationManager(ProviderManager authenticationManager) { + + public void setAuthenticationManager(AuthenticationManager authenticationManager) { this.authenticationManager = authenticationManager; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; + 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/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-db-embed.xml b/libresonic-main/src/main/resources/applicationContext-db-embed.xml similarity index 65% rename from libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-embed.xml rename to libresonic-main/src/main/resources/applicationContext-db-embed.xml index 5ee2f378..4ba2e7ed 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/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/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 66% rename from libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-legacy.xml rename to libresonic-main/src/main/resources/applicationContext-db-legacy.xml index fbceea74..77b96a94 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-legacy.xml +++ b/libresonic-main/src/main/resources/applicationContext-db-legacy.xml @@ -1,10 +1,7 @@ + + + + + + + + + + + + podcastController + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml deleted file mode 100644 index ac13f0f0..00000000 --- a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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..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,9 @@ -
" method="POST"> + + +
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/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 @@ - +

" diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml deleted file mode 100644 index d1a1ca92..00000000 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ /dev/null @@ -1,370 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - mainController - playlistController - playlistsController - helpController - lyricsController - leftController - rightController - statusController - moreController - uploadController - importPlaylistController - multiController - setMusicFileInfoController - shareManagementController - setRatingController - topController - changeCoverArtController - - multiController - multiController - multiController - multiController - multiController - videoPlayerController - nowPlayingController - starredController - settingsController - avatarUploadController - allmusicController - homeController - editTagsController - playQueueController - coverArtController - avatarController - proxyController - statusChartController - userChartController - downloadController - dbController - multiController - podcastChannelsController - podcastChannelController - podcastReceiverAdminController - podcastController - podcastController - downloadController - wapController - restController - m3uController - streamController - hlsController - externalPlayerController - - - - - - - - - - - - - - - - - - - - - - - - - - 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..09f1625c --- /dev/null +++ b/libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml @@ -0,0 +1,30 @@ + +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 + + + + + +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 + + +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 + + + +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 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 097d32b2..e0b6a88d 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 @@ -17,8 +17,6 @@ true iso-8859-1 3.1.8 - 4.3.4.RELEASE - 3.2.9.RELEASE @@ -96,60 +94,12 @@ - org.springframework - spring-core - ${spring.version} - - - 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 @@ -213,6 +163,7 @@ org.apache.maven.plugins maven-dependency-plugin + 2.10 analyze @@ -222,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*