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);
}
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);
}
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);
}
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"));
}
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());
}
Aggregations