diff --git a/build.gradle b/build.gradle index f0e7a21..71277ce 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,6 @@ plugins { } apply from: 'build.openfire-plugin.gradle' -ext.lombokVersion = '1.18.12' ext.junitVersion = '5.3.1' group = 'org.igniterealtime.openfire.plugins' @@ -31,7 +30,7 @@ test { } checkstyle { - toolVersion '8.31' + toolVersion '9.3' maxWarnings 0 } @@ -75,12 +74,6 @@ spotbugsMain { } dependencies { - compileOnly "org.projectlombok:lombok:${lombokVersion}" - annotationProcessor "org.projectlombok:lombok:${lombokVersion}" - - testCompileOnly "org.projectlombok:lombok:${lombokVersion}" - testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}" - implementation 'com.github.bbottema:emailaddress-rfc2822:2.1.4' testImplementation 'com.github.spotbugs:spotbugs-annotations:4.0.1' diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 23fb069..a36ea16 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -296,7 +296,6 @@ value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/> - diff --git a/src/lombok.config b/src/lombok.config deleted file mode 100644 index 99187cd..0000000 --- a/src/lombok.config +++ /dev/null @@ -1,2 +0,0 @@ -config.stopBubbling = true -lombok.addLombokGeneratedAnnotation = true \ No newline at end of file diff --git a/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/PasswordResetPlugin.java b/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/PasswordResetPlugin.java index fd14dc2..937d2b8 100644 --- a/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/PasswordResetPlugin.java +++ b/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/PasswordResetPlugin.java @@ -4,7 +4,6 @@ import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.Arrays; -import lombok.extern.slf4j.Slf4j; import org.apache.tomcat.InstanceManager; import org.apache.tomcat.SimpleInstanceManager; import org.eclipse.jetty.webapp.WebAppContext; @@ -17,10 +16,13 @@ import org.jivesoftware.util.EmailService; import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.SystemProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -@Slf4j public class PasswordResetPlugin implements Plugin { + private static final Logger log = LoggerFactory.getLogger(PasswordResetPlugin.class); + public static final String PLUGIN_NAME = "Password Reset"; // Exact match to plugin.xml public static final SystemProperty ENABLED = SystemProperty.Builder.ofType(Boolean.class) diff --git a/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/PasswordResetTokenManager.java b/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/PasswordResetTokenManager.java index 20d9d50..1926bd9 100644 --- a/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/PasswordResetTokenManager.java +++ b/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/PasswordResetTokenManager.java @@ -1,5 +1,7 @@ package org.jivesoftware.openfire.plugin.passwordreset; +import static java.util.Objects.requireNonNull; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -11,16 +13,17 @@ import java.util.Date; import java.util.List; import java.util.Optional; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; import org.jivesoftware.openfire.user.User; import org.jivesoftware.openfire.user.UserManager; import org.jivesoftware.openfire.user.UserNotFoundException; import org.jivesoftware.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -@Slf4j public class PasswordResetTokenManager { + private static final Logger log = LoggerFactory.getLogger(PasswordResetTokenManager.class); + private static final int TOKEN_LENGTH = 32; private static final String INSERT_SQL = "INSERT INTO ofPasswordResetToken (token, userId, sourceAddress, expires)" @@ -61,23 +64,24 @@ public PasswordResetTokenManager( */ public String generateToken(final User user, final String sourceAddress) throws SQLException { purgeOldTokens(); + Instant expires = Instant.now().plus(PasswordResetPlugin.EXPIRY.getValue()); final String token = StringUtils.randomString(TOKEN_LENGTH); - try (final Connection connection = connectionSupplier.get(); - final PreparedStatement statement = connection.prepareStatement(INSERT_SQL)) { + final Connection connection = connectionSupplier.get(); + requireNonNull(connection); + try (final PreparedStatement statement = connection.prepareStatement(INSERT_SQL)) { statement.setString(1, token); statement.setString(2, user.getUsername()); statement.setString(3, sourceAddress); - statement.setTimestamp(4, - new Timestamp(Instant.now().plus(PasswordResetPlugin.EXPIRY.getValue()) - .toEpochMilli())); + statement.setTimestamp(4, Timestamp.from(expires)); statement.execute(); } return token; } private void purgeOldTokens() throws SQLException { - try (final Connection connection = connectionSupplier.get(); - final PreparedStatement statement = connection.prepareStatement(PURGE_EXPIRED_SQL)) { + final Connection connection = connectionSupplier.get(); + requireNonNull(connection); + try (final PreparedStatement statement = connection.prepareStatement(PURGE_EXPIRED_SQL)) { final int updateCount = statement.executeUpdate(); log.debug("Purged {} records", updateCount); } @@ -92,8 +96,9 @@ private void purgeOldTokens() throws SQLException { */ public Optional getUser(final String token) throws SQLException { purgeOldTokens(); - try (final Connection connection = connectionSupplier.get(); - final PreparedStatement statement = connection.prepareStatement(FIND_USER_SQL)) { + final Connection connection = connectionSupplier.get(); + requireNonNull(connection); + try (final PreparedStatement statement = connection.prepareStatement(FIND_USER_SQL)) { statement.setString(1, token); try (final ResultSet resultSet = statement.executeQuery()) { if (resultSet.next()) { @@ -117,8 +122,9 @@ public Optional getUser(final String token) throws SQLException { * @throws SQLException if something untoward happens */ public void deleteTokens(final User user) throws SQLException { - try (final Connection connection = connectionSupplier.get(); - final PreparedStatement statement + final Connection connection = connectionSupplier.get(); + requireNonNull(connection); + try (final PreparedStatement statement = connection.prepareStatement(DELETE_TOKENS_FOR_USER)) { statement.setString(1, user.getUsername()); statement.execute(); @@ -133,8 +139,10 @@ public void deleteTokens(final User user) throws SQLException { public List getResetRequests() { try { purgeOldTokens(); - try (final Connection connection = connectionSupplier.get(); - final PreparedStatement statement = connection.prepareStatement(RESET_REQUESTS_SQL); + final Connection connection = connectionSupplier.get(); + requireNonNull(connection); + try (final PreparedStatement statement + = connection.prepareStatement(RESET_REQUESTS_SQL); final ResultSet resultSet = statement.executeQuery()) { final List resetRequests = new ArrayList<>(); @@ -154,10 +162,43 @@ public List getResetRequests() { } } - @Data public static class ResetRequest { public final String userId; public final String sourceAddress; public final Date expires; + + + /** + * ResetRequest Constructor. + * @param userId userId + * @param sourceAddress sourceAddress + * @param expires expires + */ + public ResetRequest(String userId, String sourceAddress, Date expires) { + this.userId = userId; + this.sourceAddress = sourceAddress; + this.expires = expires; + } + + public String getUserId() { + return this.userId; + } + + public String getSourceAddress() { + return this.sourceAddress; + } + + public Date getExpires() { + return this.expires; + } + + @Override + public String toString() { + return "ResetRequest{" + + "userId='" + userId + '\'' + + ", sourceAddress='" + sourceAddress + '\'' + + ", expires=" + expires + + '}'; + } } } diff --git a/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/admin/PasswordResetSettingsServlet.java b/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/admin/PasswordResetSettingsServlet.java index 658d9ea..f14f8c1 100644 --- a/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/admin/PasswordResetSettingsServlet.java +++ b/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/admin/PasswordResetSettingsServlet.java @@ -13,8 +13,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; import org.hazlewood.connor.bottema.emailaddress.EmailAddressValidator; import org.jivesoftware.admin.FlashMessageTag; import org.jivesoftware.openfire.plugin.passwordreset.PasswordResetMailer; @@ -28,10 +26,13 @@ import org.jivesoftware.util.ParamUtils; import org.jivesoftware.util.StringUtils; import org.jivesoftware.util.WebManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -@Slf4j public class PasswordResetSettingsServlet extends HttpServlet { + private static final Logger log = LoggerFactory.getLogger(PasswordResetSettingsServlet.class); + private static final long serialVersionUID = -2522058940676139518L; private static UserProvider userProvider; private static Supplier webManagerSupplier; @@ -149,7 +150,6 @@ private void redirectWithMessage( response.sendRedirect(request.getRequestURI()); } - @Data public static final class Dto { private static final int MAX_PROP_LENGTH = 4000; @@ -336,5 +336,116 @@ private String validateServer() { private Duration getExpiry() { return Duration.of(Long.parseLong(expiryCount), ChronoUnit.valueOf(expiryPeriod)); } + + public boolean isNotSupported() { + return this.notSupported; + } + + public boolean isEnabled() { + return this.enabled; + } + + public String getServer() { + return this.server; + } + + public String getServerError() { + return this.serverError; + } + + public String getSenderName() { + return this.senderName; + } + + public String getSenderNameError() { + return this.senderNameError; + } + + public String getSenderAddress() { + return this.senderAddress; + } + + public String getSenderAddressError() { + return this.senderAddressError; + } + + public String getSubject() { + return this.subject; + } + + public String getSubjectError() { + return this.subjectError; + } + + public String getBody() { + return this.body; + } + + public String getBodyError() { + return this.bodyError; + } + + public String getExpiryCount() { + return this.expiryCount; + } + + public String getExpiryPeriod() { + return this.expiryPeriod; + } + + public String getExpiryError() { + return this.expiryError; + } + + public String getMinLength() { + return this.minLength; + } + + public String getMinLengthError() { + return this.minLengthError; + } + + public String getMaxLength() { + return this.maxLength; + } + + public String getMaxLengthError() { + return this.maxLengthError; + } + + public boolean isValid() { + return this.valid; + } + + public List getResetRequests() { + return this.resetRequests; + } + + @Override + public String toString() { + return "Dto{" + + "notSupported=" + notSupported + + ", enabled=" + enabled + + ", server='" + server + '\'' + + ", serverError='" + serverError + '\'' + + ", senderName='" + senderName + '\'' + + ", senderNameError='" + senderNameError + '\'' + + ", senderAddress='" + senderAddress + '\'' + + ", senderAddressError='" + senderAddressError + '\'' + + ", subject='" + subject + '\'' + + ", subjectError='" + subjectError + '\'' + + ", body='" + body + '\'' + + ", bodyError='" + bodyError + '\'' + + ", expiryCount='" + expiryCount + '\'' + + ", expiryPeriod='" + expiryPeriod + '\'' + + ", expiryError='" + expiryError + '\'' + + ", minLength='" + minLength + '\'' + + ", minLengthError='" + minLengthError + '\'' + + ", maxLength='" + maxLength + '\'' + + ", maxLengthError='" + maxLengthError + '\'' + + ", valid=" + valid + + ", resetRequests=" + resetRequests + + '}'; + } } } diff --git a/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/client/PasswordResetChangePasswordServlet.java b/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/client/PasswordResetChangePasswordServlet.java index ce8fb95..f2e045d 100644 --- a/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/client/PasswordResetChangePasswordServlet.java +++ b/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/client/PasswordResetChangePasswordServlet.java @@ -9,17 +9,19 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; import org.jivesoftware.admin.FlashMessageTag; import org.jivesoftware.openfire.plugin.passwordreset.PasswordResetPlugin; import org.jivesoftware.openfire.plugin.passwordreset.PasswordResetTokenManager; import org.jivesoftware.openfire.user.User; import org.jivesoftware.util.ParamUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -@Slf4j public class PasswordResetChangePasswordServlet extends HttpServlet { + private static final Logger log + = LoggerFactory.getLogger(PasswordResetChangePasswordServlet.class); + private static final long serialVersionUID = -5668541154412417961L; private static PasswordResetTokenManager resetTokenManager; @@ -34,6 +36,7 @@ static void initStatic( PasswordResetChangePasswordServlet.resetTokenManager = resetTokenManager; } + @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final String token = ParamUtils.getStringParameter(request, "token", ""); @@ -64,6 +67,7 @@ private void redirectWithMessage( response.sendRedirect(request.getRequestURI()); } + @Override protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { @@ -115,7 +119,6 @@ private void handleUpdate( .forward(request, response); } - @Data public static class Form { private final String userId; @@ -165,5 +168,42 @@ private String validateNewPassword() { } return ""; } + + public String getUserId() { + return this.userId; + } + + public String getToken() { + return this.token; + } + + public String getNewPassword() { + return this.newPassword; + } + + public String getNewPasswordError() { + return this.newPasswordError; + } + + public String getNewPasswordConfirmation() { + return this.newPasswordConfirmation; + } + + public String getNewPasswordConfirmationError() { + return this.newPasswordConfirmationError; + } + + public boolean isValid() { + return this.valid; + } + + @Override + public String toString() { + return "Form{" + + "userId='" + userId + '\'' + + ", token='" + token + '\'' + + ", valid=" + valid + + '}'; + } } } diff --git a/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/client/PasswordResetSendEmailServlet.java b/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/client/PasswordResetSendEmailServlet.java index bca36ed..15ead00 100644 --- a/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/client/PasswordResetSendEmailServlet.java +++ b/src/main/java/org/jivesoftware/openfire/plugin/passwordreset/servlet/client/PasswordResetSendEmailServlet.java @@ -10,8 +10,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; import org.jivesoftware.admin.FlashMessageTag; import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.plugin.passwordreset.PasswordResetMailer; @@ -22,11 +20,14 @@ import org.jivesoftware.openfire.user.UserNotFoundException; import org.jivesoftware.openfire.user.UserProvider; import org.jivesoftware.util.ParamUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.xmpp.packet.JID; -@Slf4j public class PasswordResetSendEmailServlet extends HttpServlet { + private static final Logger log = LoggerFactory.getLogger(PasswordResetSendEmailServlet.class); + private static final long serialVersionUID = -7605965376783076351L; private static final int BATCH_SIZE = 50; private static XMPPServer xmppServer; @@ -161,7 +162,6 @@ private Optional getUserFromUserId(final String userId) { } } - @Data public static class Form { private final boolean enabled; @@ -195,6 +195,41 @@ private String validateUser() { } return ""; } + + public boolean isEnabled() { + return this.enabled; + } + + public String getUser() { + return this.user; + } + + public String getUserError() { + return this.userError; + } + + public boolean isEmailSent() { + return this.emailSent; + } + + public boolean isValid() { + return this.valid; + } + + public void setEmailSent(boolean emailSent) { + this.emailSent = emailSent; + } + + @Override + public String toString() { + return "Form{" + + "enabled=" + enabled + + ", user='" + user + '\'' + + ", userError='" + userError + '\'' + + ", emailSent=" + emailSent + + ", valid=" + valid + + '}'; + } } }