migrated to slf4j
This commit is contained in:
@ -32,11 +32,6 @@
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
|
||||
@ -17,8 +17,8 @@ import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.transaction.Transactional;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
@ -29,7 +29,7 @@ import org.apache.shiro.subject.Subject;
|
||||
@Stateless
|
||||
public class AccountControl {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(AccountControl.class.getName());
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AccountControl.class.getName());
|
||||
|
||||
@EJB
|
||||
private ConfigService configService;
|
||||
@ -105,7 +105,7 @@ public class AccountControl {
|
||||
account.setRoleEntityList(new ArrayList<>());
|
||||
account.getRoleEntityList().add(role);
|
||||
em.merge(account);
|
||||
LOGGER.log(Level.INFO, "Added role " + roleName + " to user " + account.getUsername());
|
||||
LOGGER.info("Added role " + roleName + " to user " + account.getUsername());
|
||||
|
||||
} else if (!account.getRoleEntityList().get(0).equals(role)) {
|
||||
// change role from User to Admin and vice versa
|
||||
@ -118,11 +118,11 @@ public class AccountControl {
|
||||
account.getRoleEntityList().remove(0);
|
||||
account.getRoleEntityList().add(role);
|
||||
em.merge(account);
|
||||
LOGGER.log(Level.INFO, "Switched role of user " + account.getUsername() + " to " + roleName);
|
||||
LOGGER.info("Switched role of user " + account.getUsername() + " to " + roleName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ public class AccountControl {
|
||||
String currentUserName = currentUser.getPrincipal().toString();
|
||||
|
||||
if (account.getUsername().equals(currentUserName)) {
|
||||
throw new AccountException ("Cannot delete own account");
|
||||
throw new AccountException("Cannot delete own account");
|
||||
} else {
|
||||
account.setStatus("DELETED"); // TODO add enum
|
||||
account.setLastUpdatedBy(currentUserName);
|
||||
@ -146,12 +146,12 @@ public class AccountControl {
|
||||
try {
|
||||
AccountEntity account = getAccountEntity(userName, false);
|
||||
if (account == null) {
|
||||
LOGGER.log(Level.WARN, "Account with name " + userName + " not found");
|
||||
LOGGER.warn("Account with name " + userName + " not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (account.getStatus().equals("LOCKED")) { // TODO add enumType
|
||||
LOGGER.log(Level.WARN, "Account " + userName + " is locked, cannot initialize password reset");
|
||||
LOGGER.warn("Account " + userName + " is locked, cannot initialize password reset");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -169,9 +169,9 @@ public class AccountControl {
|
||||
em.merge(account);
|
||||
return true;
|
||||
} catch (MailException ex) {
|
||||
LOGGER.log(Level.ERROR, "Error while sending password reset mail. " + ex.toString());
|
||||
LOGGER.error("Error while sending password reset mail. " + ex.toString());
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.log(Level.DEBUG, "Error while sending password reset mail.", ex);
|
||||
LOGGER.debug("Error while sending password reset mail.", ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -181,7 +181,7 @@ public class AccountControl {
|
||||
AccountEntity account = getAccountEntity(userName, false);
|
||||
|
||||
if (account == null) {
|
||||
LOGGER.log(Level.WARN, "Error while resetting password, no account with username " + userName + " found");
|
||||
LOGGER.warn("Error while resetting password, no account with username " + userName + " found");
|
||||
// TODO add extra logging for intrusion protection system like fail2ban
|
||||
return false;
|
||||
}
|
||||
@ -193,23 +193,23 @@ public class AccountControl {
|
||||
if (storedHash.equals(resetPasswordToken)) {
|
||||
// everything ok, reset password
|
||||
executePasswordReset(account, newPassword);
|
||||
LOGGER.log(Level.INFO, "Updated password for user " + userName);
|
||||
LOGGER.info("Updated password for user " + userName);
|
||||
return true;
|
||||
} else {
|
||||
// token is not valid, refuse to change password
|
||||
LOGGER.log(Level.WARN, "Trying to reset password for user " + userName + " but wrong token " + resetPasswordToken + " provided");
|
||||
LOGGER.warn("Trying to reset password for user " + userName + " but wrong token " + resetPasswordToken + " provided");
|
||||
addLoginError(account);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// password reset token no longer valid
|
||||
LOGGER.log(Level.WARN, "Trying to reset password for user " + userName + " but token is no longer valid");
|
||||
LOGGER.warn("Trying to reset password for user " + userName + " but token is no longer valid");
|
||||
addLoginError(account);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// user is not is password reset mode
|
||||
LOGGER.log(Level.WARN, "Trying to reset password for user " + userName + " but password reset was not requested");
|
||||
LOGGER.warn("Trying to reset password for user " + userName + " but password reset was not requested");
|
||||
addLoginError(account);
|
||||
return false;
|
||||
}
|
||||
@ -257,7 +257,7 @@ public class AccountControl {
|
||||
int maxFailedLogins = configService.getMaxFailedLogins();
|
||||
if ((account.getFailureCount() >= maxFailedLogins) && (!account.getStatus().equals("LOCKED"))) { // TOD add status enum
|
||||
// max failed logins reached, disabling user
|
||||
LOGGER.log(Level.INFO, "Locking account " + account.getUsername() + " due to " + account.getFailureCount() + " failed logins");
|
||||
LOGGER.info( "Locking account " + account.getUsername() + " due to " + account.getFailureCount() + " failed logins");
|
||||
account.setStatus("LOCKED"); // TODO add enum
|
||||
}
|
||||
|
||||
|
||||
@ -13,8 +13,8 @@ import javax.ejb.Stateless;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -23,7 +23,7 @@ import org.apache.log4j.Logger;
|
||||
@Stateless
|
||||
public class MailTemplateService {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(MailTemplateService.class.getName());
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MailTemplateService.class.getName());
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
@ -34,7 +34,7 @@ public class MailTemplateService {
|
||||
query.setParameter("templateName", templateName);
|
||||
MailTemplateEntity templateEntity = (MailTemplateEntity) query.getSingleResult();
|
||||
if (templateEntity == null) {
|
||||
LOGGER.log(Level.ERROR, "Tempate with name " + templateName + " not found");
|
||||
LOGGER.error( "Tempate with name " + templateName + " not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -54,9 +54,9 @@ public class MailTemplateService {
|
||||
return templateString;
|
||||
} catch (Exception ex) {
|
||||
String hint = "Error while processing template with name " + templateName + ".";
|
||||
LOGGER.log(Level.ERROR, hint + " " + ex.toString());
|
||||
LOGGER.error( hint + " " + ex.toString());
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.log(Level.DEBUG, hint, ex);
|
||||
LOGGER.debug( hint, ex);
|
||||
}
|
||||
throw new MailTemplateException(hint, ex);
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.muehlencord.shared.account.util;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.shiro.authc.credential.DefaultPasswordService;
|
||||
import org.apache.shiro.crypto.hash.DefaultHashService;
|
||||
import org.apache.shiro.crypto.hash.Sha512Hash;
|
||||
@ -11,8 +11,8 @@ import org.apache.shiro.crypto.hash.Sha512Hash;
|
||||
* @author jomu
|
||||
*/
|
||||
public class SecurityUtil {
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger (SecurityUtil.class.getName());
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(SecurityUtil.class.getName());
|
||||
|
||||
public static String createPassword(String clearTextPassword) {
|
||||
// TODO read values from shiro.ini
|
||||
@ -25,8 +25,8 @@ public class SecurityUtil {
|
||||
passwordService.setHashService(hashService);
|
||||
|
||||
// try to encrypt password
|
||||
String encryptedPassword = passwordService.encryptPassword(clearTextPassword);
|
||||
LOGGER.log (Level.TRACE, encryptedPassword);
|
||||
String encryptedPassword = passwordService.encryptPassword(clearTextPassword);
|
||||
LOGGER.trace(encryptedPassword);
|
||||
return encryptedPassword;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user