Java Code Examples for org.springframework.web.bind.ServletRequestUtils#getIntParameters()

The following examples show how to use org.springframework.web.bind.ServletRequestUtils#getIntParameters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubsonicRESTController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping("/createUser")
public void createUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    org.airsonic.player.domain.User user = securityService.getCurrentUser(request);
    if (!user.isAdminRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to create new users.");
        return;
    }

    UserSettingsCommand command = new UserSettingsCommand();
    command.setUsername(getRequiredStringParameter(request, "username"));
    command.setPassword(decrypt(getRequiredStringParameter(request, "password")));
    command.setEmail(getRequiredStringParameter(request, "email"));
    command.setLdapAuthenticated(getBooleanParameter(request, "ldapAuthenticated", false));
    command.setAdminRole(getBooleanParameter(request, "adminRole", false));
    command.setCommentRole(getBooleanParameter(request, "commentRole", false));
    command.setCoverArtRole(getBooleanParameter(request, "coverArtRole", false));
    command.setDownloadRole(getBooleanParameter(request, "downloadRole", false));
    command.setStreamRole(getBooleanParameter(request, "streamRole", true));
    command.setUploadRole(getBooleanParameter(request, "uploadRole", false));
    command.setJukeboxRole(getBooleanParameter(request, "jukeboxRole", false));
    command.setPodcastRole(getBooleanParameter(request, "podcastRole", false));
    command.setSettingsRole(getBooleanParameter(request, "settingsRole", true));
    command.setShareRole(getBooleanParameter(request, "shareRole", false));
    command.setTranscodeSchemeName(TranscodeScheme.OFF.name());

    int[] folderIds = ServletRequestUtils.getIntParameters(request, "musicFolderId");
    if (folderIds.length == 0) {
        folderIds = Util.toIntArray(org.airsonic.player.domain.MusicFolder.toIdList(settingsService.getAllMusicFolders()));
    }
    command.setAllowedMusicFolderIds(folderIds);

    userSettingsController.createUser(command);
    writeEmptyResponse(request, response);
}
 
Example 2
Source File: ShareManagementController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
private List<MediaFile> getMediaFiles(HttpServletRequest request) throws Exception {
    Integer id = ServletRequestUtils.getIntParameter(request, "id");
    Integer playerId = ServletRequestUtils.getIntParameter(request, "player");
    Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist");

    List<MediaFile> result = new ArrayList<>();

    if (id != null) {
        MediaFile album = mediaFileService.getMediaFile(id);
        int[] indexes = ServletRequestUtils.getIntParameters(request, "i");
        if (indexes.length == 0) {
            return Arrays.asList(album);
        }
        List<MediaFile> children = mediaFileService.getChildrenOf(album, true, false, true);
        for (int index : indexes) {
            result.add(children.get(index));
        }
    } else if (playerId != null) {
        Player player = playerService.getPlayerById(playerId);
        PlayQueue playQueue = player.getPlayQueue();
        result = playQueue.getFiles();
    } else if (playlistId != null) {
        result = playlistService.getFilesInPlaylist(playlistId);
    }

    return result;
}
 
Example 3
Source File: SubsonicRESTController.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping("/createUser")
public void createUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    org.airsonic.player.domain.User user = securityService.getCurrentUser(request);
    if (!user.isAdminRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to create new users.");
        return;
    }

    UserSettingsCommand command = new UserSettingsCommand();
    command.setUsername(getRequiredStringParameter(request, "username"));
    command.setPassword(decrypt(getRequiredStringParameter(request, "password")));
    command.setEmail(getRequiredStringParameter(request, "email"));
    command.setLdapAuthenticated(getBooleanParameter(request, "ldapAuthenticated", false));
    command.setAdminRole(getBooleanParameter(request, "adminRole", false));
    command.setCommentRole(getBooleanParameter(request, "commentRole", false));
    command.setCoverArtRole(getBooleanParameter(request, "coverArtRole", false));
    command.setDownloadRole(getBooleanParameter(request, "downloadRole", false));
    command.setStreamRole(getBooleanParameter(request, "streamRole", true));
    command.setUploadRole(getBooleanParameter(request, "uploadRole", false));
    command.setJukeboxRole(getBooleanParameter(request, "jukeboxRole", false));
    command.setPodcastRole(getBooleanParameter(request, "podcastRole", false));
    command.setSettingsRole(getBooleanParameter(request, "settingsRole", true));
    command.setShareRole(getBooleanParameter(request, "shareRole", false));
    command.setTranscodeSchemeName(TranscodeScheme.OFF.name());

    int[] folderIds = ServletRequestUtils.getIntParameters(request, "musicFolderId");
    if (folderIds.length == 0) {
        folderIds = Util.toIntArray(org.airsonic.player.domain.MusicFolder.toIdList(settingsService.getAllMusicFolders()));
    }
    command.setAllowedMusicFolderIds(folderIds);

    userSettingsController.createUser(command);
    writeEmptyResponse(request, response);
}
 
Example 4
Source File: ShareManagementController.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
private List<MediaFile> getMediaFiles(HttpServletRequest request) throws Exception {
    Integer id = ServletRequestUtils.getIntParameter(request, "id");
    Integer playerId = ServletRequestUtils.getIntParameter(request, "player");
    Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist");

    List<MediaFile> result = new ArrayList<>();

    if (id != null) {
        MediaFile album = mediaFileService.getMediaFile(id);
        int[] indexes = ServletRequestUtils.getIntParameters(request, "i");
        if (indexes.length == 0) {
            return Arrays.asList(album);
        }
        List<MediaFile> children = mediaFileService.getChildrenOf(album, true, false, true);
        for (int index : indexes) {
            result.add(children.get(index));
        }
    } else if (playerId != null) {
        Player player = playerService.getPlayerById(playerId);
        PlayQueue playQueue = player.getPlayQueue();
        result = playQueue.getFiles();
    } else if (playlistId != null) {
        result = playlistService.getFilesInPlaylist(playlistId);
    }

    return result;
}
 
Example 5
Source File: RESTController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
public void createUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    User user = securityService.getCurrentUser(request);
    if (!user.isAdminRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to create new users.");
        return;
    }

    UserSettingsCommand command = new UserSettingsCommand();
    command.setUsername(getRequiredStringParameter(request, "username"));
    command.setPassword(decrypt(getRequiredStringParameter(request, "password")));
    command.setEmail(getRequiredStringParameter(request, "email"));
    command.setLdapAuthenticated(getBooleanParameter(request, "ldapAuthenticated", false));
    command.setAdminRole(getBooleanParameter(request, "adminRole", false));
    command.setCommentRole(getBooleanParameter(request, "commentRole", false));
    command.setCoverArtRole(getBooleanParameter(request, "coverArtRole", false));
    command.setDownloadRole(getBooleanParameter(request, "downloadRole", false));
    command.setStreamRole(getBooleanParameter(request, "streamRole", true));
    command.setUploadRole(getBooleanParameter(request, "uploadRole", false));
    command.setJukeboxRole(getBooleanParameter(request, "jukeboxRole", false));
    command.setPodcastRole(getBooleanParameter(request, "podcastRole", false));
    command.setSettingsRole(getBooleanParameter(request, "settingsRole", true));
    command.setShareRole(getBooleanParameter(request, "shareRole", false));
    command.setTranscodeSchemeName(TranscodeScheme.OFF.name());

    int[] folderIds = ServletRequestUtils.getIntParameters(request, "musicFolderId");
    if (folderIds.length == 0) {
        folderIds = Util.toIntArray(MusicFolder.toIdList(settingsService.getAllMusicFolders()));
    }
    command.setAllowedMusicFolderIds(folderIds);

    userSettingsController.createUser(command);
    writeEmptyResponse(request, response);
}
 
Example 6
Source File: ShareManagementController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
private List<MediaFile> getMediaFiles(HttpServletRequest request) throws Exception {
    Integer id = ServletRequestUtils.getIntParameter(request, "id");
    String playerId = request.getParameter("player");
    Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist");

    List<MediaFile> result = new ArrayList<MediaFile>();

    if (id != null) {
        MediaFile album = mediaFileService.getMediaFile(id);
        int[] indexes = ServletRequestUtils.getIntParameters(request, "i");
        if (indexes.length == 0) {
            return Arrays.asList(album);
        }
        List<MediaFile> children = mediaFileService.getChildrenOf(album, true, false, true);
        for (int index : indexes) {
            result.add(children.get(index));
        }
    }

    else if (playerId != null) {
        Player player = playerService.getPlayerById(playerId);
        PlayQueue playQueue = player.getPlayQueue();
        result = playQueue.getFiles();
    }

    else if (playlistId != null) {
        result = playlistService.getFilesInPlaylist(playlistId);
    }

    return result;
}
 
Example 7
Source File: SubsonicRESTController.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
@RequestMapping("/updateUser")
public void updateUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    org.airsonic.player.domain.User user = securityService.getCurrentUser(request);
    if (!user.isAdminRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to update users.");
        return;
    }

    String username = getRequiredStringParameter(request, "username");
    org.airsonic.player.domain.User u = securityService.getUserByName(username);
    UserSettings s = settingsService.getUserSettings(username);

    if (u == null) {
        error(request, response, ErrorCode.NOT_FOUND, "No such user: " + username);
        return;
    } else if (org.airsonic.player.domain.User.USERNAME_ADMIN.equals(username)) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, "Not allowed to change admin user");
        return;
    }

    UserSettingsCommand command = new UserSettingsCommand();
    command.setUsername(username);
    command.setEmail(getStringParameter(request, "email", u.getEmail()));
    command.setLdapAuthenticated(getBooleanParameter(request, "ldapAuthenticated", u.isLdapAuthenticated()));
    command.setAdminRole(getBooleanParameter(request, "adminRole", u.isAdminRole()));
    command.setCommentRole(getBooleanParameter(request, "commentRole", u.isCommentRole()));
    command.setCoverArtRole(getBooleanParameter(request, "coverArtRole", u.isCoverArtRole()));
    command.setDownloadRole(getBooleanParameter(request, "downloadRole", u.isDownloadRole()));
    command.setStreamRole(getBooleanParameter(request, "streamRole", u.isDownloadRole()));
    command.setUploadRole(getBooleanParameter(request, "uploadRole", u.isUploadRole()));
    command.setJukeboxRole(getBooleanParameter(request, "jukeboxRole", u.isJukeboxRole()));
    command.setPodcastRole(getBooleanParameter(request, "podcastRole", u.isPodcastRole()));
    command.setSettingsRole(getBooleanParameter(request, "settingsRole", u.isSettingsRole()));
    command.setShareRole(getBooleanParameter(request, "shareRole", u.isShareRole()));

    int maxBitRate = getIntParameter(request, "maxBitRate", s.getTranscodeScheme().getMaxBitRate());
    command.setTranscodeSchemeName(Optional.ofNullable(TranscodeScheme.fromMaxBitRate(maxBitRate)).map(TranscodeScheme::name).orElse(null));

    if (hasParameter(request, "password")) {
        command.setPassword(decrypt(getRequiredStringParameter(request, "password")));
        command.setPasswordChange(true);
    }

    int[] folderIds = ServletRequestUtils.getIntParameters(request, "musicFolderId");
    if (folderIds.length == 0) {
        folderIds = Util.toIntArray(org.airsonic.player.domain.MusicFolder.toIdList(settingsService.getMusicFoldersForUser(username)));
    }
    command.setAllowedMusicFolderIds(folderIds);

    userSettingsController.updateUser(command);
    writeEmptyResponse(request, response);
}
 
Example 8
Source File: SubsonicRESTController.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
@RequestMapping("/updateUser")
public void updateUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    org.airsonic.player.domain.User user = securityService.getCurrentUser(request);
    if (!user.isAdminRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to update users.");
        return;
    }

    String username = getRequiredStringParameter(request, "username");
    org.airsonic.player.domain.User u = securityService.getUserByName(username);
    UserSettings s = settingsService.getUserSettings(username);

    if (u == null) {
        error(request, response, ErrorCode.NOT_FOUND, "No such user: " + username);
        return;
    } else if (user.getUsername().equals(username)) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, "Not allowed to change own user");
        return;
    } else if (securityService.isAdmin(username)) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, "Not allowed to change admin user");
        return;
    }

    UserSettingsCommand command = new UserSettingsCommand();
    command.setUsername(username);
    command.setEmail(getStringParameter(request, "email", u.getEmail()));
    command.setLdapAuthenticated(getBooleanParameter(request, "ldapAuthenticated", u.isLdapAuthenticated()));
    command.setAdminRole(getBooleanParameter(request, "adminRole", u.isAdminRole()));
    command.setCommentRole(getBooleanParameter(request, "commentRole", u.isCommentRole()));
    command.setCoverArtRole(getBooleanParameter(request, "coverArtRole", u.isCoverArtRole()));
    command.setDownloadRole(getBooleanParameter(request, "downloadRole", u.isDownloadRole()));
    command.setStreamRole(getBooleanParameter(request, "streamRole", u.isDownloadRole()));
    command.setUploadRole(getBooleanParameter(request, "uploadRole", u.isUploadRole()));
    command.setJukeboxRole(getBooleanParameter(request, "jukeboxRole", u.isJukeboxRole()));
    command.setPodcastRole(getBooleanParameter(request, "podcastRole", u.isPodcastRole()));
    command.setSettingsRole(getBooleanParameter(request, "settingsRole", u.isSettingsRole()));
    command.setShareRole(getBooleanParameter(request, "shareRole", u.isShareRole()));

    int maxBitRate = getIntParameter(request, "maxBitRate", s.getTranscodeScheme().getMaxBitRate());
    TranscodeScheme transcodeScheme = TranscodeScheme.fromMaxBitRate(maxBitRate);
    if (transcodeScheme != null) {
        command.setTranscodeSchemeName(transcodeScheme.name());
    }

    if (hasParameter(request, "password")) {
        command.setPassword(decrypt(getRequiredStringParameter(request, "password")));
        command.setPasswordChange(true);
    }

    int[] folderIds = ServletRequestUtils.getIntParameters(request, "musicFolderId");
    if (folderIds.length == 0) {
        folderIds = Util.toIntArray(org.airsonic.player.domain.MusicFolder.toIdList(settingsService.getMusicFoldersForUser(username)));
    }
    command.setAllowedMusicFolderIds(folderIds);

    userSettingsController.updateUser(command);
    writeEmptyResponse(request, response);
}
 
Example 9
Source File: DownloadController.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
@GetMapping
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

    User user = securityService.getCurrentUser(request);
    TransferStatus status = null;
    try {

        status = statusService.createDownloadStatus(playerService.getPlayer(request, response, false, false));

        MediaFile mediaFile = getMediaFile(request);

        Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist");
        Integer playerId = ServletRequestUtils.getIntParameter(request, "player");
        int[] indexes = request.getParameter("i") == null ? null : ServletRequestUtils.getIntParameters(request, "i");

        if (mediaFile != null) {
            response.setIntHeader("ETag", mediaFile.getId());
            response.setHeader("Accept-Ranges", "bytes");
        }

        HttpRange range = HttpRange.valueOf(request.getHeader("Range"));
        if (range != null) {
            response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
            LOG.info("Got HTTP range: " + range);
        }

        if (mediaFile != null) {
            if (!securityService.isFolderAccessAllowed(mediaFile, user.getUsername())) {
                response.sendError(HttpServletResponse.SC_FORBIDDEN,
                        "Access to file " + mediaFile.getId() + " is forbidden for user " + user.getUsername());
                return;
            }

            if (mediaFile.isFile()) {
                downloadFile(response, status, mediaFile.getFile(), range);
            } else {
                List<MediaFile> children = mediaFileService.getChildrenOf(mediaFile, true, false, true);
                String zipFileName = FilenameUtils.getBaseName(mediaFile.getPath()) + ".zip";
                File coverArtFile = indexes == null ? mediaFile.getCoverArtFile() : null;
                downloadFiles(response, status, children, indexes, coverArtFile, range, zipFileName);
            }

        } else if (playlistId != null) {
            List<MediaFile> songs = playlistService.getFilesInPlaylist(playlistId);
            Playlist playlist = playlistService.getPlaylist(playlistId);
            downloadFiles(response, status, songs, null, null, range, playlist.getName() + ".zip");

        } else if (playerId != null) {
            Player player = playerService.getPlayerById(playerId);
            PlayQueue playQueue = player.getPlayQueue();
            playQueue.setName("Playlist");
            downloadFiles(response, status, playQueue.getFiles(), indexes, null, range, "download.zip");
        }

    } finally {
        if (status != null) {
            statusService.removeDownloadStatus(status);
            securityService.updateUserByteCounts(user, 0L, status.getBytesTransfered(), 0L);
        }
    }
}
 
Example 10
Source File: RESTController.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
public void updateUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    User user = securityService.getCurrentUser(request);
    if (!user.isAdminRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to update users.");
        return;
    }

    String username = getRequiredStringParameter(request, "username");
    User u = securityService.getUserByName(username);
    UserSettings s = settingsService.getUserSettings(username);

    if (u == null) {
        error(request, response, ErrorCode.NOT_FOUND, "No such user: " + username);
        return;
    } else if (User.USERNAME_ADMIN.equals(username)) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, "Not allowed to change admin user");
        return;
    }

    UserSettingsCommand command = new UserSettingsCommand();
    command.setUsername(username);
    command.setEmail(getStringParameter(request, "email", u.getEmail()));
    command.setLdapAuthenticated(getBooleanParameter(request, "ldapAuthenticated", u.isLdapAuthenticated()));
    command.setAdminRole(getBooleanParameter(request, "adminRole", u.isAdminRole()));
    command.setCommentRole(getBooleanParameter(request, "commentRole", u.isCommentRole()));
    command.setCoverArtRole(getBooleanParameter(request, "coverArtRole", u.isCoverArtRole()));
    command.setDownloadRole(getBooleanParameter(request, "downloadRole", u.isDownloadRole()));
    command.setStreamRole(getBooleanParameter(request, "streamRole", u.isDownloadRole()));
    command.setUploadRole(getBooleanParameter(request, "uploadRole", u.isUploadRole()));
    command.setJukeboxRole(getBooleanParameter(request, "jukeboxRole", u.isJukeboxRole()));
    command.setPodcastRole(getBooleanParameter(request, "podcastRole", u.isPodcastRole()));
    command.setSettingsRole(getBooleanParameter(request, "settingsRole", u.isSettingsRole()));
    command.setShareRole(getBooleanParameter(request, "shareRole", u.isShareRole()));

    int maxBitRate = getIntParameter(request, "maxBitRate", s.getTranscodeScheme().getMaxBitRate());
    command.setTranscodeSchemeName(TranscodeScheme.fromMaxBitRate(maxBitRate).name());

    if (hasParameter(request, "password")) {
        command.setPassword(decrypt(getRequiredStringParameter(request, "password")));
        command.setPasswordChange(true);
    }

    int[] folderIds = ServletRequestUtils.getIntParameters(request, "musicFolderId");
    if (folderIds.length == 0) {
        folderIds = Util.toIntArray(MusicFolder.toIdList(settingsService.getMusicFoldersForUser(username)));
    }
    command.setAllowedMusicFolderIds(folderIds);

    userSettingsController.updateUser(command);
    writeEmptyResponse(request, response);
}
 
Example 11
Source File: DownloadController.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

        User user = securityService.getCurrentUser(request);
        TransferStatus status = null;
        try {

            status = statusService.createDownloadStatus(playerService.getPlayer(request, response, false, false));

            MediaFile mediaFile = getMediaFile(request);

            Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist");
            String playerId = request.getParameter("player");
            int[] indexes = request.getParameter("i") == null ? null : ServletRequestUtils.getIntParameters(request, "i");

            if (mediaFile != null) {
                response.setIntHeader("ETag", mediaFile.getId());
                response.setHeader("Accept-Ranges", "bytes");
            }

            HttpRange range = HttpRange.valueOf(request.getHeader("Range"));
            if (range != null) {
                response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
                LOG.info("Got HTTP range: " + range);
            }

            if (mediaFile != null) {
                if (!securityService.isFolderAccessAllowed(mediaFile, user.getUsername())) {
                    response.sendError(HttpServletResponse.SC_FORBIDDEN,
                                       "Access to file " + mediaFile.getId() + " is forbidden for user " + user.getUsername());
                    return null;
                }

                if (mediaFile.isFile()) {
                    downloadFile(response, status, mediaFile.getFile(), range);
                } else {
                    List<MediaFile> children = mediaFileService.getChildrenOf(mediaFile, true, false, true);
                    String zipFileName = FilenameUtils.getBaseName(mediaFile.getPath()) + ".zip";
                    File coverArtFile = indexes == null ? mediaFile.getCoverArtFile() : null;
                    downloadFiles(response, status, children, indexes, coverArtFile, range, zipFileName);
                }

            } else if (playlistId != null) {
                List<MediaFile> songs = playlistService.getFilesInPlaylist(playlistId);
                Playlist playlist = playlistService.getPlaylist(playlistId);
                downloadFiles(response, status, songs, null, null, range, playlist.getName() + ".zip");

            } else if (playerId != null) {
                Player player = playerService.getPlayerById(playerId);
                PlayQueue playQueue = player.getPlayQueue();
                playQueue.setName("Playlist");
                downloadFiles(response, status, playQueue.getFiles(), indexes, null, range, "download.zip");
            }

        } finally {
            if (status != null) {
                statusService.removeDownloadStatus(status);
                securityService.updateUserByteCounts(user, 0L, status.getBytesTransfered(), 0L);
            }
        }

        return null;
    }