From 53dc138574778606621608c9b43e9fdb11d6fbb4 Mon Sep 17 00:00:00 2001 From: Andrew DeMaria Date: Sun, 15 May 2016 21:05:37 -0600 Subject: [PATCH 01/27] Update to spring 3.X.X temporarily Signed-off-by: Andrew DeMaria --- libresonic-booter/pom.xml | 1 - libresonic-main/pom.xml | 28 ++-------------------------- pom.xml | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/libresonic-booter/pom.xml b/libresonic-booter/pom.xml index 451198ff..b8bf1a68 100644 --- a/libresonic-booter/pom.xml +++ b/libresonic-booter/pom.xml @@ -55,7 +55,6 @@ org.springframework spring - 2.5.6 diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 3ecbe9f6..449f002f 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -28,36 +28,12 @@ org.springframework - spring - 2.5.6 + spring-webmvc org.springframework - spring-webmvc - 2.5.6 - - - org.springframework - spring-beans - - - org.springframework - spring-core - - - org.springframework - spring-context - - - org.springframework - spring-context-support - - - org.springframework - spring-web - - + spring-jdbc diff --git a/pom.xml b/pom.xml index 3ecb5b92..b8e6b250 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,7 @@ true iso-8859-1 2.4.2 + 3.2.17.RELEASE @@ -91,6 +92,21 @@ + + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-jdbc + ${spring.version} + + + + From 3213b3f1151fb125771b9f9817bfe5b0395606c0 Mon Sep 17 00:00:00 2001 From: Andrew DeMaria Date: Sun, 15 May 2016 21:06:20 -0600 Subject: [PATCH 02/27] Update dao layer to use update spring-jdbc 3/4 api Signed-off-by: Andrew DeMaria --- .../org/libresonic/player/dao/AlbumDao.java | 3 +-- .../org/libresonic/player/dao/ArtistDao.java | 3 +-- .../org/libresonic/player/dao/AvatarDao.java | 6 ++--- .../libresonic/player/dao/BookmarkDao.java | 6 ++--- .../player/dao/InternetRadioDao.java | 6 ++--- .../libresonic/player/dao/MediaFileDao.java | 23 +++++++------------ .../libresonic/player/dao/MusicFolderDao.java | 11 ++++----- .../libresonic/player/dao/PlayQueueDao.java | 3 +-- .../org/libresonic/player/dao/PlayerDao.java | 23 ++++++------------- .../libresonic/player/dao/PlaylistDao.java | 3 +-- .../org/libresonic/player/dao/PodcastDao.java | 5 ++-- .../org/libresonic/player/dao/ShareDao.java | 8 +++---- .../libresonic/player/dao/TranscodingDao.java | 6 ++--- .../org/libresonic/player/dao/UserDao.java | 19 ++++++--------- 14 files changed, 49 insertions(+), 76 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/AlbumDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/AlbumDao.java index 71515156..71cffec2 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/AlbumDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/AlbumDao.java @@ -29,7 +29,6 @@ import java.util.Map; import org.apache.commons.lang.ObjectUtils; import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.libresonic.player.domain.Album; import org.libresonic.player.domain.MediaFile; @@ -346,7 +345,7 @@ public class AlbumDao extends AbstractDao { return queryForDate("select created from starred_album where album_id=? and username=?", null, albumId, username); } - private static class AlbumMapper implements ParameterizedRowMapper { + private static class AlbumMapper implements RowMapper { public Album mapRow(ResultSet rs, int rowNum) throws SQLException { return new Album( rs.getInt(1), diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/ArtistDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/ArtistDao.java index ea98c9c3..f7b44367 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/ArtistDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/ArtistDao.java @@ -24,7 +24,6 @@ import org.libresonic.player.domain.Artist; import org.libresonic.player.domain.MusicFolder; import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import java.sql.ResultSet; import java.sql.SQLException; @@ -199,7 +198,7 @@ public class ArtistDao extends AbstractDao { return queryForDate("select created from starred_artist where artist_id=? and username=?", null, artistId, username); } - private static class ArtistMapper implements ParameterizedRowMapper { + private static class ArtistMapper implements RowMapper { public Artist mapRow(ResultSet rs, int rowNum) throws SQLException { return new Artist( rs.getInt(1), diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/AvatarDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/AvatarDao.java index b571ffc2..118816ce 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/AvatarDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/AvatarDao.java @@ -20,7 +20,7 @@ package org.libresonic.player.dao; import org.libresonic.player.domain.Avatar; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; +import org.springframework.jdbc.core.RowMapper; import java.sql.ResultSet; import java.sql.SQLException; @@ -85,11 +85,11 @@ public class AvatarDao extends AbstractDao { } } - private static class AvatarRowMapper implements ParameterizedRowMapper { + private static class AvatarRowMapper implements RowMapper { public Avatar mapRow(ResultSet rs, int rowNum) throws SQLException { return new Avatar(rs.getInt(1), rs.getString(2), rs.getTimestamp(3), rs.getString(4), rs.getInt(5), rs.getInt(6), rs.getBytes(7)); } } -} \ No newline at end of file +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/BookmarkDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/BookmarkDao.java index de7a976f..1ea9ac44 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/BookmarkDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/BookmarkDao.java @@ -19,12 +19,12 @@ */ package org.libresonic.player.dao; +import org.springframework.jdbc.core.RowMapper; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; - import org.libresonic.player.domain.Bookmark; /** @@ -81,7 +81,7 @@ public class BookmarkDao extends AbstractDao { update("delete from bookmark where username=? and media_file_id=?", username, mediaFileId); } - private static class BookmarkRowMapper implements ParameterizedRowMapper { + private static class BookmarkRowMapper implements RowMapper { public Bookmark mapRow(ResultSet rs, int rowNum) throws SQLException { return new Bookmark(rs.getInt(1), rs.getInt(2), rs.getLong(3), rs.getString(4), rs.getString(5), rs.getTimestamp(6), rs.getTimestamp(7)); diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/InternetRadioDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/InternetRadioDao.java index b1a1d4d4..385e4a90 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/InternetRadioDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/InternetRadioDao.java @@ -19,12 +19,12 @@ */ package org.libresonic.player.dao; +import org.springframework.jdbc.core.RowMapper; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; - import org.libresonic.player.Logger; import org.libresonic.player.domain.InternetRadio; @@ -81,7 +81,7 @@ public class InternetRadioDao extends AbstractDao { update(sql, radio.getName(), radio.getStreamUrl(), radio.getHomepageUrl(), radio.isEnabled(), radio.getChanged(), radio.getId()); } - private static class InternetRadioRowMapper implements ParameterizedRowMapper { + private static class InternetRadioRowMapper implements RowMapper { public InternetRadio mapRow(ResultSet rs, int rowNum) throws SQLException { return new InternetRadio(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getBoolean(5), rs.getTimestamp(6)); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/MediaFileDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/MediaFileDao.java index 25968340..78dd0b47 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/MediaFileDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/MediaFileDao.java @@ -19,22 +19,15 @@ */ package org.libresonic.player.dao; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.apache.commons.lang.StringUtils; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; - import org.libresonic.player.domain.Genre; import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.MusicFolder; +import org.springframework.jdbc.core.RowMapper; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; import static org.libresonic.player.domain.MediaFile.MediaType; import static org.libresonic.player.domain.MediaFile.MediaType.*; @@ -568,7 +561,7 @@ public class MediaFileDao extends AbstractDao { update("checkpoint"); } - private static class MediaFileMapper implements ParameterizedRowMapper { + private static class MediaFileMapper implements RowMapper { public MediaFile mapRow(ResultSet rs, int rowNum) throws SQLException { return new MediaFile( rs.getInt(1), @@ -604,7 +597,7 @@ public class MediaFileDao extends AbstractDao { } } - private static class MusicFileInfoMapper implements ParameterizedRowMapper { + private static class MusicFileInfoMapper implements RowMapper { public MediaFile mapRow(ResultSet rs, int rowNum) throws SQLException { MediaFile file = new MediaFile(); file.setPlayCount(rs.getInt(1)); @@ -614,7 +607,7 @@ public class MediaFileDao extends AbstractDao { } } - private static class GenreMapper implements ParameterizedRowMapper { + private static class GenreMapper implements RowMapper { public Genre mapRow(ResultSet rs, int rowNum) throws SQLException { return new Genre(rs.getString(1), rs.getInt(2), rs.getInt(3)); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/MusicFolderDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/MusicFolderDao.java index ca997b45..49dcdc3e 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/MusicFolderDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/MusicFolderDao.java @@ -19,16 +19,15 @@ */ package org.libresonic.player.dao; +import org.libresonic.player.Logger; +import org.libresonic.player.domain.MusicFolder; +import org.springframework.jdbc.core.RowMapper; + import java.io.File; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; - -import org.libresonic.player.Logger; -import org.libresonic.player.domain.MusicFolder; - /** * Provides database services for music folders. * @@ -99,7 +98,7 @@ public class MusicFolderDao extends AbstractDao { } } - private static class MusicFolderRowMapper implements ParameterizedRowMapper { + private static class MusicFolderRowMapper implements RowMapper { public MusicFolder mapRow(ResultSet rs, int rowNum) throws SQLException { return new MusicFolder(rs.getInt(1), new File(rs.getString(2)), rs.getString(3), rs.getBoolean(4), rs.getTimestamp(5)); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/PlayQueueDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/PlayQueueDao.java index f56bd232..a098c43b 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/PlayQueueDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/PlayQueueDao.java @@ -23,7 +23,6 @@ import java.sql.SQLException; import java.util.List; import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.libresonic.player.domain.SavedPlayQueue; @@ -60,7 +59,7 @@ public class PlayQueueDao extends AbstractDao { } } - private static class PlayQueueMapper implements ParameterizedRowMapper { + private static class PlayQueueMapper implements RowMapper { public SavedPlayQueue mapRow(ResultSet rs, int rowNum) throws SQLException { return new SavedPlayQueue(rs.getInt(1), rs.getString(2), diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java index be855e61..4530fd35 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java @@ -19,22 +19,13 @@ */ package org.libresonic.player.dao; +import org.libresonic.player.Logger; +import org.libresonic.player.domain.*; +import org.springframework.jdbc.core.RowMapper; + import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Calendar; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; - -import org.libresonic.player.Logger; -import org.libresonic.player.domain.CoverArtScheme; -import org.libresonic.player.domain.Player; -import org.libresonic.player.domain.PlayerTechnology; -import org.libresonic.player.domain.PlayQueue; -import org.libresonic.player.domain.TranscodeScheme; +import java.util.*; /** * Provides player-related database services. @@ -95,7 +86,7 @@ public class PlayerDao extends AbstractDao { * @param player The player to create. */ public synchronized void createPlayer(Player player) { - int id = getJdbcTemplate().queryForInt("select max(id) from player") + 1; + int id = getJdbcTemplate().queryForObject("select max(id) from player", Integer.class) + 1; player.setId(String.valueOf(id)); String sql = "insert into player (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")"; update(sql, player.getId(), player.getName(), player.getType(), player.getUsername(), @@ -169,7 +160,7 @@ public class PlayerDao extends AbstractDao { player.setPlayQueue(playQueue); } - private class PlayerRowMapper implements ParameterizedRowMapper { + private class PlayerRowMapper implements RowMapper { public Player mapRow(ResultSet rs, int rowNum) throws SQLException { Player player = new Player(); int col = 1; diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/PlaylistDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/PlaylistDao.java index 996d84eb..e41e3781 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/PlaylistDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/PlaylistDao.java @@ -23,7 +23,6 @@ import org.libresonic.player.Logger; import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.Playlist; import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import java.sql.ResultSet; import java.sql.SQLException; @@ -125,7 +124,7 @@ public class PlaylistDao extends AbstractDao { new Date(), playlist.getImportedFrom(), playlist.getId()); } - private static class PlaylistMapper implements ParameterizedRowMapper { + private static class PlaylistMapper implements RowMapper { public Playlist mapRow(ResultSet rs, int rowNum) throws SQLException { return new Playlist( rs.getInt(1), diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/PodcastDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/PodcastDao.java index ca84b044..b61d870b 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/PodcastDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/PodcastDao.java @@ -24,7 +24,6 @@ import java.sql.SQLException; import java.util.List; import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.libresonic.player.domain.PodcastChannel; import org.libresonic.player.domain.PodcastEpisode; @@ -55,7 +54,7 @@ public class PodcastDao extends AbstractDao { update(sql, null, channel.getUrl(), channel.getTitle(), channel.getDescription(), channel.getImageUrl(), channel.getStatus().name(), channel.getErrorMessage()); - return getJdbcTemplate().queryForInt("select max(id) from podcast_channel"); + return getJdbcTemplate().queryForObject("select max(id) from podcast_channel", Integer.class); } /** @@ -182,7 +181,7 @@ public class PodcastDao extends AbstractDao { } } - private static class PodcastEpisodeRowMapper implements ParameterizedRowMapper { + private static class PodcastEpisodeRowMapper implements RowMapper { public PodcastEpisode mapRow(ResultSet rs, int rowNum) throws SQLException { return new PodcastEpisode(rs.getInt(1), rs.getInt(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getTimestamp(7), rs.getString(8), (Long) rs.getObject(9), diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/ShareDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/ShareDao.java index 15ca4fa3..702e4965 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/ShareDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/ShareDao.java @@ -26,7 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; +import org.springframework.jdbc.core.RowMapper; import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.domain.Share; @@ -53,7 +53,7 @@ public class ShareDao extends AbstractDao { update(sql, null, share.getName(), share.getDescription(), share.getUsername(), share.getCreated(), share.getExpires(), share.getLastVisited(), share.getVisitCount()); - int id = getJdbcTemplate().queryForInt("select max(id) from share"); + int id = getJdbcTemplate().queryForObject("select max(id) from share", Integer.class); share.setId(id); } @@ -129,14 +129,14 @@ public class ShareDao extends AbstractDao { update("delete from share where id=?", id); } - private static class ShareRowMapper implements ParameterizedRowMapper { + private static class ShareRowMapper implements RowMapper { public Share mapRow(ResultSet rs, int rowNum) throws SQLException { return new Share(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getTimestamp(5), rs.getTimestamp(6), rs.getTimestamp(7), rs.getInt(8)); } } - private static class ShareFileRowMapper implements ParameterizedRowMapper { + private static class ShareFileRowMapper implements RowMapper { public String mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getString(1); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java index bfd43b1f..5ca8a3e9 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java @@ -23,7 +23,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; +import org.springframework.jdbc.core.RowMapper; import org.libresonic.player.Logger; import org.libresonic.player.domain.Transcoding; @@ -82,7 +82,7 @@ public class TranscodingDao extends AbstractDao { * @param transcoding The transcoding to create. */ public synchronized void createTranscoding(Transcoding transcoding) { - int id = getJdbcTemplate().queryForInt("select max(id) + 1 from transcoding2"); + int id = getJdbcTemplate().queryForObject("select max(id) + 1 from transcoding2", Integer.class); transcoding.setId(id); String sql = "insert into transcoding2 (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")"; update(sql, transcoding.getId(), transcoding.getName(), transcoding.getSourceFormats(), @@ -115,7 +115,7 @@ public class TranscodingDao extends AbstractDao { transcoding.getStep3(), transcoding.isDefaultActive(), transcoding.getId()); } - private static class TranscodingRowMapper implements ParameterizedRowMapper { + private static class TranscodingRowMapper implements RowMapper { public Transcoding mapRow(ResultSet rs, int rowNum) throws SQLException { return new Transcoding(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getBoolean(8)); diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/UserDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/UserDao.java index 8af3216e..abd1ac2e 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/UserDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/UserDao.java @@ -19,20 +19,15 @@ */ package org.libresonic.player.dao; +import org.libresonic.player.Logger; +import org.libresonic.player.domain.*; +import org.libresonic.player.util.StringUtil; +import org.springframework.jdbc.core.RowMapper; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import org.springframework.jdbc.core.simple.ParameterizedRowMapper; - -import org.libresonic.player.Logger; -import org.libresonic.player.domain.AlbumListType; -import org.libresonic.player.domain.AvatarScheme; -import org.libresonic.player.domain.TranscodeScheme; -import org.libresonic.player.domain.User; -import org.libresonic.player.domain.UserSettings; -import org.libresonic.player.util.StringUtil; - /** * Provides user-related database services. * @@ -296,7 +291,7 @@ public class UserDao extends AbstractDao { } } - private class UserRowMapper implements ParameterizedRowMapper { + private class UserRowMapper implements RowMapper { public User mapRow(ResultSet rs, int rowNum) throws SQLException { User user = new User(rs.getString(1), decrypt(rs.getString(2)), rs.getString(3), rs.getBoolean(4), rs.getLong(5), rs.getLong(6), rs.getLong(7)); @@ -305,7 +300,7 @@ public class UserDao extends AbstractDao { } } - private static class UserSettingsRowMapper implements ParameterizedRowMapper { + private static class UserSettingsRowMapper implements RowMapper { public UserSettings mapRow(ResultSet rs, int rowNum) throws SQLException { int col = 1; UserSettings settings = new UserSettings(rs.getString(col++)); From 6f54dc05d590cf9ffb0fed393f0b03295f4b57ce Mon Sep 17 00:00:00 2001 From: Andrew DeMaria Date: Mon, 16 May 2016 22:32:48 -0600 Subject: [PATCH 03/27] Fixed issue with null Integer id return value Signed-off-by: Andrew DeMaria --- .../src/main/java/org/libresonic/player/dao/PlayerDao.java | 6 +++++- .../java/org/libresonic/player/dao/TranscodingDao.java | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java index 4530fd35..d470452d 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java @@ -86,7 +86,11 @@ public class PlayerDao extends AbstractDao { * @param player The player to create. */ public synchronized void createPlayer(Player player) { - int id = getJdbcTemplate().queryForObject("select max(id) from player", Integer.class) + 1; + Integer existingMax = getJdbcTemplate().queryForObject("select max(id) from player", Integer.class); + if(existingMax == null) { + existingMax = 0; + } + int id = existingMax + 1; player.setId(String.valueOf(id)); String sql = "insert into player (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")"; update(sql, player.getId(), player.getName(), player.getType(), player.getUsername(), diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java index 5ca8a3e9..d3d11720 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java @@ -82,8 +82,11 @@ public class TranscodingDao extends AbstractDao { * @param transcoding The transcoding to create. */ public synchronized void createTranscoding(Transcoding transcoding) { - int id = getJdbcTemplate().queryForObject("select max(id) + 1 from transcoding2", Integer.class); - transcoding.setId(id); + Integer existingMax = getJdbcTemplate().queryForObject("select max(id) from transcoding2", Integer.class); + if(existingMax == null) { + existingMax = 0; + } + transcoding.setId(existingMax + 1); String sql = "insert into transcoding2 (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")"; update(sql, transcoding.getId(), transcoding.getName(), transcoding.getSourceFormats(), transcoding.getTargetFormat(), transcoding.getStep1(), From 1e81ae70d42c6056a943e5ea39ae88ae59f145ec Mon Sep 17 00:00:00 2001 From: Andrew DeMaria Date: Tue, 31 May 2016 23:27:22 -0600 Subject: [PATCH 04/27] Added missing dependencies Signed-off-by: Andrew DeMaria --- libresonic-main/pom.xml | 20 ++++++++++++++++++++ pom.xml | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 449f002f..8eeb6e45 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -31,11 +31,31 @@ spring-webmvc + + org.springframework + spring-web + + org.springframework spring-jdbc + + org.springframework + spring-tx + + + + org.springframework + spring-context + + + + org.springframework + spring-beans + + org.acegisecurity acegi-security diff --git a/pom.xml b/pom.xml index b8e6b250..5a18cf41 100644 --- a/pom.xml +++ b/pom.xml @@ -99,11 +99,31 @@ spring-webmvc ${spring.version} + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + org.springframework spring-jdbc ${spring.version} + + org.springframework + spring-tx + ${spring.version} + + + org.springframework + spring-beans + ${spring.version} + From 04f0167f66a625584e58064f2674bf5beddd801c Mon Sep 17 00:00:00 2001 From: Andrew DeMaria Date: Wed, 19 Oct 2016 20:25:02 -0600 Subject: [PATCH 05/27] Migrate from acegisecurity to spring security Signed-off-by: Andrew DeMaria --- libresonic-main/pom.xml | 33 +- .../player/controller/MultiController.java | 42 ++- .../ldap/LibresonicLdapBindAuthenticator.java | 132 -------- ...tailsServiceBasedAuthoritiesPopulator.java | 51 --- .../LibresonicApplicationEventListener.java | 6 +- .../RESTRequestParameterProcessingFilter.java | 27 +- .../player/service/SecurityService.java | 40 ++- .../WEB-INF/applicationContext-security.xml | 305 ++++-------------- .../src/main/webapp/WEB-INF/jsp/login.jsp | 6 +- .../src/main/webapp/WEB-INF/jsp/top.jsp | 2 +- .../src/main/webapp/WEB-INF/web.xml | 10 +- pom.xml | 17 + 12 files changed, 147 insertions(+), 524 deletions(-) delete mode 100644 libresonic-main/src/main/java/org/libresonic/player/ldap/LibresonicLdapBindAuthenticator.java delete mode 100644 libresonic-main/src/main/java/org/libresonic/player/ldap/UserDetailsServiceBasedAuthoritiesPopulator.java diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 8eeb6e45..70abbc5c 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -57,27 +57,18 @@ - org.acegisecurity - acegi-security - 1.0.5 - - - org.springframework - spring-core - - - org.springframework - spring-remoting - - - org.springframework - spring-jdbc - - - org.springframework - spring-support - - + org.springframework.security + spring-security-web + + + + org.springframework.security + spring-security-ldap + + + + org.springframework.security + spring-security-config diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java index 8564e46e..00e318aa 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java @@ -19,30 +19,19 @@ */ package org.libresonic.player.controller; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Date; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - 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.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 org.libresonic.player.Logger; import org.libresonic.player.domain.Playlist; import org.libresonic.player.domain.User; @@ -51,9 +40,16 @@ 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 net.tanesha.recaptcha.ReCaptcha; -import net.tanesha.recaptcha.ReCaptchaFactory; -import net.tanesha.recaptcha.ReCaptchaResponse; +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.HashMap; +import java.util.Map; +import java.util.Properties; /** * Multi-controller used for simple pages. @@ -76,8 +72,10 @@ public class MultiController extends MultiActionController { if (username != null && password != null) { username = StringUtil.urlEncode(username); password = StringUtil.urlEncode(password); - return new ModelAndView(new RedirectView("j_acegi_security_check?j_username=" + username + - "&j_password=" + password + "&_acegi_security_remember_me=checked")); + return new ModelAndView(new RedirectView("/j_spring_security_check?"+ + UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY+"=" + username + + "&"+UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY+"=" + password + )); } Map map = new HashMap(); @@ -296,4 +294,4 @@ public class MultiController extends MultiActionController { public void setPlaylistService(PlaylistService playlistService) { this.playlistService = playlistService; } -} \ No newline at end of file +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/ldap/LibresonicLdapBindAuthenticator.java b/libresonic-main/src/main/java/org/libresonic/player/ldap/LibresonicLdapBindAuthenticator.java deleted file mode 100644 index 3591f944..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/ldap/LibresonicLdapBindAuthenticator.java +++ /dev/null @@ -1,132 +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.ldap; - -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.acegisecurity.BadCredentialsException; -import org.acegisecurity.ldap.DefaultInitialDirContextFactory; -import org.acegisecurity.ldap.search.FilterBasedLdapUserSearch; -import org.acegisecurity.providers.ldap.LdapAuthenticator; -import org.acegisecurity.providers.ldap.authenticator.BindAuthenticator; -import org.acegisecurity.userdetails.ldap.LdapUserDetails; -import org.apache.commons.lang.StringUtils; - -import java.util.HashMap; -import java.util.Map; - -/** - * LDAP authenticator which uses a delegate {@link BindAuthenticator}, and which - * supports dynamically changing LDAP provider URL and search filter. - * - * @author Sindre Mehus - */ -public class LibresonicLdapBindAuthenticator implements LdapAuthenticator { - - private static final Logger LOG = Logger.getLogger(LibresonicLdapBindAuthenticator.class); - - private SecurityService securityService; - private SettingsService settingsService; - - private long authenticatorTimestamp; - private BindAuthenticator delegateAuthenticator; - - public LdapUserDetails authenticate(String username, String password) { - - // LDAP authentication must be enabled on the system. - if (!settingsService.isLdapEnabled()) { - throw new BadCredentialsException("LDAP authentication disabled."); - } - - // User must be defined in Libresonic, unless auto-shadowing is enabled. - User user = securityService.getUserByName(username); - if (user == null && !settingsService.isLdapAutoShadowing()) { - throw new BadCredentialsException("User does not exist."); - } - - // LDAP authentication must be enabled for the given user. - if (user != null && !user.isLdapAuthenticated()) { - throw new BadCredentialsException("LDAP authentication disabled for user."); - } - - try { - createDelegate(); - LdapUserDetails details = delegateAuthenticator.authenticate(username, password); - if (details != null) { - LOG.info("User '" + username + "' successfully authenticated in LDAP. DN: " + details.getDn()); - - if (user == null) { - User newUser = new User(username, "", null, true, 0L, 0L, 0L); - newUser.setStreamRole(true); - newUser.setSettingsRole(true); - securityService.createUser(newUser); - LOG.info("Created local user '" + username + "' for DN " + details.getDn()); - } - } - - return details; - } catch (RuntimeException x) { - LOG.info("Failed to authenticate user '" + username + "' in LDAP.", x); - throw x; - } - } - - /** - * Creates the delegate {@link BindAuthenticator}. - */ - private synchronized void createDelegate() { - - // Only create it if necessary. - if (delegateAuthenticator == null || authenticatorTimestamp < settingsService.getSettingsChanged()) { - - DefaultInitialDirContextFactory contextFactory = new DefaultInitialDirContextFactory(settingsService.getLdapUrl()); - - String managerDn = settingsService.getLdapManagerDn(); - String managerPassword = settingsService.getLdapManagerPassword(); - if (StringUtils.isNotEmpty(managerDn) && StringUtils.isNotEmpty(managerPassword)) { - contextFactory.setManagerDn(managerDn); - contextFactory.setManagerPassword(managerPassword); - } - - Map extraEnvVars = new HashMap(); - extraEnvVars.put("java.naming.referral", "follow"); - contextFactory.setExtraEnvVars(extraEnvVars); - - FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch("", settingsService.getLdapSearchFilter(), contextFactory); - userSearch.setSearchSubtree(true); - userSearch.setDerefLinkFlag(true); - - delegateAuthenticator = new BindAuthenticator(contextFactory); - delegateAuthenticator.setUserSearch(userSearch); - - authenticatorTimestamp = settingsService.getSettingsChanged(); - } - } - - 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/ldap/UserDetailsServiceBasedAuthoritiesPopulator.java b/libresonic-main/src/main/java/org/libresonic/player/ldap/UserDetailsServiceBasedAuthoritiesPopulator.java deleted file mode 100644 index 81f4e3ef..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/ldap/UserDetailsServiceBasedAuthoritiesPopulator.java +++ /dev/null @@ -1,51 +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.ldap; - -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.ldap.LdapDataAccessException; -import org.acegisecurity.providers.ldap.LdapAuthoritiesPopulator; -import org.acegisecurity.userdetails.UserDetailsService; -import org.acegisecurity.userdetails.UserDetails; -import org.acegisecurity.userdetails.ldap.LdapUserDetails; - -/** - * An {@link LdapAuthoritiesPopulator} that retrieves the roles from the - * database using the {@link UserDetailsService} instead of retrieving the roles - * from LDAP. An instance of this class can be configured for the - * {@link org.acegisecurity.providers.ldap.LdapAuthenticationProvider} when - * authentication should be done using LDAP and authorization using the - * information stored in the database. - * - * @author Thomas M. Hofmann - */ -public class UserDetailsServiceBasedAuthoritiesPopulator implements LdapAuthoritiesPopulator { - - private UserDetailsService userDetailsService; - - public GrantedAuthority[] getGrantedAuthorities(LdapUserDetails userDetails) throws LdapDataAccessException { - UserDetails details = userDetailsService.loadUserByUsername(userDetails.getUsername()); - return details.getAuthorities(); - } - - public void setUserDetailsService(UserDetailsService userDetailsService) { - this.userDetailsService = userDetailsService; - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/security/LibresonicApplicationEventListener.java b/libresonic-main/src/main/java/org/libresonic/player/security/LibresonicApplicationEventListener.java index 48469d42..dfeaee5f 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/security/LibresonicApplicationEventListener.java +++ b/libresonic-main/src/main/java/org/libresonic/player/security/LibresonicApplicationEventListener.java @@ -19,11 +19,11 @@ package org.libresonic.player.security; -import org.acegisecurity.event.authentication.AbstractAuthenticationFailureEvent; -import org.acegisecurity.providers.AbstractAuthenticationToken; -import org.acegisecurity.ui.WebAuthenticationDetails; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; +import org.springframework.security.authentication.AbstractAuthenticationToken; +import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent; +import org.springframework.security.web.authentication.WebAuthenticationDetails; /** * @author Sindre Mehus 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 9081c372..efa374b6 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 @@ -19,25 +19,8 @@ */ package org.libresonic.player.security; -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.acegisecurity.Authentication; -import org.acegisecurity.AuthenticationException; -import org.acegisecurity.context.SecurityContextHolder; -import org.acegisecurity.providers.ProviderManager; -import org.acegisecurity.providers.UsernamePasswordAuthenticationToken; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; - import org.libresonic.player.Logger; import org.libresonic.player.controller.JAXBWriter; import org.libresonic.player.controller.RESTController; @@ -47,6 +30,16 @@ 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.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.context.SecurityContextHolder; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * Performs authentication based on credentials being present in the HTTP request parameters. Also checks diff --git a/libresonic-main/src/main/java/org/libresonic/player/service/SecurityService.java b/libresonic-main/src/main/java/org/libresonic/player/service/SecurityService.java index 773e215e..2b79c018 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/service/SecurityService.java +++ b/libresonic-main/src/main/java/org/libresonic/player/service/SecurityService.java @@ -19,20 +19,6 @@ */ package org.libresonic.player.service; -import java.io.File; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - -import org.acegisecurity.GrantedAuthority; -import org.acegisecurity.GrantedAuthorityImpl; -import org.acegisecurity.providers.dao.DaoAuthenticationProvider; -import org.acegisecurity.userdetails.UserDetails; -import org.acegisecurity.userdetails.UserDetailsService; -import org.acegisecurity.userdetails.UsernameNotFoundException; -import org.acegisecurity.wrapper.SecurityContextHolderAwareRequestWrapper; -import org.springframework.dao.DataAccessException; - import net.sf.ehcache.Ehcache; import org.libresonic.player.Logger; import org.libresonic.player.dao.UserDao; @@ -40,6 +26,18 @@ import org.libresonic.player.domain.MediaFile; import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.domain.User; import org.libresonic.player.util.FileUtil; +import org.springframework.dao.DataAccessException; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper; + +import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.util.ArrayList; +import java.util.List; /** * Provides security-related services for authentication and authorization. @@ -57,7 +55,7 @@ public class SecurityService implements UserDetailsService { /** * Locates the user based on the username. * - * @param username The username presented to the {@link DaoAuthenticationProvider} + * @param username The username * @return A fully populated user record (never null) * @throws UsernameNotFoundException if the user could not be found or the user has no GrantedAuthority. * @throws DataAccessException If user could not be found for a repository-specific reason. @@ -69,16 +67,14 @@ public class SecurityService implements UserDetailsService { } String[] roles = userDao.getRolesForUser(username); - GrantedAuthority[] authorities = new GrantedAuthority[roles.length]; + List authorities = new ArrayList<>(); + authorities.add(new SimpleGrantedAuthority("IS_AUTHENTICATED_ANONYMOUSLY")); + authorities.add(new SimpleGrantedAuthority("ROLE_USER")); for (int i = 0; i < roles.length; i++) { - authorities[i] = new GrantedAuthorityImpl("ROLE_" + roles[i].toUpperCase()); + authorities.add(new SimpleGrantedAuthority("ROLE_" + roles[i].toUpperCase())); } - // If user is LDAP authenticated, disable user. The proper authentication should in that case - // be done by LibresonicLdapBindAuthenticator. - boolean enabled = !user.isLdapAuthenticated(); - - return new org.acegisecurity.userdetails.User(username, user.getPassword(), enabled, true, true, true, authorities); + return new org.springframework.security.core.userdetails.User(username, user.getPassword(), authorities); } /** diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml index b2af9b4b..4a9850e8 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml @@ -1,246 +1,65 @@ - - - - - - - - - - - - PATTERN_TYPE_APACHE_ANT - /wap**=httpSessionContextIntegrationFilter,logoutFilter,basicProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,basicExceptionTranslationFilter,filterInvocationInterceptor - /podcastChannel**=httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,basicProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor - /podcast**=httpSessionContextIntegrationFilter,logoutFilter,basicProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,basicExceptionTranslationFilter,filterInvocationInterceptor - /rest/**=httpSessionContextIntegrationFilter,logoutFilter,basicProcessingFilter,restRequestParameterProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,basicExceptionTranslationFilter,filterInvocationInterceptor - /**=httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,basicProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PATTERN_TYPE_APACHE_ANT - - /login.view=IS_AUTHENTICATED_ANONYMOUSLY - /recover.view=IS_AUTHENTICATED_ANONYMOUSLY - /accessDenied.view=IS_AUTHENTICATED_ANONYMOUSLY - /coverArt.view=IS_AUTHENTICATED_ANONYMOUSLY - /hls/**=IS_AUTHENTICATED_ANONYMOUSLY - /stream/**=IS_AUTHENTICATED_ANONYMOUSLY - /ws/**=IS_AUTHENTICATED_ANONYMOUSLY - /share/**=IS_AUTHENTICATED_ANONYMOUSLY - /style/**=IS_AUTHENTICATED_ANONYMOUSLY - /icons/**=IS_AUTHENTICATED_ANONYMOUSLY - /flash/**=IS_AUTHENTICATED_ANONYMOUSLY - /script/**=IS_AUTHENTICATED_ANONYMOUSLY - /sonos/**=IS_AUTHENTICATED_ANONYMOUSLY - /crossdomain.xml=IS_AUTHENTICATED_ANONYMOUSLY - - /personalSettings.view=ROLE_SETTINGS - /passwordSettings.view=ROLE_SETTINGS - /playerSettings.view=ROLE_SETTINGS - /shareSettings.view=ROLE_SETTINGS - - /generalSettings.view=ROLE_ADMIN - /advancedSettings.view=ROLE_ADMIN - /userSettings.view=ROLE_ADMIN - /musicFolderSettings.view=ROLE_ADMIN - /networkSettings.view=ROLE_ADMIN - /dlnaSettings.view=ROLE_ADMIN - /sonosSettings.view=ROLE_ADMIN - /transcodingSettings.view=ROLE_ADMIN - /internetRadioSettings.view=ROLE_ADMIN - /podcastSettings.view=ROLE_ADMIN - /db.view=ROLE_ADMIN - - /deletePlaylist.view=ROLE_PLAYLIST - /savePlaylist.view=ROLE_PLAYLIST - - /download.view=ROLE_DOWNLOAD - - /upload.view=ROLE_UPLOAD - - /createShare.view=ROLE_SHARE - - /changeCoverArt.view=ROLE_COVERART - /editTags.view=ROLE_COVERART - - /setMusicFileInfo.view=ROLE_COMMENT - - /podcastReceiverAdmin.view=ROLE_PODCAST - - /**=IS_AUTHENTICATED_REMEMBERED - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.libresonic.player.ajax.TagService.setTags=ROLE_COVERART - org.libresonic.player.ajax.TransferService.getUploadInfo=ROLE_UPLOAD - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/security + http://www.springframework.org/schema/security/spring-security-3.2.xsd"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 acc6a193..6209b414 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/login.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/login.jsp @@ -12,7 +12,7 @@ -
" method="POST"> +" method="POST">
@@ -35,10 +35,6 @@ " tabindex="4"> - - - - diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/top.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/top.jsp index a8e1cbe3..7eeb095d 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/top.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/top.jsp @@ -138,7 +138,7 @@ diff --git a/libresonic-main/src/main/webapp/WEB-INF/web.xml b/libresonic-main/src/main/webapp/WEB-INF/web.xml index 661fffe8..5bd36336 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/web.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/web.xml @@ -208,16 +208,12 @@ - AcegiFilter - org.acegisecurity.util.FilterToBeanProxy - - targetClass - org.acegisecurity.util.FilterChainProxy - + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy - AcegiFilter + springSecurityFilterChain /* diff --git a/pom.xml b/pom.xml index 5a18cf41..4391875c 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,7 @@ iso-8859-1 2.4.2 3.2.17.RELEASE + 3.2.9.RELEASE @@ -109,6 +110,22 @@ spring-web ${spring.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 From 92368cca8fb78cb066692bdf3e87a0186a15650a Mon Sep 17 00:00:00 2001 From: Andrew DeMaria Date: Thu, 20 Oct 2016 22:43:54 -0600 Subject: [PATCH 06/27] Fixed display of login error Signed-off-by: Andrew DeMaria --- .../src/main/webapp/WEB-INF/applicationContext-security.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml index 4a9850e8..c9dc232d 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml @@ -56,7 +56,7 @@ - + From a03aa2805d050ef3cdc9b315adda87148daa7454 Mon Sep 17 00:00:00 2001 From: remi Date: Mon, 21 Nov 2016 23:32:43 +0100 Subject: [PATCH 07/27] New LoginController in place of the login method in MultiController. Slight introduction to Java annotation based configuration (note that has been added to libresonic-servlet.xml). --- .../player/controller/LoginController.java | 72 +++++++++++++++++++ .../player/controller/MultiController.java | 28 -------- .../webapp/WEB-INF/libresonic-servlet.xml | 16 ++++- 3 files changed, 87 insertions(+), 29 deletions(-) create mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java 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 new file mode 100644 index 00000000..41a9e3ea --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/LoginController.java @@ -0,0 +1,72 @@ +package org.libresonic.player.controller; + +import org.libresonic.player.Logger; +import org.libresonic.player.domain.User; +import org.libresonic.player.service.PlaylistService; +import org.libresonic.player.service.SecurityService; +import org.libresonic.player.service.SettingsService; +import org.libresonic.player.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.view.RedirectView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; + +/** + * Spring MVC Controller that serves the login page. + */ +@Controller +@RequestMapping("/login") +public class LoginController { + + + private static final Logger LOG = Logger.getLogger(LoginController.class); + + private final SecurityService securityService; + private final SettingsService settingsService; + private final PlaylistService playlistService; + + @Autowired + public LoginController(SecurityService securityService, SettingsService settingsService, PlaylistService playlistService) { + this.securityService = securityService; + this.settingsService = settingsService; + this.playlistService = playlistService; + } + + @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }) + public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception { + + // Auto-login if "user" and "password" parameters are given. + String username = request.getParameter("user"); + String password = request.getParameter("password"); + if (username != null && password != null) { + username = StringUtil.urlEncode(username); + password = StringUtil.urlEncode(password); + return new ModelAndView(new RedirectView("/j_spring_security_check?"+ + UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY+"=" + username + + "&"+UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY+"=" + password + )); + } + + Map map = new HashMap(); + map.put("logout", request.getParameter("logout") != null); + map.put("error", request.getParameter("error") != null); + map.put("brand", settingsService.getBrand()); + map.put("loginMessage", settingsService.getLoginMessage()); + + User admin = securityService.getUserByName(User.USERNAME_ADMIN); + if (User.USERNAME_ADMIN.equals(admin.getPassword())) { + map.put("insecure", true); + } + + return new ModelAndView("login", "model", map); + } + +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java index e37b736e..fcf98d9b 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/MultiController.java @@ -64,34 +64,6 @@ public class MultiController extends MultiActionController { private SettingsService settingsService; private PlaylistService playlistService; - public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception { - - // Auto-login if "user" and "password" parameters are given. - String username = request.getParameter("user"); - String password = request.getParameter("password"); - if (username != null && password != null) { - username = StringUtil.urlEncode(username); - password = StringUtil.urlEncode(password); - return new ModelAndView(new RedirectView("/j_spring_security_check?"+ - UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY+"=" + username + - "&"+UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY+"=" + password - )); - } - - Map map = new HashMap(); - map.put("logout", request.getParameter("logout") != null); - map.put("error", request.getParameter("error") != null); - map.put("brand", settingsService.getBrand()); - map.put("loginMessage", settingsService.getLoginMessage()); - - User admin = securityService.getUserByName(User.USERNAME_ADMIN); - if (User.USERNAME_ADMIN.equals(admin.getPassword())) { - map.put("insecure", true); - } - - return new ModelAndView("login", "model", map); - } - public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception { Map map = new HashMap(); diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index 52b0f556..5933acd7 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -2,7 +2,18 @@ + xmlns:context="http://www.springframework.org/schema/context" + xmlns:mvc="http://www.springframework.org/schema/mvc" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/mvc + http://www.springframework.org/schema/mvc/spring-mvc.xsd"> + + + @@ -434,7 +445,10 @@ topController randomPlayQueueController changeCoverArtController + multiController multiController multiController From 520008bb609abfbde14ce869314b0ed519ec9687 Mon Sep 17 00:00:00 2001 From: remi Date: Tue, 22 Nov 2016 22:09:16 +0100 Subject: [PATCH 08/27] No need for a constructor in the LoginController. Just need to @Autowire each property. --- .../player/controller/LoginController.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) 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 41a9e3ea..dfdb5f1d 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 @@ -29,16 +29,10 @@ public class LoginController { private static final Logger LOG = Logger.getLogger(LoginController.class); - private final SecurityService securityService; - private final SettingsService settingsService; - private final PlaylistService playlistService; - @Autowired - public LoginController(SecurityService securityService, SettingsService settingsService, PlaylistService playlistService) { - this.securityService = securityService; - this.settingsService = settingsService; - this.playlistService = playlistService; - } + private final SecurityService securityService = null; + @Autowired + private final SettingsService settingsService = null; @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }) public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception { From 02544d840696ad4e034b37448c918e613c10f366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Mon, 28 Nov 2016 20:52:03 +0100 Subject: [PATCH 09/27] LoginController : no need to declare members final. --- .../org/libresonic/player/controller/LoginController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 dfdb5f1d..1c74da4d 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 @@ -30,9 +30,9 @@ public class LoginController { private static final Logger LOG = Logger.getLogger(LoginController.class); @Autowired - private final SecurityService securityService = null; + private SecurityService securityService; @Autowired - private final SettingsService settingsService = null; + private SettingsService settingsService; @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }) public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception { From 3354f6623a1e414343013a7ba5007b58da9884cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Mon, 28 Nov 2016 21:22:20 +0100 Subject: [PATCH 10/27] Change version to 6.2.spring4-SNAPSHOT. --- libresonic-assembly/pom.xml | 2 +- libresonic-booter/pom.xml | 2 +- libresonic-installer-debian/pom.xml | 2 +- libresonic-installer-mac/pom.xml | 2 +- libresonic-installer-rpm/pom.xml | 2 +- libresonic-installer-windows/pom.xml | 2 +- libresonic-main/pom.xml | 2 +- libresonic-rest-api/pom.xml | 2 +- libresonic-sonos-api/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libresonic-assembly/pom.xml b/libresonic-assembly/pom.xml index 7f2b49bc..97ba9468 100644 --- a/libresonic-assembly/pom.xml +++ b/libresonic-assembly/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.1.beta2 + 6.2.spring4-SNAPSHOT diff --git a/libresonic-booter/pom.xml b/libresonic-booter/pom.xml index f4a68915..8c19afde 100644 --- a/libresonic-booter/pom.xml +++ b/libresonic-booter/pom.xml @@ -8,7 +8,7 @@ org.libresonic.player libresonic - 6.1.beta2 + 6.2.spring4-SNAPSHOT diff --git a/libresonic-installer-debian/pom.xml b/libresonic-installer-debian/pom.xml index ac53d340..915e2ca5 100644 --- a/libresonic-installer-debian/pom.xml +++ b/libresonic-installer-debian/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.1.beta2 + 6.2.spring4-SNAPSHOT diff --git a/libresonic-installer-mac/pom.xml b/libresonic-installer-mac/pom.xml index 432d5085..7095aa86 100644 --- a/libresonic-installer-mac/pom.xml +++ b/libresonic-installer-mac/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.1.beta2 + 6.2.spring4-SNAPSHOT diff --git a/libresonic-installer-rpm/pom.xml b/libresonic-installer-rpm/pom.xml index 74e86211..ef68ab1d 100644 --- a/libresonic-installer-rpm/pom.xml +++ b/libresonic-installer-rpm/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.1.beta2 + 6.2.spring4-SNAPSHOT diff --git a/libresonic-installer-windows/pom.xml b/libresonic-installer-windows/pom.xml index e9567211..a49724f1 100644 --- a/libresonic-installer-windows/pom.xml +++ b/libresonic-installer-windows/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.1.beta2 + 6.2.spring4-SNAPSHOT diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 3e40f989..6583e36d 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.1.beta2 + 6.2.spring4-SNAPSHOT diff --git a/libresonic-rest-api/pom.xml b/libresonic-rest-api/pom.xml index dcb9249c..420ba6c7 100644 --- a/libresonic-rest-api/pom.xml +++ b/libresonic-rest-api/pom.xml @@ -8,7 +8,7 @@ org.libresonic.player libresonic - 6.1.beta2 + 6.2.spring4-SNAPSHOT diff --git a/libresonic-sonos-api/pom.xml b/libresonic-sonos-api/pom.xml index ad46cb27..61daab0a 100644 --- a/libresonic-sonos-api/pom.xml +++ b/libresonic-sonos-api/pom.xml @@ -8,7 +8,7 @@ org.libresonic.player libresonic - 6.1.beta2 + 6.2.spring4-SNAPSHOT diff --git a/pom.xml b/pom.xml index c96e0227..31b9a1da 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.libresonic.player libresonic - 6.1.beta2 + 6.2.spring4-SNAPSHOT Libresonic pom From f6541632bb4b216d5b23c71195a812f8fb8c3539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Tue, 29 Nov 2016 23:03:07 +0100 Subject: [PATCH 11/27] Add temporary test jetty server (to be removed later). --- libresonic-main/pom.xml | 28 +++++++++++++++++++ .../org/libresonic/player/TestServer.java | 20 +++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 libresonic-main/src/main/java/org/libresonic/player/TestServer.java diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 6583e36d..95dabbaf 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -18,6 +18,34 @@ + + + org.mortbay.jetty + jetty + 6.1.5 + + + + org.mortbay.jetty + jetty-embedded + 6.1.5 + + + javax.servlet.jsp + jsp-api + + + + + + org.mortbay.jetty + jsp-2.0 + 6.1.5 + pom + + + + org.libresonic.player libresonic-rest-api diff --git a/libresonic-main/src/main/java/org/libresonic/player/TestServer.java b/libresonic-main/src/main/java/org/libresonic/player/TestServer.java new file mode 100644 index 00000000..eab79fb8 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/TestServer.java @@ -0,0 +1,20 @@ +package org.libresonic.player; + +import org.mortbay.jetty.Server; +import org.mortbay.jetty.webapp.WebAppContext; + +public class TestServer { + + public static void main(String[] args) throws Exception { + Server server = new Server(8080); + WebAppContext webapp = new WebAppContext(); + webapp.setContextPath("/libresonic"); + String baseDir = TestServer.class.getResource("/" + TestServer.class.getName().replaceAll("\\.", "/") + ".class").getFile(); + baseDir = baseDir.substring(0,baseDir.indexOf("/target")); + webapp.setWar(baseDir + "/src/main/webapp"); + server.setHandler(webapp); + server.setAttribute("reload", "automatic"); + server.start(); + server.join(); + } +} \ No newline at end of file From d422fc4086e6035add14cd896998010fd0e214b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Wed, 30 Nov 2016 00:18:50 +0100 Subject: [PATCH 12/27] Begin of migration of deprecated controllers style. --- .../AdvancedSettingsController.java | 37 +++++++++++-------- .../controller/PodcastSettingsController.java | 32 ++++++++++------ .../webapp/WEB-INF/libresonic-servlet.xml | 15 -------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/AdvancedSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/AdvancedSettingsController.java index 3622bedc..6cbc2392 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/AdvancedSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/AdvancedSettingsController.java @@ -19,24 +19,33 @@ */ package org.libresonic.player.controller; +import org.apache.commons.lang.StringUtils; import org.libresonic.player.command.AdvancedSettingsCommand; import org.libresonic.player.service.SettingsService; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.apache.commons.lang.StringUtils; - -import javax.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; /** * Controller for the page used to administrate advanced settings. * * @author Sindre Mehus */ -public class AdvancedSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/advancedSettings") +public class AdvancedSettingsController { + @Autowired private SettingsService settingsService; - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { + // TODO replace with @GetMapping in Spring 4 + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(Model model) throws Exception { AdvancedSettingsCommand command = new AdvancedSettingsCommand(); command.setDownloadLimit(String.valueOf(settingsService.getDownloadBitrateLimit())); command.setUploadLimit(String.valueOf(settingsService.getUploadBitrateLimit())); @@ -53,12 +62,12 @@ public class AdvancedSettingsController extends SimpleFormController { command.setSmtpUser(settingsService.getSmtpUser()); command.setSmtpFrom(settingsService.getSmtpFrom()); - return command; + model.addAttribute("command", command); + return "advancedSettings"; } - @Override - protected void doSubmitAction(Object comm) throws Exception { - AdvancedSettingsCommand command = (AdvancedSettingsCommand) comm; + @RequestMapping(method = RequestMethod.POST) + protected String doSubmitAction(@ModelAttribute AdvancedSettingsCommand command,Model model) throws Exception { command.setToast(true); command.setReloadNeeded(false); @@ -90,10 +99,8 @@ public class AdvancedSettingsController extends SimpleFormController { settingsService.setSmtpPassword(command.getSmtpPassword()); } - settingsService.save(); + model.addAttribute("command", command); + return "advancedSettings"; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java index 3608b2f2..4a1133de 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java @@ -19,6 +19,12 @@ */ package org.libresonic.player.controller; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.mvc.SimpleFormController; import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.PodcastService; @@ -31,23 +37,30 @@ import javax.servlet.http.HttpServletRequest; * * @author Sindre Mehus */ -public class PodcastSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/podcastSettings") +public class PodcastSettingsController { + @Autowired private SettingsService settingsService; + @Autowired private PodcastService podcastService; - protected Object formBackingObject(HttpServletRequest request) throws Exception { + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(Model model) throws Exception { PodcastSettingsCommand command = new PodcastSettingsCommand(); command.setInterval(String.valueOf(settingsService.getPodcastUpdateInterval())); command.setEpisodeRetentionCount(String.valueOf(settingsService.getPodcastEpisodeRetentionCount())); command.setEpisodeDownloadCount(String.valueOf(settingsService.getPodcastEpisodeDownloadCount())); command.setFolder(settingsService.getPodcastFolder()); - return command; + + model.addAttribute("command",command); + return "podcastSettings"; } - protected void doSubmitAction(Object comm) throws Exception { - PodcastSettingsCommand command = (PodcastSettingsCommand) comm; + @RequestMapping(method = RequestMethod.POST) + protected String doSubmitAction(@ModelAttribute PodcastSettingsCommand command, Model model) throws Exception { command.setToast(true); settingsService.setPodcastUpdateInterval(Integer.parseInt(command.getInterval())); @@ -57,13 +70,8 @@ public class PodcastSettingsController extends SimpleFormController { settingsService.save(); podcastService.schedule(); + model.addAttribute("command",command); + return "podcastSettings"; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setPodcastService(PodcastService podcastService) { - this.podcastService = podcastService; - } } diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index 3a1ca182..d84853e8 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -225,25 +225,12 @@ - - - - - - - - - - - - - @@ -467,9 +454,7 @@ networkSettingsController transcodingSettingsController internetRadioSettingsController - podcastSettingsController generalSettingsController - advancedSettingsController personalSettingsController avatarUploadController userSettingsController From 9bdbb5ab4f8e18c61f3222e6fde44bf7603e87ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Wed, 30 Nov 2016 21:10:18 +0100 Subject: [PATCH 13/27] Migration of NetworkSettingsController + unit test. --- .../controller/NetworkSettingsController.java | 45 ++++++++++++------- .../webapp/WEB-INF/libresonic-servlet.xml | 8 ---- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java index 08824ccf..02f622bd 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java @@ -24,6 +24,13 @@ import java.util.Random; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; +import org.apache.tools.ant.taskdefs.ManifestTask; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.mvc.SimpleFormController; import org.libresonic.player.command.NetworkSettingsCommand; @@ -36,12 +43,17 @@ import org.libresonic.player.service.SettingsService; * * @author Sindre Mehus */ -public class NetworkSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/networkSettings") +public class NetworkSettingsController { + @Autowired private SettingsService settingsService; + @Autowired private NetworkService networkService; - protected Object formBackingObject(HttpServletRequest request) throws Exception { + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(Model model) throws Exception { NetworkSettingsCommand command = new NetworkSettingsCommand(); command.setPortForwardingEnabled(settingsService.isPortForwardingEnabled()); command.setUrlRedirectionEnabled(settingsService.isUrlRedirectionEnabled()); @@ -51,18 +63,26 @@ public class NetworkSettingsController extends SimpleFormController { command.setPort(settingsService.getPort()); command.setLicenseInfo(settingsService.getLicenseInfo()); - return command; + model.addAttribute("command",command); + return "networkSettings"; } - protected void doSubmitAction(Object cmd) throws Exception { - NetworkSettingsCommand command = (NetworkSettingsCommand) cmd; + @RequestMapping(method = RequestMethod.POST) + protected String doSubmitAction(@ModelAttribute NetworkSettingsCommand command, Model model) throws Exception { command.setToast(true); settingsService.setPortForwardingEnabled(command.isPortForwardingEnabled()); settingsService.setUrlRedirectionEnabled(command.isUrlRedirectionEnabled()); - settingsService.setUrlRedirectType(UrlRedirectType.valueOf(command.getUrlRedirectType())); - settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom())); - settingsService.setUrlRedirectCustomUrl(StringUtils.trimToEmpty(command.getUrlRedirectCustomUrl())); + String urlRedirectType = command.getUrlRedirectType(); + if (urlRedirectType == null) { + command.setUrlRedirectType("NORMAL"); + command.setUrlRedirectFrom("yourname"); + command.setUrlRedirectCustomUrl("http://"); + } else { + settingsService.setUrlRedirectType(UrlRedirectType.valueOf(command.getUrlRedirectType())); + settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom())); + settingsService.setUrlRedirectCustomUrl(StringUtils.trimToEmpty(command.getUrlRedirectCustomUrl())); + } if (settingsService.getServerId() == null) { Random rand = new Random(System.currentTimeMillis()); @@ -72,13 +92,8 @@ public class NetworkSettingsController extends SimpleFormController { settingsService.save(); networkService.initPortForwarding(0); networkService.initUrlRedirection(true); + model.addAttribute("command",command); + return "networkSettings"; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setNetworkService(NetworkService networkService) { - this.networkService = networkService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index d84853e8..431c2c54 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -208,13 +208,6 @@ - - - - - - - @@ -451,7 +444,6 @@ sonosSettingsController shareSettingsController musicFolderSettingsController - networkSettingsController transcodingSettingsController internetRadioSettingsController generalSettingsController From f5a380eadad8c859ab724f2ff053bd46cf5a137f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Wed, 30 Nov 2016 22:05:40 +0100 Subject: [PATCH 14/27] Migration of MusicFolderSettingsController + unit test. --- .../MusicFolderSettingsController.java | 78 ++++++++++--------- .../WEB-INF/jsp/musicFolderSettings.jsp | 1 + .../webapp/WEB-INF/libresonic-servlet.xml | 11 --- 3 files changed, 42 insertions(+), 48 deletions(-) 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 eaef1b65..6d19d917 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 @@ -20,6 +20,7 @@ package org.libresonic.player.controller; import org.libresonic.player.command.MusicFolderSettingsCommand; +import org.libresonic.player.command.NetworkSettingsCommand; import org.libresonic.player.dao.AlbumDao; import org.libresonic.player.dao.ArtistDao; import org.libresonic.player.dao.MediaFileDao; @@ -27,6 +28,13 @@ import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.service.MediaScannerService; import org.libresonic.player.service.SettingsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; import org.springframework.web.servlet.view.RedirectView; @@ -40,22 +48,33 @@ import java.util.List; * * @author Sindre Mehus */ -public class MusicFolderSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/musicFolderSettings") +public class MusicFolderSettingsController { + @Autowired private SettingsService settingsService; + @Autowired private MediaScannerService mediaScannerService; + @Autowired private ArtistDao artistDao; + @Autowired private AlbumDao albumDao; + @Autowired private MediaFileDao mediaFileDao; - protected Object formBackingObject(HttpServletRequest request) throws Exception { + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(@RequestParam(value = "scanNow",required = false) String scanNow, + @RequestParam(value = "expunge",required = false) String expunge, + @RequestParam(value = "reload",required = false) String reload, + Model model) throws Exception { MusicFolderSettingsCommand command = new MusicFolderSettingsCommand(); - if (request.getParameter("scanNow") != null) { + if (scanNow != null) { settingsService.clearMusicFolderCache(); mediaScannerService.scanLibrary(); } - if (request.getParameter("expunge") != null) { + if (expunge != null) { expunge(); } @@ -66,8 +85,10 @@ public class MusicFolderSettingsController extends SimpleFormController { command.setScanning(mediaScannerService.isScanning()); command.setMusicFolders(wrap(settingsService.getAllMusicFolders(true, true))); command.setNewMusicFolder(new MusicFolderSettingsCommand.MusicFolderInfo()); - command.setReload(request.getParameter("reload") != null || request.getParameter("scanNow") != null); - return command; + command.setReload(reload != null || scanNow != null); + + model.addAttribute("command",command); + return "musicFolderSettings"; } private void expunge() { @@ -84,17 +105,18 @@ public class MusicFolderSettingsController extends SimpleFormController { return result; } - @Override - protected ModelAndView onSubmit(Object comm) throws Exception { - MusicFolderSettingsCommand command = (MusicFolderSettingsCommand) comm; - - for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) { - if (musicFolderInfo.isDelete()) { - settingsService.deleteMusicFolder(musicFolderInfo.getId()); - } else { - MusicFolder musicFolder = musicFolderInfo.toMusicFolder(); - if (musicFolder != null) { - settingsService.updateMusicFolder(musicFolder); + @RequestMapping(method = RequestMethod.POST) + protected String onSubmit(@ModelAttribute MusicFolderSettingsCommand command, Model model) throws Exception { + + if (command.getMusicFolders() != null) { + for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) { + if (musicFolderInfo.isDelete()) { + settingsService.deleteMusicFolder(musicFolderInfo.getId()); + } else { + MusicFolder musicFolder = musicFolderInfo.toMusicFolder(); + if (musicFolder != null) { + settingsService.updateMusicFolder(musicFolder); + } } } } @@ -111,26 +133,8 @@ public class MusicFolderSettingsController extends SimpleFormController { settingsService.save(); mediaScannerService.schedule(); - return new ModelAndView(new RedirectView(getSuccessView() + ".view?reload")); - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setMediaScannerService(MediaScannerService mediaScannerService) { - this.mediaScannerService = mediaScannerService; + model.addAttribute("command",command); + return "redirect:musicFolderSettings.view"; } - public void setArtistDao(ArtistDao artistDao) { - this.artistDao = artistDao; - } - - public void setAlbumDao(AlbumDao albumDao) { - this.albumDao = albumDao; - } - - public void setMediaFileDao(MediaFileDao mediaFileDao) { - this.mediaFileDao = mediaFileDao; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/musicFolderSettings.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/musicFolderSettings.jsp index de6af01d..b7c569be 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/musicFolderSettings.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/musicFolderSettings.jsp @@ -38,6 +38,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 index 431c2c54..270279f6 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -198,16 +198,6 @@ - - - - - - - - - - @@ -443,7 +433,6 @@ dlnaSettingsController sonosSettingsController shareSettingsController - musicFolderSettingsController transcodingSettingsController internetRadioSettingsController generalSettingsController From 7a76a3ea7594b3f54510d22e17f4e7db8098cf2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Wed, 30 Nov 2016 22:22:05 +0100 Subject: [PATCH 15/27] Migration of GeneralSettingsController + unit test. --- .../controller/GeneralSettingsController.java | 27 ++++++++++++------- .../webapp/WEB-INF/libresonic-servlet.xml | 7 ----- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java index 9c1b5ffb..daa38959 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java @@ -23,6 +23,12 @@ import java.util.Locale; import javax.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.mvc.SimpleFormController; import org.libresonic.player.command.GeneralSettingsCommand; @@ -34,11 +40,15 @@ import org.libresonic.player.service.SettingsService; * * @author Sindre Mehus */ -public class GeneralSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/generalSettings") +public class GeneralSettingsController { + @Autowired private SettingsService settingsService; - protected Object formBackingObject(HttpServletRequest request) throws Exception { + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(Model model) throws Exception { GeneralSettingsCommand command = new GeneralSettingsCommand(); command.setCoverArtFileTypes(settingsService.getCoverArtFileTypes()); command.setIgnoredArticles(settingsService.getIgnoredArticles()); @@ -76,12 +86,12 @@ public class GeneralSettingsController extends SimpleFormController { } command.setLocales(localeStrings); - return command; - + model.addAttribute("command",command); + return "generalSettings"; } - protected void doSubmitAction(Object comm) throws Exception { - GeneralSettingsCommand command = (GeneralSettingsCommand) comm; + @RequestMapping(method = RequestMethod.POST) + protected String doSubmitAction(@ModelAttribute GeneralSettingsCommand command, Model model) throws Exception { int themeIndex = Integer.parseInt(command.getThemeIndex()); Theme theme = settingsService.getAvailableThemes()[themeIndex]; @@ -112,9 +122,8 @@ public class GeneralSettingsController extends SimpleFormController { settingsService.setThemeId(theme.getId()); settingsService.setLocale(locale); settingsService.save(); - } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; + return "redirect:generalSettings.view"; } + } diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index 270279f6..690befd5 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -208,12 +208,6 @@ - - - - - - @@ -435,7 +429,6 @@ shareSettingsController transcodingSettingsController internetRadioSettingsController - generalSettingsController personalSettingsController avatarUploadController userSettingsController From c46416834b2f6c82cc0422160984ba27b7bbed2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 1 Dec 2016 21:53:55 +0100 Subject: [PATCH 16/27] Migration of PlayerSettingsController + unit test. --- .../controller/PlayerSettingsController.java | 38 ++++++++++--------- .../webapp/WEB-INF/libresonic-servlet.xml | 9 ----- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java index 2a6d5d28..50baca35 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java @@ -25,6 +25,12 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.mvc.SimpleFormController; import org.libresonic.player.command.PlayerSettingsCommand; @@ -42,14 +48,19 @@ import org.libresonic.player.service.TranscodingService; * * @author Sindre Mehus */ -public class PlayerSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/playerSettings") +public class PlayerSettingsController { + @Autowired private PlayerService playerService; + @Autowired private SecurityService securityService; + @Autowired private TranscodingService transcodingService; - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { + @RequestMapping(method = RequestMethod.GET) + protected Object formBackingObject(HttpServletRequest request, Model model) throws Exception { handleRequestParameters(request); List players = getPlayers(request); @@ -91,12 +102,12 @@ public class PlayerSettingsController extends SimpleFormController { command.setPlayers(players.toArray(new Player[players.size()])); command.setAdmin(user.isAdminRole()); - return command; + model.addAttribute("command",command); + return "playerSettings"; } - @Override - protected void doSubmitAction(Object comm) throws Exception { - PlayerSettingsCommand command = (PlayerSettingsCommand) comm; + @RequestMapping(method = RequestMethod.POST) + protected String doSubmitAction(@ModelAttribute PlayerSettingsCommand command, Model model) throws Exception { Player player = playerService.getPlayerById(command.getPlayerId()); player.setAutoControlEnabled(command.isAutoControlEnabled()); @@ -110,6 +121,8 @@ public class PlayerSettingsController extends SimpleFormController { transcodingService.setTranscodingsForPlayer(player, command.getActiveTranscodingIds()); command.setReloadNeeded(true); + model.addAttribute("command",command); + return "redirect:playerSettings.view"; } private List getPlayers(HttpServletRequest request) { @@ -135,15 +148,4 @@ public class PlayerSettingsController extends SimpleFormController { } } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setTranscodingService(TranscodingService transcodingService) { - this.transcodingService = transcodingService; - } } diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index 690befd5..7c7d01c7 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -173,14 +173,6 @@ - - - - - - - - @@ -423,7 +415,6 @@ starredController searchController settingsController - playerSettingsController dlnaSettingsController sonosSettingsController shareSettingsController From 0c265e2f3dee016b2bd00263c2ca41ea0b0f34a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 1 Dec 2016 22:19:28 +0100 Subject: [PATCH 17/27] Migration of SearchController + unit test. --- .../controller/PlayerSettingsController.java | 2 +- .../player/controller/SearchController.java | 43 +++++++++---------- .../webapp/WEB-INF/libresonic-servlet.xml | 10 ----- 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java index 50baca35..875a7cc8 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java @@ -60,7 +60,7 @@ public class PlayerSettingsController { private TranscodingService transcodingService; @RequestMapping(method = RequestMethod.GET) - protected Object formBackingObject(HttpServletRequest request, Model model) throws Exception { + protected String formBackingObject(HttpServletRequest request, Model model) throws Exception { handleRequestParameters(request); List players = getPlayers(request); diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java index a357b120..3c5144d1 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java @@ -25,7 +25,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.ui.Model; import org.springframework.validation.BindException; +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.SimpleFormController; @@ -45,24 +50,30 @@ import org.libresonic.player.service.SettingsService; * * @author Sindre Mehus */ -public class SearchController extends SimpleFormController { +@Controller +@RequestMapping("/search") +public class SearchController { private static final int MATCH_COUNT = 25; + @Autowired private SecurityService securityService; + @Autowired private SettingsService settingsService; + @Autowired private PlayerService playerService; + @Autowired private SearchService searchService; - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - return new SearchCommand(); + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(HttpServletRequest request, Model model) throws Exception { + model.addAttribute("command",new SearchCommand()); + return "search"; } - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object com, BindException errors) + @RequestMapping(method = RequestMethod.POST) + protected String onSubmit(HttpServletRequest request, HttpServletResponse response, SearchCommand command, Model model) throws Exception { - SearchCommand command = (SearchCommand) com; User user = securityService.getCurrentUser(request); UserSettings userSettings = settingsService.getUserSettings(user.getUsername()); @@ -90,22 +101,8 @@ public class SearchController extends SimpleFormController { command.setPlayer(playerService.getPlayer(request, response)); } - return new ModelAndView(getSuccessView(), errors.getModel()); + model.addAttribute("command",command); + return "search"; } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setSearchService(SearchService searchService) { - this.searchService = searchService; - } } diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index 7c7d01c7..afbf083e 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -161,15 +161,6 @@ - - - - - - - - - @@ -413,7 +404,6 @@ videoPlayerController nowPlayingController starredController - searchController settingsController dlnaSettingsController sonosSettingsController From f4636a09edf7a0d94a25f0af8a0eb2892f9ae484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Tue, 6 Dec 2016 19:51:24 +0100 Subject: [PATCH 18/27] Migration of UserSettingsController + unit test. --- .../controller/UserSettingsController.java | 62 ++++++++++++------- .../validator/UserSettingsValidator.java | 12 ++-- .../webapp/WEB-INF/libresonic-servlet.xml | 17 +---- 3 files changed, 44 insertions(+), 47 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java index 4a913f9f..adc91939 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java @@ -30,8 +30,16 @@ import org.libresonic.player.service.TranscodingService; import org.libresonic.player.util.Util; import org.apache.commons.lang.StringUtils; +import org.libresonic.player.validator.UserSettingsValidator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.ServletRequestUtils; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.SimpleFormController; import javax.servlet.http.HttpServletRequest; @@ -45,14 +53,27 @@ import java.util.List; * * @author Sindre Mehus */ -public class UserSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/userSettings") +@SessionAttributes(value = "command") +public class UserSettingsController { + @Autowired private SecurityService securityService; + @Autowired private SettingsService settingsService; + @Autowired private TranscodingService transcodingService; + @Autowired + private UserSettingsValidator userSettingsValidator; - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { + @InitBinder + protected void initBinder(WebDataBinder binder) { + binder.addValidators(userSettingsValidator); + } + + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(HttpServletRequest request,Model model) throws Exception { UserSettingsCommand command = new UserSettingsCommand(); User user = getUser(request); @@ -77,7 +98,8 @@ public class UserSettingsController extends SimpleFormController { command.setAllMusicFolders(settingsService.getAllMusicFolders()); command.setAllowedMusicFolderIds(Util.toIntArray(getAllowedMusicFolderIds(user))); - return command; + model.addAttribute("command",command); + return "userSettings"; } private User getUser(HttpServletRequest request) throws ServletRequestBindingException { @@ -103,18 +125,21 @@ public class UserSettingsController extends SimpleFormController { return result; } - @Override - protected void doSubmitAction(Object comm) throws Exception { - UserSettingsCommand command = (UserSettingsCommand) comm; + @RequestMapping(method = RequestMethod.POST) + protected String doSubmitAction(@ModelAttribute("command") @Validated UserSettingsCommand command,final BindingResult binding) throws Exception { - if (command.isDeleteUser()) { - deleteUser(command); - } else if (command.isNewUser()) { - createUser(command); - } else { - updateUser(command); + if (!binding.hasErrors()) { + if (command.isDeleteUser()) { + deleteUser(command); + } else if (command.isNewUser()) { + createUser(command); + } else { + updateUser(command); + } } resetCommand(command); + + return "userSettings"; } private void deleteUser(UserSettingsCommand command) { @@ -176,15 +201,4 @@ public class UserSettingsController extends SimpleFormController { command.setReload(true); } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - 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/validator/UserSettingsValidator.java b/libresonic-main/src/main/java/org/libresonic/player/validator/UserSettingsValidator.java index 3686e8c6..755ae0ea 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/validator/UserSettingsValidator.java +++ b/libresonic-main/src/main/java/org/libresonic/player/validator/UserSettingsValidator.java @@ -24,6 +24,8 @@ import org.libresonic.player.controller.UserSettingsController; import org.libresonic.player.service.SecurityService; import org.libresonic.player.service.SettingsService; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import org.springframework.validation.Validator; @@ -32,9 +34,12 @@ import org.springframework.validation.Validator; * * @author Sindre Mehus */ +@Component public class UserSettingsValidator implements Validator { + @Autowired private SecurityService securityService; + @Autowired private SettingsService settingsService; /** @@ -82,11 +87,4 @@ public class UserSettingsValidator implements Validator { } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } } \ No newline at end of file diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index afbf083e..a649d1f3 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -13,7 +13,7 @@ http://www.springframework.org/schema/mvc/spring-mvc.xsd"> - + @@ -203,16 +203,6 @@ - - - - - - - - - - @@ -364,10 +354,6 @@ - - - - @@ -412,7 +398,6 @@ internetRadioSettingsController personalSettingsController avatarUploadController - userSettingsController passwordSettingsController premiumSettingsController allmusicController From ba80e997032610692652546439ba1c65aafd781c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 11 Dec 2016 17:18:28 +0100 Subject: [PATCH 19/27] Migration of PersonalSettingsController + unit test. --- .../PersonalSettingsController.java | 38 ++++++++++++------- .../webapp/WEB-INF/libresonic-servlet.xml | 8 ---- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PersonalSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PersonalSettingsController.java index 3a0cb5f0..433e471d 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PersonalSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PersonalSettingsController.java @@ -25,6 +25,12 @@ import java.util.Locale; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.mvc.SimpleFormController; import org.libresonic.player.command.PersonalSettingsCommand; @@ -41,13 +47,17 @@ import org.libresonic.player.service.SettingsService; * * @author Sindre Mehus */ -public class PersonalSettingsController extends SimpleFormController { +@Controller +@RequestMapping("/personalSettings") +public class PersonalSettingsController { + @Autowired private SettingsService settingsService; + @Autowired private SecurityService securityService; - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { + @ModelAttribute + protected void formBackingObject(HttpServletRequest request,Model model) throws Exception { PersonalSettingsCommand command = new PersonalSettingsCommand(); User user = securityService.getCurrentUser(request); @@ -100,12 +110,16 @@ public class PersonalSettingsController extends SimpleFormController { } } - return command; + model.addAttribute("command",command); } - @Override - protected void doSubmitAction(Object comm) throws Exception { - PersonalSettingsCommand command = (PersonalSettingsCommand) comm; + @RequestMapping(method = RequestMethod.GET) + protected String displayForm() throws Exception { + return "personalSettings"; + } + + @RequestMapping(method = RequestMethod.POST) + protected String doSubmitAction(@ModelAttribute("command") PersonalSettingsCommand command,Model model) throws Exception { int localeIndex = Integer.parseInt(command.getLocaleIndex()); Locale locale = null; @@ -152,6 +166,9 @@ public class PersonalSettingsController extends SimpleFormController { settingsService.updateUserSettings(settings); command.setReloadNeeded(true); + + model.addAttribute("command",command); + return "personalSettings"; } private int getAvatarId(UserSettings userSettings) { @@ -178,11 +195,4 @@ public class PersonalSettingsController extends SimpleFormController { return avatarId; } - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } } diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index a649d1f3..835583ba 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -191,13 +191,6 @@ - - - - - - - @@ -396,7 +389,6 @@ shareSettingsController transcodingSettingsController internetRadioSettingsController - personalSettingsController avatarUploadController passwordSettingsController premiumSettingsController From a0ab86a6acbfccfdbbafdeb637ba1d5ebca9d275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 11 Dec 2016 17:44:31 +0100 Subject: [PATCH 20/27] Corrections on NetworkSettingsController. --- .../controller/NetworkSettingsController.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java index 02f622bd..ae5129e9 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java @@ -52,8 +52,8 @@ public class NetworkSettingsController { @Autowired private NetworkService networkService; - @RequestMapping(method = RequestMethod.GET) - protected String formBackingObject(Model model) throws Exception { + @ModelAttribute + protected void formBackingObject(Model model) throws Exception { NetworkSettingsCommand command = new NetworkSettingsCommand(); command.setPortForwardingEnabled(settingsService.isPortForwardingEnabled()); command.setUrlRedirectionEnabled(settingsService.isUrlRedirectionEnabled()); @@ -62,27 +62,23 @@ public class NetworkSettingsController { command.setUrlRedirectCustomUrl(settingsService.getUrlRedirectCustomUrl()); command.setPort(settingsService.getPort()); command.setLicenseInfo(settingsService.getLicenseInfo()); - model.addAttribute("command",command); + } + + @RequestMapping(method = RequestMethod.GET) + protected String displayForm() throws Exception { return "networkSettings"; } @RequestMapping(method = RequestMethod.POST) - protected String doSubmitAction(@ModelAttribute NetworkSettingsCommand command, Model model) throws Exception { + protected String doSubmitAction(@ModelAttribute("command") NetworkSettingsCommand command, Model model) throws Exception { command.setToast(true); settingsService.setPortForwardingEnabled(command.isPortForwardingEnabled()); settingsService.setUrlRedirectionEnabled(command.isUrlRedirectionEnabled()); - String urlRedirectType = command.getUrlRedirectType(); - if (urlRedirectType == null) { - command.setUrlRedirectType("NORMAL"); - command.setUrlRedirectFrom("yourname"); - command.setUrlRedirectCustomUrl("http://"); - } else { - settingsService.setUrlRedirectType(UrlRedirectType.valueOf(command.getUrlRedirectType())); - settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom())); - settingsService.setUrlRedirectCustomUrl(StringUtils.trimToEmpty(command.getUrlRedirectCustomUrl())); - } + settingsService.setUrlRedirectType(UrlRedirectType.valueOf(command.getUrlRedirectType())); + settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom())); + settingsService.setUrlRedirectCustomUrl(StringUtils.trimToEmpty(command.getUrlRedirectCustomUrl())); if (settingsService.getServerId() == null) { Random rand = new Random(System.currentTimeMillis()); @@ -92,7 +88,6 @@ public class NetworkSettingsController { settingsService.save(); networkService.initPortForwarding(0); networkService.initUrlRedirection(true); - model.addAttribute("command",command); return "networkSettings"; } From b2b4384387f8a6589a160129b317f99bcbc51b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 11 Dec 2016 19:03:41 +0100 Subject: [PATCH 21/27] Corrections on MusicFolderSettingsController. --- .../MusicFolderSettingsController.java | 30 ++++++++++--------- .../WEB-INF/jsp/musicFolderSettings.jsp | 1 - 2 files changed, 16 insertions(+), 15 deletions(-) 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 6d19d917..4c3597f4 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 @@ -64,7 +64,12 @@ public class MusicFolderSettingsController { private MediaFileDao mediaFileDao; @RequestMapping(method = RequestMethod.GET) - protected String formBackingObject(@RequestParam(value = "scanNow",required = false) String scanNow, + protected String displayForm() throws Exception { + return "musicFolderSettings"; + } + + @ModelAttribute + protected void formBackingObject(@RequestParam(value = "scanNow",required = false) String scanNow, @RequestParam(value = "expunge",required = false) String expunge, @RequestParam(value = "reload",required = false) String reload, Model model) throws Exception { @@ -88,9 +93,9 @@ public class MusicFolderSettingsController { command.setReload(reload != null || scanNow != null); model.addAttribute("command",command); - return "musicFolderSettings"; } + private void expunge() { artistDao.expunge(); albumDao.expunge(); @@ -106,17 +111,15 @@ public class MusicFolderSettingsController { } @RequestMapping(method = RequestMethod.POST) - protected String onSubmit(@ModelAttribute MusicFolderSettingsCommand command, Model model) throws Exception { - - if (command.getMusicFolders() != null) { - for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) { - if (musicFolderInfo.isDelete()) { - settingsService.deleteMusicFolder(musicFolderInfo.getId()); - } else { - MusicFolder musicFolder = musicFolderInfo.toMusicFolder(); - if (musicFolder != null) { - settingsService.updateMusicFolder(musicFolder); - } + protected String onSubmit(@ModelAttribute("command") MusicFolderSettingsCommand command, Model model) throws Exception { + + for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) { + if (musicFolderInfo.isDelete()) { + settingsService.deleteMusicFolder(musicFolderInfo.getId()); + } else { + MusicFolder musicFolder = musicFolderInfo.toMusicFolder(); + if (musicFolder != null) { + settingsService.updateMusicFolder(musicFolder); } } } @@ -133,7 +136,6 @@ public class MusicFolderSettingsController { settingsService.save(); mediaScannerService.schedule(); - model.addAttribute("command",command); return "redirect:musicFolderSettings.view"; } diff --git a/libresonic-main/src/main/webapp/WEB-INF/jsp/musicFolderSettings.jsp b/libresonic-main/src/main/webapp/WEB-INF/jsp/musicFolderSettings.jsp index b7c569be..de6af01d 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/jsp/musicFolderSettings.jsp +++ b/libresonic-main/src/main/webapp/WEB-INF/jsp/musicFolderSettings.jsp @@ -38,7 +38,6 @@ - From 4561e388073d8885e1ffc5988099a9d7a494a58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 11 Dec 2016 19:11:29 +0100 Subject: [PATCH 22/27] Corrections on GeneralSettingsController. --- .../player/controller/GeneralSettingsController.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java index daa38959..6ee010c1 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java @@ -48,7 +48,12 @@ public class GeneralSettingsController { private SettingsService settingsService; @RequestMapping(method = RequestMethod.GET) - protected String formBackingObject(Model model) throws Exception { + protected String displayForm() throws Exception { + return "generalSettings"; + } + + @ModelAttribute + protected void formBackingObject(Model model) throws Exception { GeneralSettingsCommand command = new GeneralSettingsCommand(); command.setCoverArtFileTypes(settingsService.getCoverArtFileTypes()); command.setIgnoredArticles(settingsService.getIgnoredArticles()); @@ -87,11 +92,10 @@ public class GeneralSettingsController { command.setLocales(localeStrings); model.addAttribute("command",command); - return "generalSettings"; } @RequestMapping(method = RequestMethod.POST) - protected String doSubmitAction(@ModelAttribute GeneralSettingsCommand command, Model model) throws Exception { + protected String doSubmitAction(@ModelAttribute("command") GeneralSettingsCommand command, Model model) throws Exception { int themeIndex = Integer.parseInt(command.getThemeIndex()); Theme theme = settingsService.getAvailableThemes()[themeIndex]; From ddea3f47ffeba88bfd58b8136eab9c2201f4f2d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 11 Dec 2016 19:21:02 +0100 Subject: [PATCH 23/27] Corrections on PlayerSettingsController and SearchController. --- .../player/controller/PlayerSettingsController.java | 11 +++++++---- .../player/controller/SearchController.java | 12 ++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java index 875a7cc8..9dd3df9c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java @@ -60,7 +60,12 @@ public class PlayerSettingsController { private TranscodingService transcodingService; @RequestMapping(method = RequestMethod.GET) - protected String formBackingObject(HttpServletRequest request, Model model) throws Exception { + protected String displayForm() throws Exception { + return "playerSettings"; + } + + @ModelAttribute + protected void formBackingObject(HttpServletRequest request, Model model) throws Exception { handleRequestParameters(request); List players = getPlayers(request); @@ -103,11 +108,10 @@ public class PlayerSettingsController { command.setAdmin(user.isAdminRole()); model.addAttribute("command",command); - return "playerSettings"; } @RequestMapping(method = RequestMethod.POST) - protected String doSubmitAction(@ModelAttribute PlayerSettingsCommand command, Model model) throws Exception { + protected String doSubmitAction(@ModelAttribute("command") PlayerSettingsCommand command, Model model) throws Exception { Player player = playerService.getPlayerById(command.getPlayerId()); player.setAutoControlEnabled(command.isAutoControlEnabled()); @@ -121,7 +125,6 @@ public class PlayerSettingsController { transcodingService.setTranscodingsForPlayer(player, command.getActiveTranscodingIds()); command.setReloadNeeded(true); - model.addAttribute("command",command); return "redirect:playerSettings.view"; } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java index 3c5144d1..7ee3fbe8 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindException; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; @@ -66,13 +67,17 @@ public class SearchController { private SearchService searchService; @RequestMapping(method = RequestMethod.GET) - protected String formBackingObject(HttpServletRequest request, Model model) throws Exception { - model.addAttribute("command",new SearchCommand()); + protected String displayForm() throws Exception { return "search"; } + @ModelAttribute + protected void formBackingObject(HttpServletRequest request, Model model) throws Exception { + model.addAttribute("command",new SearchCommand()); + } + @RequestMapping(method = RequestMethod.POST) - protected String onSubmit(HttpServletRequest request, HttpServletResponse response, SearchCommand command, Model model) + protected String onSubmit(HttpServletRequest request, HttpServletResponse response,@ModelAttribute("command") SearchCommand command, Model model) throws Exception { User user = securityService.getCurrentUser(request); @@ -101,7 +106,6 @@ public class SearchController { command.setPlayer(playerService.getPlayer(request, response)); } - model.addAttribute("command",command); return "search"; } From d78244aa36ef596ce8a16ce3189802651c16c81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 11 Dec 2016 19:31:33 +0100 Subject: [PATCH 24/27] Corrections on UserSettingsController. --- .../controller/UserSettingsController.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java index adc91939..256acf77 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java @@ -73,7 +73,12 @@ public class UserSettingsController { } @RequestMapping(method = RequestMethod.GET) - protected String formBackingObject(HttpServletRequest request,Model model) throws Exception { + protected String displayForm() throws Exception { + return "userSettings"; + } + + @ModelAttribute + protected void formBackingObject(HttpServletRequest request,Model model) throws Exception { UserSettingsCommand command = new UserSettingsCommand(); User user = getUser(request); @@ -99,7 +104,6 @@ public class UserSettingsController { command.setAllowedMusicFolderIds(Util.toIntArray(getAllowedMusicFolderIds(user))); model.addAttribute("command",command); - return "userSettings"; } private User getUser(HttpServletRequest request) throws ServletRequestBindingException { @@ -126,16 +130,14 @@ public class UserSettingsController { } @RequestMapping(method = RequestMethod.POST) - protected String doSubmitAction(@ModelAttribute("command") @Validated UserSettingsCommand command,final BindingResult binding) throws Exception { - - if (!binding.hasErrors()) { - if (command.isDeleteUser()) { - deleteUser(command); - } else if (command.isNewUser()) { - createUser(command); - } else { - updateUser(command); - } + protected String doSubmitAction(@ModelAttribute("command") @Validated UserSettingsCommand command) throws Exception { + + if (command.isDeleteUser()) { + deleteUser(command); + } else if (command.isNewUser()) { + createUser(command); + } else { + updateUser(command); } resetCommand(command); From ddd849804059e6e0a382d6e2dfdec0dea550a38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 11 Dec 2016 21:13:51 +0100 Subject: [PATCH 25/27] Move to Spring4 + remove PasswordSettingsController + remove PremiumSettingsController --- .../command/PasswordSettingsCommand.java | 75 ------------ .../command/PremiumSettingsCommand.java | 107 ------------------ .../controller/GeneralSettingsController.java | 12 +- .../MusicFolderSettingsController.java | 6 - .../controller/NetworkSettingsController.java | 15 +-- .../PasswordSettingsController.java | 60 ---------- .../PersonalSettingsController.java | 21 ++-- .../controller/PlayerSettingsController.java | 23 ++-- .../controller/PodcastSettingsController.java | 9 +- .../controller/PremiumSettingsController.java | 80 ------------- .../player/controller/SearchController.java | 27 ++--- .../controller/UserSettingsController.java | 6 +- .../org/libresonic/player/dao/RatingDao.java | 2 +- .../libresonic/player/dao/schema/Schema.java | 2 +- .../player/dao/schema/hsql/Schema26.java | 4 +- .../player/dao/schema/hsql/Schema27.java | 2 +- .../player/dao/schema/hsql/Schema28.java | 2 +- .../player/dao/schema/hsql/Schema29.java | 2 +- .../player/dao/schema/hsql/Schema30.java | 2 +- .../player/dao/schema/hsql/Schema31.java | 2 +- .../player/dao/schema/hsql/Schema32.java | 4 +- .../player/dao/schema/hsql/Schema33.java | 2 +- .../player/dao/schema/hsql/Schema34.java | 2 +- .../player/dao/schema/hsql/Schema35.java | 6 +- .../player/dao/schema/hsql/Schema36.java | 2 +- .../player/dao/schema/hsql/Schema37.java | 6 +- .../player/dao/schema/hsql/Schema38.java | 2 +- .../player/dao/schema/hsql/Schema40.java | 2 +- .../player/dao/schema/hsql/Schema43.java | 4 +- .../player/dao/schema/hsql/Schema45.java | 4 +- .../player/dao/schema/hsql/Schema46.java | 2 +- .../player/dao/schema/hsql/Schema47.java | 2 +- .../player/dao/schema/hsql/Schema49.java | 2 +- .../player/dao/schema/hsql/Schema50.java | 4 +- .../player/dao/schema/hsql/Schema51.java | 2 +- .../player/dao/schema/hsql/Schema52.java | 2 +- .../player/dao/schema/hsql/Schema53.java | 2 +- .../player/dao/schema/hsql/Schema61.java | 2 +- .../player/dao/schema/hsql/Schema62.java | 2 +- .../validator/PasswordSettingsValidator.java | 46 -------- .../validator/PremiumSettingsValidator.java | 53 --------- .../WEB-INF/applicationContext-security.xml | 4 +- .../webapp/WEB-INF/libresonic-servlet.xml | 22 ---- .../org/libresonic/player/TestCaseUtils.java | 2 +- pom.xml | 5 +- 45 files changed, 78 insertions(+), 567 deletions(-) delete mode 100644 libresonic-main/src/main/java/org/libresonic/player/command/PasswordSettingsCommand.java delete mode 100644 libresonic-main/src/main/java/org/libresonic/player/command/PremiumSettingsCommand.java delete mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/PasswordSettingsController.java delete mode 100644 libresonic-main/src/main/java/org/libresonic/player/controller/PremiumSettingsController.java delete mode 100644 libresonic-main/src/main/java/org/libresonic/player/validator/PasswordSettingsValidator.java delete mode 100644 libresonic-main/src/main/java/org/libresonic/player/validator/PremiumSettingsValidator.java diff --git a/libresonic-main/src/main/java/org/libresonic/player/command/PasswordSettingsCommand.java b/libresonic-main/src/main/java/org/libresonic/player/command/PasswordSettingsCommand.java deleted file mode 100644 index 8f12e554..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/command/PasswordSettingsCommand.java +++ /dev/null @@ -1,75 +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.command; - -import org.libresonic.player.controller.*; - -/** - * Command used in {@link PasswordSettingsController}. - * - * @author Sindre Mehus - */ -public class PasswordSettingsCommand { - private String username; - private String password; - private String confirmPassword; - private boolean ldapAuthenticated; - private boolean toast; - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getConfirmPassword() { - return confirmPassword; - } - - public void setConfirmPassword(String confirmPassword) { - this.confirmPassword = confirmPassword; - } - - public boolean isLdapAuthenticated() { - return ldapAuthenticated; - } - - public void setLdapAuthenticated(boolean ldapAuthenticated) { - this.ldapAuthenticated = ldapAuthenticated; - } - - public boolean isToast() { - return toast; - } - - public void setToast(boolean toast) { - this.toast = toast; - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/command/PremiumSettingsCommand.java b/libresonic-main/src/main/java/org/libresonic/player/command/PremiumSettingsCommand.java deleted file mode 100644 index f20014dc..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/command/PremiumSettingsCommand.java +++ /dev/null @@ -1,107 +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.command; - -import org.apache.commons.lang.StringUtils; - -import org.libresonic.player.controller.PremiumSettingsController; -import org.libresonic.player.domain.LicenseInfo; -import org.libresonic.player.domain.User; - -/** - * Command used in {@link PremiumSettingsController}. - * - * @author Sindre Mehus - */ -public class PremiumSettingsCommand { - - private String path; - private String brand; - private LicenseInfo licenseInfo; - private String licenseCode; - private boolean forceChange; - private boolean submissionError; - private User user; - private boolean toast; - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public String getBrand() { - return brand; - } - - public void setBrand(String brand) { - this.brand = brand; - } - - public LicenseInfo getLicenseInfo() { - return licenseInfo; - } - - public String getLicenseCode() { - return licenseCode; - } - - public void setLicenseCode(String licenseCode) { - this.licenseCode = StringUtils.trimToNull(licenseCode); - } - - public void setLicenseInfo(LicenseInfo licenseInfo) { - this.licenseInfo = licenseInfo; - } - - public boolean isForceChange() { - return forceChange; - } - - public void setForceChange(boolean forceChange) { - this.forceChange = forceChange; - } - - public boolean isSubmissionError() { - return submissionError; - } - - public void setSubmissionError(boolean submissionError) { - this.submissionError = submissionError; - } - - public void setUser(User user) { - this.user = user; - } - - public User getUser() { - return user; - } - - public void setToast(boolean toast) { - this.toast = toast; - } - - public boolean isToast() { - return toast; - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java index 6ee010c1..b549ee56 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/GeneralSettingsController.java @@ -19,21 +19,17 @@ */ package org.libresonic.player.controller; -import java.util.Locale; - -import javax.servlet.http.HttpServletRequest; - +import org.libresonic.player.command.GeneralSettingsCommand; +import org.libresonic.player.domain.Theme; +import org.libresonic.player.service.SettingsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.libresonic.player.command.GeneralSettingsCommand; -import org.libresonic.player.domain.Theme; -import org.libresonic.player.service.SettingsService; +import java.util.Locale; /** * Controller for the page used to administrate general settings. 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 4c3597f4..47a66562 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 @@ -20,14 +20,12 @@ package org.libresonic.player.controller; import org.libresonic.player.command.MusicFolderSettingsCommand; -import org.libresonic.player.command.NetworkSettingsCommand; import org.libresonic.player.dao.AlbumDao; import org.libresonic.player.dao.ArtistDao; import org.libresonic.player.dao.MediaFileDao; import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.service.MediaScannerService; import org.libresonic.player.service.SettingsService; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -35,11 +33,7 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.springframework.web.servlet.view.RedirectView; -import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.List; diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java index ae5129e9..ed341e94 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/NetworkSettingsController.java @@ -19,24 +19,19 @@ */ package org.libresonic.player.controller; -import java.util.Random; - -import javax.servlet.http.HttpServletRequest; - import org.apache.commons.lang.StringUtils; -import org.apache.tools.ant.taskdefs.ManifestTask; +import org.libresonic.player.command.NetworkSettingsCommand; +import org.libresonic.player.domain.UrlRedirectType; +import org.libresonic.player.service.NetworkService; +import org.libresonic.player.service.SettingsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.libresonic.player.command.NetworkSettingsCommand; -import org.libresonic.player.domain.UrlRedirectType; -import org.libresonic.player.service.NetworkService; -import org.libresonic.player.service.SettingsService; +import java.util.Random; /** * Controller for the page used to change the network settings. diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PasswordSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PasswordSettingsController.java deleted file mode 100644 index 3fb1e1ce..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PasswordSettingsController.java +++ /dev/null @@ -1,60 +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 org.springframework.web.servlet.mvc.*; -import org.libresonic.player.service.*; -import org.libresonic.player.command.*; -import org.libresonic.player.domain.*; - -import javax.servlet.http.*; - -/** - * Controller for the page used to change password. - * - * @author Sindre Mehus - */ -public class PasswordSettingsController extends SimpleFormController { - - private SecurityService securityService; - - protected Object formBackingObject(HttpServletRequest request) throws Exception { - PasswordSettingsCommand command = new PasswordSettingsCommand(); - User user = securityService.getCurrentUser(request); - command.setUsername(user.getUsername()); - command.setLdapAuthenticated(user.isLdapAuthenticated()); - return command; - } - - protected void doSubmitAction(Object comm) throws Exception { - PasswordSettingsCommand command = (PasswordSettingsCommand) comm; - User user = securityService.getUserByName(command.getUsername()); - user.setPassword(command.getPassword()); - securityService.updateUser(user); - - command.setPassword(null); - command.setConfirmPassword(null); - command.setToast(true); - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PersonalSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PersonalSettingsController.java index 433e471d..f09afc82 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PersonalSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PersonalSettingsController.java @@ -19,28 +19,21 @@ */ package org.libresonic.player.controller; -import java.util.Date; -import java.util.Locale; - -import javax.servlet.http.HttpServletRequest; - import org.apache.commons.lang.StringUtils; +import org.libresonic.player.command.PersonalSettingsCommand; +import org.libresonic.player.domain.*; +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.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.libresonic.player.command.PersonalSettingsCommand; -import org.libresonic.player.domain.AlbumListType; -import org.libresonic.player.domain.AvatarScheme; -import org.libresonic.player.domain.Theme; -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 javax.servlet.http.HttpServletRequest; +import java.util.Date; +import java.util.Locale; /** * Controller for the page used to administrate per-user settings. diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java index 9dd3df9c..433467bb 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java @@ -19,29 +19,22 @@ */ package org.libresonic.player.controller; -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - import org.apache.commons.lang.StringUtils; +import org.libresonic.player.command.PlayerSettingsCommand; +import org.libresonic.player.domain.*; +import org.libresonic.player.service.PlayerService; +import org.libresonic.player.service.SecurityService; +import org.libresonic.player.service.TranscodingService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.libresonic.player.command.PlayerSettingsCommand; -import org.libresonic.player.domain.Player; -import org.libresonic.player.domain.PlayerTechnology; -import org.libresonic.player.domain.TranscodeScheme; -import org.libresonic.player.domain.Transcoding; -import org.libresonic.player.domain.User; -import org.libresonic.player.service.PlayerService; -import org.libresonic.player.service.SecurityService; -import org.libresonic.player.service.TranscodingService; +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; /** * Controller for the player settings page. diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java index 4a1133de..bec26a95 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PodcastSettingsController.java @@ -19,18 +19,15 @@ */ package org.libresonic.player.controller; +import org.libresonic.player.command.PodcastSettingsCommand; +import org.libresonic.player.service.PodcastService; +import org.libresonic.player.service.SettingsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.libresonic.player.service.SettingsService; -import org.libresonic.player.service.PodcastService; -import org.libresonic.player.command.PodcastSettingsCommand; - -import javax.servlet.http.HttpServletRequest; /** * Controller for the page used to administrate the Podcast receiver. diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PremiumSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PremiumSettingsController.java deleted file mode 100644 index 39c29a6c..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PremiumSettingsController.java +++ /dev/null @@ -1,80 +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.util.Date; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import org.libresonic.player.command.PremiumSettingsCommand; -import org.libresonic.player.service.SecurityService; -import org.libresonic.player.service.SettingsService; - -/** - * Controller for the Subsonic Premium page. - * - * @author Sindre Mehus - */ -public class PremiumSettingsController extends SimpleFormController { - - private SettingsService settingsService; - private SecurityService securityService; - - protected Object formBackingObject(HttpServletRequest request) throws Exception { - PremiumSettingsCommand command = new PremiumSettingsCommand(); - command.setPath(request.getParameter("path")); - command.setForceChange(request.getParameter("change") != null); - command.setLicenseInfo(settingsService.getLicenseInfo()); - command.setBrand(settingsService.getBrand()); - command.setUser(securityService.getCurrentUser(request)); - return command; - } - - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object com, BindException errors) - throws Exception { - PremiumSettingsCommand command = (PremiumSettingsCommand) com; - Date now = new Date(); - - settingsService.setLicenseCode(command.getLicenseCode()); - settingsService.setLicenseEmail(command.getLicenseInfo().getLicenseEmail()); - settingsService.setLicenseDate(now); - settingsService.save(); - settingsService.scheduleLicenseValidation(); - - // Reflect changes in view. The validator will validate the license asynchronously. - command.setLicenseInfo(settingsService.getLicenseInfo()); - command.setToast(true); - - return new ModelAndView(getSuccessView(), errors.getModel()); - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java index 7ee3fbe8..197d96b8 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java @@ -19,32 +19,23 @@ */ package org.libresonic.player.controller; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.lang.StringUtils; +import org.libresonic.player.command.SearchCommand; +import org.libresonic.player.domain.*; +import org.libresonic.player.service.PlayerService; +import org.libresonic.player.service.SearchService; +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.ui.Model; -import org.springframework.validation.BindException; import org.springframework.web.bind.annotation.ModelAttribute; 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.SimpleFormController; -import org.libresonic.player.command.SearchCommand; -import org.libresonic.player.domain.MusicFolder; -import org.libresonic.player.domain.SearchCriteria; -import org.libresonic.player.domain.SearchResult; -import org.libresonic.player.domain.User; -import org.libresonic.player.domain.UserSettings; -import org.libresonic.player.service.PlayerService; -import org.libresonic.player.service.SearchService; -import org.libresonic.player.service.SecurityService; -import org.libresonic.player.service.SettingsService; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * Controller for the search page. diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java index 256acf77..02b8c294 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/UserSettingsController.java @@ -19,6 +19,7 @@ */ package org.libresonic.player.controller; +import org.apache.commons.lang.StringUtils; import org.libresonic.player.command.UserSettingsCommand; import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.domain.TranscodeScheme; @@ -28,22 +29,17 @@ import org.libresonic.player.service.SecurityService; import org.libresonic.player.service.SettingsService; import org.libresonic.player.service.TranscodingService; import org.libresonic.player.util.Util; - -import org.apache.commons.lang.StringUtils; import org.libresonic.player.validator.UserSettingsValidator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.ServletRequestUtils; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.mvc.SimpleFormController; import javax.servlet.http.HttpServletRequest; - import java.util.ArrayList; import java.util.Date; import java.util.List; diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/RatingDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/RatingDao.java index 6572fac7..2dec6169 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/RatingDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/RatingDao.java @@ -107,7 +107,7 @@ public class RatingDao extends AbstractDao { */ public Integer getRatingForUser(String username, MediaFile mediaFile) { try { - return getJdbcTemplate().queryForInt("select rating from user_rating where username=? and path=?", new Object[]{username, mediaFile.getPath()}); + return getJdbcTemplate().queryForObject("select rating from user_rating where username=? and path=?", new Object[]{username, mediaFile.getPath()},Integer.class); } catch (EmptyResultDataAccessException x) { return null; } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/Schema.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/Schema.java index 4cf63dca..13872a82 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/Schema.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/Schema.java @@ -68,7 +68,7 @@ public abstract class Schema { protected boolean rowExists(JdbcTemplate template, String whereClause, String table) { try { - int rowCount = template.queryForInt("select count(*) from " + table + " where " + whereClause); + int rowCount = template.queryForObject("select count(*) from " + table + " where " + whereClause,Integer.class); return rowCount > 0; } catch (Exception x) { return false; diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema26.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema26.java index 8094e7c2..05413aaf 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema26.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema26.java @@ -35,7 +35,7 @@ public class Schema26 extends Schema { public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 2") == 0) { + if (template.queryForObject("select count(*) from version where version = 2",Integer.class) == 0) { LOG.info("Updating database schema to version 2."); template.execute("insert into version values (2)"); } @@ -99,7 +99,7 @@ public class Schema26 extends Schema { LOG.info("Database column 'player.dynamic_ip' was added successfully."); } - if (template.queryForInt("select count(*) from role where id = 6") == 0) { + if (template.queryForObject("select count(*) from role where id = 6",Integer.class) == 0) { LOG.info("Role 'comment' not found in database. Creating it."); template.execute("insert into role values (6, 'comment')"); template.execute("insert into user_role " + diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema27.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema27.java index baa4672e..08ae2aa4 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema27.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema27.java @@ -35,7 +35,7 @@ public class Schema27 extends Schema { public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 3") == 0) { + if (template.queryForObject("select count(*) from version where version = 3",Integer.class) == 0) { LOG.info("Updating database schema to version 3."); template.execute("insert into version values (3)"); diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema28.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema28.java index c1678f67..515a4c0f 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema28.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema28.java @@ -35,7 +35,7 @@ public class Schema28 extends Schema { public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 4") == 0) { + if (template.queryForObject("select count(*) from version where version = 4",Integer.class) == 0) { LOG.info("Updating database schema to version 4."); template.execute("insert into version values (4)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema29.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema29.java index 2495af4b..bef298f9 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema29.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema29.java @@ -35,7 +35,7 @@ public class Schema29 extends Schema { public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 5") == 0) { + if (template.queryForObject("select count(*) from version where version = 5",Integer.class) == 0) { LOG.info("Updating database schema to version 5."); template.execute("insert into version values (5)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema30.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema30.java index 4a72499b..18e73175 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema30.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema30.java @@ -35,7 +35,7 @@ public class Schema30 extends Schema { public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 6") == 0) { + if (template.queryForObject("select count(*) from version where version = 6", Integer.class) == 0) { LOG.info("Updating database schema to version 6."); template.execute("insert into version values (6)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema31.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema31.java index a8bdc198..6019070c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema31.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema31.java @@ -35,7 +35,7 @@ public class Schema31 extends Schema { public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 7") == 0) { + if (template.queryForObject("select count(*) from version where version = 7",Integer.class) == 0) { LOG.info("Updating database schema to version 7."); template.execute("insert into version values (7)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema32.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema32.java index bc134665..85ad7f50 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema32.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema32.java @@ -35,7 +35,7 @@ public class Schema32 extends Schema { public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 8") == 0) { + if (template.queryForObject("select count(*) from version where version = 8",Integer.class) == 0) { LOG.info("Updating database schema to version 8."); template.execute("insert into version values (8)"); } @@ -83,7 +83,7 @@ public class Schema32 extends Schema { LOG.info("Database table 'podcast_episode' was created successfully."); } - if (template.queryForInt("select count(*) from role where id = 7") == 0) { + if (template.queryForObject("select count(*) from role where id = 7",Integer.class) == 0) { LOG.info("Role 'podcast' not found in database. Creating it."); template.execute("insert into role values (7, 'podcast')"); template.execute("insert into user_role " + diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema33.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema33.java index c76376d1..ffb0f4c1 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema33.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema33.java @@ -36,7 +36,7 @@ public class Schema33 extends Schema { public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 9") == 0) { + if (template.queryForObject("select count(*) from version where version = 9",Integer.class) == 0) { LOG.info("Updating database schema to version 9."); template.execute("insert into version values (9)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema34.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema34.java index 9fb38f88..7f3b09c6 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema34.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema34.java @@ -36,7 +36,7 @@ public class Schema34 extends Schema { public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 10") == 0) { + if (template.queryForObject("select count(*) from version where version = 10",Integer.class) == 0) { LOG.info("Updating database schema to version 10."); template.execute("insert into version values (10)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema35.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema35.java index c7244686..5ed4b9d5 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema35.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema35.java @@ -58,7 +58,7 @@ public class Schema35 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 11") == 0) { + if (template.queryForObject("select count(*) from version where version = 11",Integer.class) == 0) { LOG.info("Updating database schema to version 11."); template.execute("insert into version values (11)"); } @@ -75,7 +75,7 @@ public class Schema35 extends Schema { LOG.info("Database column 'user_settings.web_player_default' was added successfully."); } - if (template.queryForInt("select count(*) from role where id = 8") == 0) { + if (template.queryForObject("select count(*) from role where id = 8",Integer.class) == 0) { LOG.info("Role 'stream' not found in database. Creating it."); template.execute("insert into role values (8, 'stream')"); template.execute("insert into user_role select distinct u.username, 8 from user u"); @@ -135,7 +135,7 @@ public class Schema35 extends Schema { } private void createAvatar(JdbcTemplate template, String avatar) { - if (template.queryForInt("select count(*) from system_avatar where name = ?", new Object[]{avatar}) == 0) { + if (template.queryForObject("select count(*) from system_avatar where name = ?", new Object[]{avatar},Integer.class) == 0) { InputStream in = null; try { diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema36.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema36.java index 2c763a77..03c71a7b 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema36.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema36.java @@ -37,7 +37,7 @@ public class Schema36 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 12") == 0) { + if (template.queryForObject("select count(*) from version where version = 12",Integer.class) == 0) { LOG.info("Updating database schema to version 12."); template.execute("insert into version values (12)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema37.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema37.java index 25fd2fe4..7d29d7d6 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema37.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema37.java @@ -37,19 +37,19 @@ public class Schema37 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 13") == 0) { + if (template.queryForObject("select count(*) from version where version = 13",Integer.class) == 0) { LOG.info("Updating database schema to version 13."); template.execute("insert into version values (13)"); } - if (template.queryForInt("select count(*) from role where id = 9") == 0) { + if (template.queryForObject("select count(*) from role where id = 9",Integer.class) == 0) { LOG.info("Role 'settings' not found in database. Creating it."); template.execute("insert into role values (9, 'settings')"); template.execute("insert into user_role select distinct u.username, 9 from user u"); LOG.info("Role 'settings' was created successfully."); } - if (template.queryForInt("select count(*) from role where id = 10") == 0) { + if (template.queryForObject("select count(*) from role where id = 10",Integer.class) == 0) { LOG.info("Role 'jukebox' not found in database. Creating it."); template.execute("insert into role values (10, 'jukebox')"); template.execute("insert into user_role " + diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema38.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema38.java index a2b4a389..a3fdd4d6 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema38.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema38.java @@ -37,7 +37,7 @@ public class Schema38 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 14") == 0) { + if (template.queryForObject("select count(*) from version where version = 14",Integer.class) == 0) { LOG.info("Updating database schema to version 14."); template.execute("insert into version values (14)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema40.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema40.java index 73c65737..4beaa679 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema40.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema40.java @@ -37,7 +37,7 @@ public class Schema40 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 15") == 0) { + if (template.queryForObject("select count(*) from version where version = 15",Integer.class) == 0) { LOG.info("Updating database schema to version 15."); template.execute("insert into version values (15)"); diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema43.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema43.java index 5af5726d..a0422784 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema43.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema43.java @@ -40,12 +40,12 @@ public class Schema43 extends Schema { public void execute(JdbcTemplate template) { // version 16 was used for 4.3.beta1 - if (template.queryForInt("select count(*) from version where version = 16") == 0) { + if (template.queryForObject("select count(*) from version where version = 16",Integer.class) == 0) { LOG.info("Updating database schema to version 16."); template.execute("insert into version values (16)"); } - if (template.queryForInt("select count(*) from version where version = 17") == 0) { + if (template.queryForObject("select count(*) from version where version = 17",Integer.class) == 0) { LOG.info("Updating database schema to version 17."); template.execute("insert into version values (17)"); diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema45.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema45.java index 72cdae1f..e03568ce 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema45.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema45.java @@ -37,12 +37,12 @@ public class Schema45 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 18") == 0) { + if (template.queryForObject("select count(*) from version where version = 18",Integer.class) == 0) { LOG.info("Updating database schema to version 18."); template.execute("insert into version values (18)"); } - if (template.queryForInt("select count(*) from role where id = 11") == 0) { + if (template.queryForObject("select count(*) from role where id = 11",Integer.class) == 0) { LOG.info("Role 'share' not found in database. Creating it."); template.execute("insert into role values (11, 'share')"); template.execute("insert into user_role " + diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema46.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema46.java index cd002ed2..814467e5 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema46.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema46.java @@ -37,7 +37,7 @@ public class Schema46 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 19") == 0) { + if (template.queryForObject("select count(*) from version where version = 19",Integer.class) == 0) { LOG.info("Updating database schema to version 19."); template.execute("insert into version values (19)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema47.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema47.java index 09503566..cb23d28b 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema47.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema47.java @@ -37,7 +37,7 @@ public class Schema47 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 20") == 0) { + if (template.queryForObject("select count(*) from version where version = 20",Integer.class) == 0) { LOG.info("Updating database schema to version 20."); template.execute("insert into version values (20)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema49.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema49.java index 8b49511c..59e7b447 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema49.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema49.java @@ -37,7 +37,7 @@ public class Schema49 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 21") == 0) { + if (template.queryForObject("select count(*) from version where version = 21",Integer.class) == 0) { LOG.info("Updating database schema to version 21."); template.execute("insert into version values (21)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema50.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema50.java index 8db91f62..6d3c9f52 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema50.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema50.java @@ -37,7 +37,7 @@ public class Schema50 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 22") == 0) { + if (template.queryForObject("select count(*) from version where version = 22",Integer.class) == 0) { LOG.info("Updating database schema to version 22."); template.execute("insert into version values (22)"); @@ -57,7 +57,7 @@ public class Schema50 extends Schema { } // Added in 5.0.beta2 - if (template.queryForInt("select count(*) from version where version = 23") == 0) { + if (template.queryForObject("select count(*) from version where version = 23",Integer.class) == 0) { LOG.info("Updating database schema to version 23."); template.execute("insert into version values (23)"); template.execute("update transcoding2 set step1='ffmpeg -i %s -map 0:0 -b:a %bk -v 0 -f mp3 -' where name='mp3 audio'"); diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema51.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema51.java index cccd762d..4285d147 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema51.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema51.java @@ -36,7 +36,7 @@ public class Schema51 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 23") == 0) { + if (template.queryForObject("select count(*) from version where version = 23",Integer.class) == 0) { LOG.info("Updating database schema to version 23."); template.execute("insert into version values (23)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema52.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema52.java index 2853c256..a0c33dec 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema52.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema52.java @@ -36,7 +36,7 @@ public class Schema52 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 24") == 0) { + if (template.queryForObject("select count(*) from version where version = 24",Integer.class) == 0) { LOG.info("Updating database schema to version 24."); template.execute("insert into version values (24)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema53.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema53.java index 9ebead30..caccee78 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema53.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema53.java @@ -38,7 +38,7 @@ public class Schema53 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 25") == 0) { + if (template.queryForObject("select count(*) from version where version = 25",Integer.class) == 0) { LOG.info("Updating database schema to version 25."); template.execute("insert into version values (25)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema61.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema61.java index 378d11c3..cf61876a 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema61.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema61.java @@ -34,7 +34,7 @@ public class Schema61 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 26") == 0) { + if (template.queryForObject("select count(*) from version where version = 26",Integer.class) == 0) { LOG.info("Updating database schema to version 26."); template.execute("insert into version values (26)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema62.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema62.java index 0e945944..a8a5fb0c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema62.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema62.java @@ -34,7 +34,7 @@ public class Schema62 extends Schema { @Override public void execute(JdbcTemplate template) { - if (template.queryForInt("select count(*) from version where version = 27") == 0) { + if (template.queryForObject("select count(*) from version where version = 27",Integer.class) == 0) { LOG.info("Updating database schema to version 27."); template.execute("insert into version values (27)"); } diff --git a/libresonic-main/src/main/java/org/libresonic/player/validator/PasswordSettingsValidator.java b/libresonic-main/src/main/java/org/libresonic/player/validator/PasswordSettingsValidator.java deleted file mode 100644 index 44b5260e..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/validator/PasswordSettingsValidator.java +++ /dev/null @@ -1,46 +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.validator; - -import org.springframework.validation.*; -import org.libresonic.player.command.*; -import org.libresonic.player.controller.*; - -/** - * Validator for {@link PasswordSettingsController}. - * - * @author Sindre Mehus - */ -public class PasswordSettingsValidator implements Validator { - - public boolean supports(Class clazz) { - return clazz.equals(PasswordSettingsCommand.class); - } - - public void validate(Object obj, Errors errors) { - PasswordSettingsCommand command = (PasswordSettingsCommand) obj; - - if (command.getPassword() == null || command.getPassword().length() == 0) { - errors.rejectValue("password", "usersettings.nopassword"); - } else if (!command.getPassword().equals(command.getConfirmPassword())) { - errors.rejectValue("password", "usersettings.wrongpassword"); - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/validator/PremiumSettingsValidator.java b/libresonic-main/src/main/java/org/libresonic/player/validator/PremiumSettingsValidator.java deleted file mode 100644 index e4a2438b..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/validator/PremiumSettingsValidator.java +++ /dev/null @@ -1,53 +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.validator; - -import org.springframework.validation.Errors; -import org.springframework.validation.Validator; - -import org.libresonic.player.command.PremiumSettingsCommand; -import org.libresonic.player.controller.PremiumSettingsController; -import org.libresonic.player.service.SettingsService; - -/** - * Validator for {@link PremiumSettingsController}. - * - * @author Sindre Mehus - */ -public class PremiumSettingsValidator implements Validator { - private SettingsService settingsService; - - public boolean supports(Class clazz) { - return clazz.equals(PremiumSettingsCommand.class); - } - - public void validate(Object obj, Errors errors) { - PremiumSettingsCommand command = (PremiumSettingsCommand) obj; - - if (!settingsService.isLicenseValid(command.getLicenseInfo().getLicenseEmail(), command.getLicenseCode())) { - command.setSubmissionError(true); - errors.rejectValue("licenseCode", "premium.invalidlicense"); - } - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } -} diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml index c9dc232d..e8fe29a1 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-security.xml @@ -3,9 +3,9 @@ xmlns:security="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security - http://www.springframework.org/schema/security/spring-security-3.2.xsd"> + http://www.springframework.org/schema/security/spring-security.xsd"> diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index 835583ba..2a8fd8cc 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -196,14 +196,6 @@ - - - - - - - - @@ -286,14 +278,6 @@ - - - - - - - - @@ -344,10 +328,6 @@ - - - - @@ -390,8 +370,6 @@ transcodingSettingsController internetRadioSettingsController avatarUploadController - passwordSettingsController - premiumSettingsController allmusicController homeController editTagsController diff --git a/libresonic-main/src/test/java/org/libresonic/player/TestCaseUtils.java b/libresonic-main/src/test/java/org/libresonic/player/TestCaseUtils.java index f6ac5d45..8be3071a 100644 --- a/libresonic-main/src/test/java/org/libresonic/player/TestCaseUtils.java +++ b/libresonic-main/src/test/java/org/libresonic/player/TestCaseUtils.java @@ -88,7 +88,7 @@ public class TestCaseUtils { * @return */ public static Integer recordsInTable(String tableName, DaoHelper daoHelper) { - return daoHelper.getJdbcTemplate().queryForInt("select count(1) from " + tableName); + return daoHelper.getJdbcTemplate().queryForObject("select count(1) from " + tableName,Integer.class); } diff --git a/pom.xml b/pom.xml index 31b9a1da..aea990cd 100644 --- a/pom.xml +++ b/pom.xml @@ -16,8 +16,8 @@ true iso-8859-1 - 2.4.2 - 3.2.17.RELEASE + 3.1.8 + 4.3.4.RELEASE 3.2.9.RELEASE @@ -230,7 +230,6 @@ - From 5ae6f5462aba839914504646218c0f46b8299ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 11 Dec 2016 22:23:22 +0100 Subject: [PATCH 26/27] Clean up dependencies --- libresonic-main/pom.xml | 41 ++----------------- .../org/libresonic/player/TestServer.java | 20 --------- 2 files changed, 4 insertions(+), 57 deletions(-) delete mode 100644 libresonic-main/src/main/java/org/libresonic/player/TestServer.java diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 95dabbaf..9d7c92f4 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -18,34 +18,6 @@ - - - org.mortbay.jetty - jetty - 6.1.5 - - - - org.mortbay.jetty - jetty-embedded - 6.1.5 - - - javax.servlet.jsp - jsp-api - - - - - - org.mortbay.jetty - jsp-2.0 - 6.1.5 - pom - - - - org.libresonic.player libresonic-rest-api @@ -360,33 +332,28 @@ org.apache.cxf - cxf-rt-frontend-jaxws + cxf-core ${cxf.version} org.apache.cxf - cxf-rt-bindings-soap + cxf-rt-frontend-jaxws ${cxf.version} org.apache.cxf - cxf-rt-databinding-jaxb + cxf-rt-bindings-soap ${cxf.version} org.apache.cxf - cxf-api + cxf-rt-databinding-jaxb ${cxf.version} - - org.apache.cxf - cxf-common-utilities - ${cxf.version} - diff --git a/libresonic-main/src/main/java/org/libresonic/player/TestServer.java b/libresonic-main/src/main/java/org/libresonic/player/TestServer.java deleted file mode 100644 index eab79fb8..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/TestServer.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.libresonic.player; - -import org.mortbay.jetty.Server; -import org.mortbay.jetty.webapp.WebAppContext; - -public class TestServer { - - public static void main(String[] args) throws Exception { - Server server = new Server(8080); - WebAppContext webapp = new WebAppContext(); - webapp.setContextPath("/libresonic"); - String baseDir = TestServer.class.getResource("/" + TestServer.class.getName().replaceAll("\\.", "/") + ".class").getFile(); - baseDir = baseDir.substring(0,baseDir.indexOf("/target")); - webapp.setWar(baseDir + "/src/main/webapp"); - server.setHandler(webapp); - server.setAttribute("reload", "automatic"); - server.start(); - server.join(); - } -} \ No newline at end of file From 8cc6ab95fd67763dd1a8e85b7ef0cd761977b355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Mon, 12 Dec 2016 21:37:42 +0100 Subject: [PATCH 27/27] Change version number to 6.2.beta1.spring4 --- libresonic-assembly/pom.xml | 2 +- libresonic-booter/pom.xml | 2 +- libresonic-installer-debian/pom.xml | 2 +- libresonic-installer-mac/pom.xml | 2 +- libresonic-installer-rpm/pom.xml | 2 +- libresonic-installer-windows/pom.xml | 2 +- libresonic-main/pom.xml | 2 +- libresonic-rest-api/pom.xml | 2 +- libresonic-sonos-api/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libresonic-assembly/pom.xml b/libresonic-assembly/pom.xml index 97ba9468..d77e8e89 100644 --- a/libresonic-assembly/pom.xml +++ b/libresonic-assembly/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.spring4-SNAPSHOT + 6.2.beta1.spring4 diff --git a/libresonic-booter/pom.xml b/libresonic-booter/pom.xml index 8c19afde..8831c500 100644 --- a/libresonic-booter/pom.xml +++ b/libresonic-booter/pom.xml @@ -8,7 +8,7 @@ org.libresonic.player libresonic - 6.2.spring4-SNAPSHOT + 6.2.beta1.spring4 diff --git a/libresonic-installer-debian/pom.xml b/libresonic-installer-debian/pom.xml index 915e2ca5..39baa5f9 100644 --- a/libresonic-installer-debian/pom.xml +++ b/libresonic-installer-debian/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.spring4-SNAPSHOT + 6.2.beta1.spring4 diff --git a/libresonic-installer-mac/pom.xml b/libresonic-installer-mac/pom.xml index 7095aa86..a20abb07 100644 --- a/libresonic-installer-mac/pom.xml +++ b/libresonic-installer-mac/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.spring4-SNAPSHOT + 6.2.beta1.spring4 diff --git a/libresonic-installer-rpm/pom.xml b/libresonic-installer-rpm/pom.xml index ef68ab1d..794d29b3 100644 --- a/libresonic-installer-rpm/pom.xml +++ b/libresonic-installer-rpm/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.spring4-SNAPSHOT + 6.2.beta1.spring4 diff --git a/libresonic-installer-windows/pom.xml b/libresonic-installer-windows/pom.xml index a49724f1..b213a361 100644 --- a/libresonic-installer-windows/pom.xml +++ b/libresonic-installer-windows/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.spring4-SNAPSHOT + 6.2.beta1.spring4 diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 9d7c92f4..f95c6716 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -9,7 +9,7 @@ org.libresonic.player libresonic - 6.2.spring4-SNAPSHOT + 6.2.beta1.spring4 diff --git a/libresonic-rest-api/pom.xml b/libresonic-rest-api/pom.xml index 420ba6c7..e95a1a8d 100644 --- a/libresonic-rest-api/pom.xml +++ b/libresonic-rest-api/pom.xml @@ -8,7 +8,7 @@ org.libresonic.player libresonic - 6.2.spring4-SNAPSHOT + 6.2.beta1.spring4 diff --git a/libresonic-sonos-api/pom.xml b/libresonic-sonos-api/pom.xml index 61daab0a..1012b990 100644 --- a/libresonic-sonos-api/pom.xml +++ b/libresonic-sonos-api/pom.xml @@ -8,7 +8,7 @@ org.libresonic.player libresonic - 6.2.spring4-SNAPSHOT + 6.2.beta1.spring4 diff --git a/pom.xml b/pom.xml index aea990cd..1070b1e4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.libresonic.player libresonic - 6.2.spring4-SNAPSHOT + 6.2.beta1.spring4 Libresonic pom