Skip to content
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
19 changes: 10 additions & 9 deletions .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
import java.nio.channels.*;
import java.util.Properties;

public class MavenWrapperDownloader {
public final class MavenWrapperDownloader {

private MavenWrapperDownloader() {
throw new UnsupportedOperationException("Utility class");
}
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
Expand Down Expand Up @@ -106,12 +109,10 @@ protected PasswordAuthentication getPasswordAuthentication() {
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}

}
try (ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination)) {
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}

}}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class AuthEntryPointJwt implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
logger.error("Unauthorized error: {}", authException.getMessage());
if (logger.isErrorEnabled()) {
logger.error("Unauthorized error: {}", authException.getMessage());

response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
Expand All @@ -39,5 +40,5 @@ public void commence(HttpServletRequest request, HttpServletResponse response, A
final ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(response.getOutputStream(), body);
}

}
}
30 changes: 21 additions & 9 deletions src/main/java/com/bezkoder/spring/login/security/jwt/JwtUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,38 @@ public String getUserNameFromJwtToken(String token) {
.parseClaimsJws(token).getBody().getSubject();
}

private Key key() {
private Key key() {
return Keys.hmacShaKeyFor(Decoders.BASE64.decode(jwtSecret));
}
private void logJwtError(String message, Exception e) {
if (logger.isErrorEnabled()) {
logger.error(message, e.getMessage());
}
}

public boolean validateJwtToken(String authToken) {
try {
Jwts.parserBuilder().setSigningKey(key()).build().parse(authToken);
return true;
Jwts.parserBuilder()
.setSigningKey(key())
.build()
.parse(authToken);
return true;

} catch (MalformedJwtException e) {
logger.error("Invalid JWT token: {}", e.getMessage());
logJwtError("Invalid JWT token: {}", e);

} catch (ExpiredJwtException e) {
logger.error("JWT token is expired: {}", e.getMessage());
logJwtError("JWT token is expired: {}", e);

} catch (UnsupportedJwtException e) {
logger.error("JWT token is unsupported: {}", e.getMessage());
logJwtError("JWT token is unsupported: {}", e);

} catch (IllegalArgumentException e) {
logger.error("JWT claims string is empty: {}", e.getMessage());
logJwtError("JWT claims string is empty: {}", e);
}

return false;
}
}

public String generateTokenFromUsername(String username) {
return Jwts.builder()
Expand All @@ -85,4 +97,4 @@ public String generateTokenFromUsername(String username) {
.signWith(key(), SignatureAlgorithm.HS256)
.compact();
}
}
}