Skip to content

Commit

Permalink
chore: #169 - Use Lombok + parameterised logging
Browse files Browse the repository at this point in the history
* Some Intellisense cleanup too.
  • Loading branch information
gazbert committed Nov 13, 2024
1 parent 4b2dc6f commit e1ce999
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ public StrategyConfig save(StrategyConfig config) {
.collect(Collectors.toList()));
} else {
log.warn(
"Trying to update StrategyConfig but id does not exist StrategyConfig: {} Existing StrategyConfig: {}",
config,
strategiesType.getStrategies());
"Trying to update StrategyConfig but id does not exist StrategyConfig: "
+ config
+ " Existing StrategyConfig: "
+ strategiesType.getStrategies());
return null;
}
}
Expand All @@ -161,9 +162,10 @@ public StrategyConfig delete(String id) {
return adaptInternalToExternalConfig(Collections.singletonList(strategyToRemove));
} else {
log.warn(
"Trying to delete StrategyConfig but id does not exist. StrategyConfig id: {} Existing StrategyConfig: {}",
id,
strategiesType.getStrategies());
"Trying to delete StrategyConfig but id does not exist. StrategyConfig id: "
+ id
+ " Existing StrategyConfig: "
+ strategiesType.getStrategies());
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected void doFilterInternal(
final Claims claims = jwtUtils.validateTokenAndGetClaims(authorizationHeader);
log.info("JWT is valid");
final String username = jwtUtils.getUsernameFromTokenClaims(claims);
log.info("Username in JWT: " + username);
log.info("Username in JWT: {}", username);

if (SecurityContextHolder.getContext().getAuthentication() == null) {
// First time in - store user details in Spring's Security context
Expand All @@ -91,14 +91,14 @@ protected void doFilterInternal(
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(authentication);

log.info("Authenticated User: " + username + " has been set in Spring SecurityContext.");
log.info("Authenticated User: {} has been set in Spring SecurityContext.", username);
}
}

chain.doFilter(request, response);

} catch (Exception e) {
log.error("JWT Authentication failure! Details: " + e.getMessage(), e);
log.error("JWT Authentication failure! Details: {}", e.getMessage(), e);
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

/**
* Encapsulates a JWT Authentication Request containing username/password sent from the client.
Expand All @@ -35,6 +37,8 @@
*
* @author gazbert
*/
@Setter
@Getter
public class JwtAuthenticationRequest {

@Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "The username.")
Expand All @@ -61,40 +65,4 @@ public JwtAuthenticationRequest(String username, String password) {
this.username = username;
this.password = password;
}

/**
* Returns the username.
*
* @return the username.
*/
public String getUsername() {
return this.username;
}

/**
* Sets the username.
*
* @param username the username.
*/
public void setUsername(String username) {
this.username = username;
}

/**
* Returns the password.
*
* @return the password.
*/
public String getPassword() {
return this.password;
}

/**
* Sets the password.
*
* @param password the password.
*/
public void setPassword(String password) {
this.password = password;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

/**
* Encapsulates a JWT Authentication response. It wraps the JWT (Base64 encoded String).
*
* @author gazbert
*/
@Setter
@Getter
public class JwtAuthenticationResponse {

@Schema(requiredMode = Schema.RequiredMode.REQUIRED, description = "The JWT.")
Expand All @@ -51,22 +55,4 @@ public JwtAuthenticationResponse() {
public JwtAuthenticationResponse(String token) {
this.token = token;
}

/**
* Returns the JWT.
*
* @return the JWT.
*/
public String getToken() {
return this.token;
}

/**
* Sets the JWT.
*
* @param token the JWT.
*/
public void setToken(String token) {
this.token = token;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public RestCorsConfig() {
@Bean
CorsConfigurationSource corsConfigurationSource() {

log.info("CORS Allowed Origins: " + allowedOrigin);
log.info("CORS Allowed Origins: {}", allowedOrigin);

final CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Collections.singletonList(allowedOrigin));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

Expand All @@ -48,29 +49,24 @@ public class JwtUser implements UserDetails {
/** Username. */
private final String username;

/** Firstname. */
private final String firstname;
@Getter private final String firstname;

/** Lastname. */
private final String lastname;
@Getter private final String lastname;

/** Password. */
private final String password;

/** Email. */
private final String email;
@Getter private final String email;

/** Granted authorities. */
private final Collection<? extends GrantedAuthority> authorities;

/** Is enabled. */
private final boolean enabled;

/** Last password reset date. */
private final long lastPasswordResetDate;
@Getter private final long lastPasswordResetDate;

/** The user's roles. */
private final List<String> roles;
@Getter private final List<String> roles;

/**
* Creates a JWT User.
Expand Down Expand Up @@ -146,33 +142,6 @@ public boolean isCredentialsNonExpired() {
return true;
}

/**
* Returns the firstname.
*
* @return the firstname.
*/
public String getFirstname() {
return firstname;
}

/**
* Returns the lastname.
*
* @return the lastname.
*/
public String getLastname() {
return lastname;
}

/**
* Returns the email.
*
* @return the email.
*/
public String getEmail() {
return email;
}

@JsonIgnore
@Override
public String getPassword() {
Expand All @@ -188,22 +157,4 @@ public Collection<? extends GrantedAuthority> getAuthorities() {
public boolean isEnabled() {
return enabled;
}

/**
* Returns the last password reset date.
*
* @return the last password reset date.
*/
public long getLastPasswordResetDate() {
return lastPasswordResetDate;
}

/**
* Returns the roles.
*
* @return the roles.
*/
public List<String> getRoles() {
return roles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.Getter;
import lombok.Setter;

/**
* Represents a Role for a BX-bot User.
*
* @author gazbert
*/
@Setter
@Getter
@Entity
@Table(name = "ROLE")
public class Role {
Expand All @@ -65,58 +69,4 @@ public class Role {
public Role() {
// No extra init needed.
}

/**
* Returns the id.
*
* @return the id.
*/
public Long getId() {
return id;
}

/**
* Sets the id.
*
* @param id the id.
*/
public void setId(Long id) {
this.id = id;
}

/**
* Returns the name.
*
* @return the name.
*/
public RoleName getName() {
return name;
}

/**
* Sets the name.
*
* @param name the name.
*/
public void setName(RoleName name) {
this.name = name;
}

/**
* Returns the users.
*
* @return the users.
*/
public List<User> getUsers() {
return users;
}

/**
* Sets the users.
*
* @param users the users.
*/
public void setUsers(List<User> users) {
this.users = users;
}
}
Loading

0 comments on commit e1ce999

Please sign in to comment.