Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delombok #9

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -31,7 +30,7 @@ test {
}

checkstyle {
toolVersion '8.31'
toolVersion '9.3'
maxWarnings 0
}

Expand Down Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="allowedAnnotations" value="Override, Test"/>
Expand Down
2 changes: 0 additions & 2 deletions src/lombok.config

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Boolean> ENABLED =
SystemProperty.Builder.ofType(Boolean.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)"
Expand Down Expand Up @@ -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();
stokito marked this conversation as resolved.
Show resolved Hide resolved
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);
}
Expand All @@ -92,8 +96,9 @@ private void purgeOldTokens() throws SQLException {
*/
public Optional<User> 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()) {
Expand All @@ -117,8 +122,9 @@ public Optional<User> 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();
Expand All @@ -133,8 +139,10 @@ public void deleteTokens(final User user) throws SQLException {
public List<ResetRequest> 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<ResetRequest> resetRequests = new ArrayList<>();
Expand All @@ -154,10 +162,43 @@ public List<ResetRequest> getResetRequests() {
}
}

@Data
public static class ResetRequest {
public final String userId;
public final String sourceAddress;
public final Date expires;

stokito marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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
+ '}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<WebManager> webManagerSupplier;
Expand Down Expand Up @@ -149,7 +150,6 @@ private void redirectWithMessage(
response.sendRedirect(request.getRequestURI());
}

@Data
stokito marked this conversation as resolved.
Show resolved Hide resolved
public static final class Dto {

private static final int MAX_PROP_LENGTH = 4000;
Expand Down Expand Up @@ -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<ResetRequest> 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
+ '}';
}
}
}
Loading