Search in sources :

Example 16 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class RESTController method changePassword.

@RequestMapping(value = "/rest/changePassword", method = { RequestMethod.GET, RequestMethod.POST })
public void changePassword(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = getRequiredStringParameter(request, "username");
    String password = decrypt(getRequiredStringParameter(request, "password"));
    User authUser = securityService.getCurrentUser(request);
    boolean allowed = authUser.isAdminRole() || username.equals(authUser.getUsername()) && authUser.isSettingsRole();
    if (!allowed) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, authUser.getUsername() + " is not authorized to change password for " + username);
        return;
    }
    User user = securityService.getUserByName(username);
    user.setPassword(password);
    securityService.updateUser(user);
    writeEmptyResponse(request, response);
}
Also used : User(org.libresonic.player.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class RESTController method deleteUser.

@RequestMapping(value = "/rest/deleteUser", method = { RequestMethod.GET, RequestMethod.POST })
public void deleteUser(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 delete users.");
        return;
    }
    String username = getRequiredStringParameter(request, "username");
    if (User.USERNAME_ADMIN.equals(username)) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, "Not allowed to delete admin user");
        return;
    }
    securityService.deleteUser(username);
    writeEmptyResponse(request, response);
}
Also used : User(org.libresonic.player.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class RESTController method getUser.

@RequestMapping(value = "/rest/getUser", method = { RequestMethod.GET, RequestMethod.POST })
public void getUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = getRequiredStringParameter(request, "username");
    User currentUser = securityService.getCurrentUser(request);
    if (!username.equals(currentUser.getUsername()) && !currentUser.isAdminRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, currentUser.getUsername() + " is not authorized to get details for other users.");
        return;
    }
    User requestedUser = securityService.getUserByName(username);
    if (requestedUser == null) {
        error(request, response, ErrorCode.NOT_FOUND, "No such user: " + username);
        return;
    }
    Response res = createResponse();
    res.setUser(createJaxbUser(requestedUser));
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) User(org.libresonic.player.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class UserDaoTestCase method testUserSettings.

@Test
public void testUserSettings() {
    assertNull("Error in getUserSettings.", userDao.getUserSettings("sindre"));
    try {
        userDao.updateUserSettings(new UserSettings("sindre"));
        fail("Expected DataIntegrityViolationException.");
    } catch (DataIntegrityViolationException x) {
    }
    userDao.createUser(new User("sindre", "secret", null));
    assertNull("Error in getUserSettings.", userDao.getUserSettings("sindre"));
    userDao.updateUserSettings(new UserSettings("sindre"));
    UserSettings userSettings = userDao.getUserSettings("sindre");
    assertNotNull("Error in getUserSettings().", userSettings);
    assertNull("Error in getUserSettings().", userSettings.getLocale());
    assertNull("Error in getUserSettings().", userSettings.getThemeId());
    assertFalse("Error in getUserSettings().", userSettings.isFinalVersionNotificationEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isBetaVersionNotificationEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isSongNotificationEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isShowSideBar());
    assertFalse("Error in getUserSettings().", userSettings.isLastFmEnabled());
    assertNull("Error in getUserSettings().", userSettings.getLastFmUsername());
    assertNull("Error in getUserSettings().", userSettings.getLastFmPassword());
    assertSame("Error in getUserSettings().", TranscodeScheme.OFF, userSettings.getTranscodeScheme());
    assertFalse("Error in getUserSettings().", userSettings.isShowNowPlayingEnabled());
    assertEquals("Error in getUserSettings().", -1, userSettings.getSelectedMusicFolderId());
    assertFalse("Error in getUserSettings().", userSettings.isPartyModeEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isNowPlayingAllowed());
    assertSame("Error in getUserSettings().", AvatarScheme.NONE, userSettings.getAvatarScheme());
    assertNull("Error in getUserSettings().", userSettings.getSystemAvatarId());
    assertEquals("Error in getUserSettings().", 0, userSettings.getListReloadDelay());
    assertFalse("Error in getUserSettings().", userSettings.isKeyboardShortcutsEnabled());
    assertEquals("Error in getUserSettings().", 0, userSettings.getPaginationSize());
    UserSettings settings = new UserSettings("sindre");
    settings.setLocale(Locale.SIMPLIFIED_CHINESE);
    settings.setThemeId("midnight");
    settings.setBetaVersionNotificationEnabled(true);
    settings.setSongNotificationEnabled(false);
    settings.setShowSideBar(true);
    settings.getMainVisibility().setBitRateVisible(true);
    settings.getPlaylistVisibility().setYearVisible(true);
    settings.setLastFmEnabled(true);
    settings.setLastFmUsername("last_user");
    settings.setLastFmPassword("last_pass");
    settings.setTranscodeScheme(TranscodeScheme.MAX_192);
    settings.setShowNowPlayingEnabled(false);
    settings.setSelectedMusicFolderId(3);
    settings.setPartyModeEnabled(true);
    settings.setNowPlayingAllowed(true);
    settings.setAvatarScheme(AvatarScheme.SYSTEM);
    settings.setSystemAvatarId(1);
    settings.setChanged(new Date(9412L));
    settings.setListReloadDelay(60);
    settings.setKeyboardShortcutsEnabled(true);
    settings.setPaginationSize(120);
    userDao.updateUserSettings(settings);
    userSettings = userDao.getUserSettings("sindre");
    assertNotNull("Error in getUserSettings().", userSettings);
    assertEquals("Error in getUserSettings().", Locale.SIMPLIFIED_CHINESE, userSettings.getLocale());
    assertEquals("Error in getUserSettings().", false, userSettings.isFinalVersionNotificationEnabled());
    assertEquals("Error in getUserSettings().", true, userSettings.isBetaVersionNotificationEnabled());
    assertEquals("Error in getUserSettings().", false, userSettings.isSongNotificationEnabled());
    assertEquals("Error in getUserSettings().", true, userSettings.isShowSideBar());
    assertEquals("Error in getUserSettings().", "midnight", userSettings.getThemeId());
    assertEquals("Error in getUserSettings().", true, userSettings.getMainVisibility().isBitRateVisible());
    assertEquals("Error in getUserSettings().", true, userSettings.getPlaylistVisibility().isYearVisible());
    assertEquals("Error in getUserSettings().", true, userSettings.isLastFmEnabled());
    assertEquals("Error in getUserSettings().", "last_user", userSettings.getLastFmUsername());
    assertEquals("Error in getUserSettings().", "last_pass", userSettings.getLastFmPassword());
    assertSame("Error in getUserSettings().", TranscodeScheme.MAX_192, userSettings.getTranscodeScheme());
    assertFalse("Error in getUserSettings().", userSettings.isShowNowPlayingEnabled());
    assertEquals("Error in getUserSettings().", 3, userSettings.getSelectedMusicFolderId());
    assertTrue("Error in getUserSettings().", userSettings.isPartyModeEnabled());
    assertTrue("Error in getUserSettings().", userSettings.isNowPlayingAllowed());
    assertSame("Error in getUserSettings().", AvatarScheme.SYSTEM, userSettings.getAvatarScheme());
    assertEquals("Error in getUserSettings().", 1, userSettings.getSystemAvatarId().intValue());
    assertEquals("Error in getUserSettings().", new Date(9412L), userSettings.getChanged());
    assertEquals("Error in getUserSettings().", 60, userSettings.getListReloadDelay());
    assertTrue("Error in getUserSettings().", userSettings.isKeyboardShortcutsEnabled());
    assertEquals("Error in getUserSettings().", 120, userSettings.getPaginationSize());
    userDao.deleteUser("sindre");
    assertNull("Error in cascading delete.", userDao.getUserSettings("sindre"));
}
Also used : User(org.libresonic.player.domain.User) UserSettings(org.libresonic.player.domain.UserSettings) Date(java.util.Date) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 20 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class UserDaoTestCase method testCreateUserTransactionalError.

@Test
public void testCreateUserTransactionalError() {
    User user = new User("muff1nman", "secret", "noemail") {

        @Override
        public boolean isPlaylistRole() {
            throw new RuntimeException();
        }
    };
    user.setAdminRole(true);
    int beforeSize = userDao.getAllUsers().size();
    boolean caughtException = false;
    try {
        userDao.createUser(user);
    } catch (RuntimeException e) {
        caughtException = true;
    }
    assertTrue("It was expected for createUser to throw an exception", caughtException);
    assertEquals(beforeSize, userDao.getAllUsers().size());
}
Also used : User(org.libresonic.player.domain.User) Test(org.junit.Test)

Aggregations

User (org.libresonic.player.domain.User)52 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)33 ModelAndView (org.springframework.web.servlet.ModelAndView)10 HashMap (java.util.HashMap)8 Test (org.junit.Test)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 Share (org.libresonic.player.domain.Share)6 UserSettings (org.libresonic.player.domain.UserSettings)6 MusicFolder (org.libresonic.player.domain.MusicFolder)5 Player (org.libresonic.player.domain.Player)4 UserSettingsCommand (org.libresonic.player.command.UserSettingsCommand)3 Playlist (org.libresonic.player.domain.Playlist)3 org.libresonic.restapi (org.libresonic.restapi)3 RedirectView (org.springframework.web.servlet.view.RedirectView)3 File (java.io.File)2 Date (java.util.Date)2 MediaFile (org.libresonic.player.domain.MediaFile)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 LinkedHashMap (java.util.LinkedHashMap)1 ReCaptcha (net.tanesha.recaptcha.ReCaptcha)1