Controller migration
This commit is contained in:
+28
@@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+51
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+28
@@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+38
-101
@@ -1,24 +1,20 @@
|
|||||||
/*
|
|
||||||
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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Copyright 2016 (C) Libresonic Authors
|
|
||||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
|
||||||
*/
|
|
||||||
package org.libresonic.player.controller;
|
package org.libresonic.player.controller;
|
||||||
|
|
||||||
|
import net.tanesha.recaptcha.ReCaptcha;
|
||||||
|
import net.tanesha.recaptcha.ReCaptchaFactory;
|
||||||
|
import net.tanesha.recaptcha.ReCaptchaResponse;
|
||||||
|
import org.apache.commons.lang.RandomStringUtils;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.libresonic.player.Logger;
|
||||||
|
import org.libresonic.player.domain.User;
|
||||||
|
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.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import javax.mail.Transport;
|
import javax.mail.Transport;
|
||||||
@@ -26,44 +22,27 @@ import javax.mail.internet.InternetAddress;
|
|||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
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.web.servlet.ModelAndView;
|
|
||||||
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
|
|
||||||
import org.springframework.web.servlet.view.RedirectView;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multi-controller used for simple pages.
|
* Spring MVC Controller that serves the login page.
|
||||||
*
|
|
||||||
* @author Sindre Mehus
|
|
||||||
*/
|
*/
|
||||||
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 SettingsService settingsService;
|
||||||
private PlaylistService playlistService;
|
@Autowired
|
||||||
|
private SecurityService securityService;
|
||||||
|
|
||||||
|
@RequestMapping(method = {RequestMethod.GET})
|
||||||
public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
@@ -107,9 +86,20 @@ public class MultiController extends MultiActionController {
|
|||||||
return new ModelAndView("recover", "model", map);
|
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) {
|
private boolean emailPassword(String password, String username, String email) {
|
||||||
/* Default to protocol smtp when SmtpEncryption is set to "None" */
|
/* Default to protocol smtp when SmtpEncryption is set to "None" */
|
||||||
String prot = "smtp";
|
String prot = "smtp";
|
||||||
@@ -169,57 +159,4 @@ public class MultiController extends MultiActionController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private User getUserByUsernameOrEmail(String usernameOrEmail) {
|
|
||||||
if (usernameOrEmail != null) {
|
|
||||||
User user = securityService.getUserByName(usernameOrEmail);
|
|
||||||
if (user != null) {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
return securityService.getUserByEmail(usernameOrEmail);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModelAndView accessDenied(HttpServletRequest request, HttpServletResponse response) {
|
|
||||||
return new ModelAndView("accessDenied");
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModelAndView notFound(HttpServletRequest request, HttpServletResponse response) {
|
|
||||||
return new ModelAndView("notFound");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ModelAndView exportPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
||||||
|
|
||||||
int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
|
|
||||||
Playlist playlist = playlistService.getPlaylist(id);
|
|
||||||
if (!playlistService.isReadAllowed(playlist, securityService.getCurrentUsername(request))) {
|
|
||||||
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
response.setContentType("application/x-download");
|
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + StringUtil.fileSystemSafe(playlist.getName()) + ".m3u8\"");
|
|
||||||
|
|
||||||
playlistService.exportPlaylist(id, response.getOutputStream());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ModelAndView test(HttpServletRequest request, HttpServletResponse response) {
|
|
||||||
return new ModelAndView("test");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSecurityService(SecurityService securityService) {
|
|
||||||
this.securityService = securityService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSettingsService(SettingsService settingsService) {
|
|
||||||
this.settingsService = settingsService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlaylistService(PlaylistService playlistService) {
|
|
||||||
this.playlistService = playlistService;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -53,11 +53,6 @@
|
|||||||
<property name="settingsService" ref="settingsService"/>
|
<property name="settingsService" ref="settingsService"/>
|
||||||
<property name="mediaFileService" ref="mediaFileService"/>
|
<property name="mediaFileService" ref="mediaFileService"/>
|
||||||
</bean>
|
</bean>
|
||||||
<bean id="multiController" class="org.libresonic.player.controller.MultiController">
|
|
||||||
<property name="securityService" ref="securityService"/>
|
|
||||||
<property name="settingsService" ref="settingsService"/>
|
|
||||||
<property name="playlistService" ref="playlistService"/>
|
|
||||||
</bean>
|
|
||||||
<bean id="wapController" class="org.libresonic.player.controller.WapController">
|
<bean id="wapController" class="org.libresonic.player.controller.WapController">
|
||||||
<property name="settingsService" ref="settingsService"/>
|
<property name="settingsService" ref="settingsService"/>
|
||||||
<property name="playerService" ref="playerService"/>
|
<property name="playerService" ref="playerService"/>
|
||||||
@@ -108,15 +103,9 @@
|
|||||||
<property name="alwaysUseFullPath" value="true"/>
|
<property name="alwaysUseFullPath" value="true"/>
|
||||||
<property name="mappings">
|
<property name="mappings">
|
||||||
<props>
|
<props>
|
||||||
<prop key="/exportPlaylist.view">multiController</prop>
|
|
||||||
<prop key="/recover.view">multiController</prop>
|
|
||||||
<prop key="/accessDenied.view">multiController</prop>
|
|
||||||
<prop key="/notFound.view">multiController</prop>
|
|
||||||
<prop key="/index.view">multiController</prop>
|
|
||||||
<prop key="/videoPlayer.view">videoPlayerController</prop>
|
<prop key="/videoPlayer.view">videoPlayerController</prop>
|
||||||
<prop key="/download.view">downloadController</prop>
|
<prop key="/download.view">downloadController</prop>
|
||||||
<prop key="/db.view">dbController</prop>
|
<prop key="/db.view">dbController</prop>
|
||||||
<prop key="/test.view">multiController</prop>
|
|
||||||
<prop key="/podcast/**">podcastController</prop>
|
<prop key="/podcast/**">podcastController</prop>
|
||||||
<prop key="/wap/download.view">downloadController</prop>
|
<prop key="/wap/download.view">downloadController</prop>
|
||||||
<prop key="/wap/**">wapController</prop>
|
<prop key="/wap/**">wapController</prop>
|
||||||
|
|||||||
Reference in New Issue
Block a user