check for nulls before querying the database

This commit is contained in:
Athou
2013-04-23 09:06:35 +02:00
parent 64747881de
commit 92e76d469f
2 changed files with 7 additions and 2 deletions

View File

@@ -1,13 +1,11 @@
package com.commafeed.backend.feeds;
import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.SystemUtils;
import org.xml.sax.InputSource;

View File

@@ -10,6 +10,7 @@ import com.commafeed.backend.dao.UserDAO;
import com.commafeed.backend.model.User;
import com.commafeed.backend.model.UserRole;
import com.commafeed.backend.model.UserRole.Role;
import com.google.common.base.Preconditions;
@Stateless
public class UserService {
@@ -21,6 +22,9 @@ public class UserService {
PasswordEncryptionService encryptionService;
public User login(String name, String password) {
Preconditions.checkNotNull(name);
Preconditions.checkNotNull(password);
User user = userDAO.findByName(name);
if (user != null && !user.isDisabled()) {
boolean authenticated = encryptionService.authenticate(password,
@@ -41,6 +45,9 @@ public class UserService {
public User register(String name, String password, String email,
Collection<Role> roles) {
Preconditions.checkNotNull(name);
Preconditions.checkNotNull(password);
if (userDAO.findByName(name) != null) {
return null;
}