Closed sanseervi closed 4 years ago
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.
Did you find it? . I have a similar error
Hi, I am getting similar one. Did you find the resolution?
hi did u find it ,? i need help , i have a similar error
Hello Everyone,
I am using aws S3 service in our project. After a while I get this error. Has anyone came across the same problem and found a solution ?
My conf:
@Bean
public AmazonS3 s3Client() {
System.setProperty(SDKGlobalConfiguration.DISABLE_CERT_CHECKING_SYSTEM_PROPERTY,"true");
AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
new BasicAWSCredentials(accessKey, secretKey));
return AmazonS3ClientBuilder
.standard()
.withPathStyleAccessEnabled(true)
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpointUrl, "eu-central-1"))
.withCredentials(awsStaticCredentialsProvider)
.build();
}
I'm closing the objects.
finally { if (s3Object != null) { s3Object.close(); } }
org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
I was getting the same error as “Error executing DDL ‘create table user’ in the postgresql database. user is a keyword in postgresql, so it gives this error. I changed it to @Table(name=”user_table")
and it was fixed. I hope this can help you.
You need use private key and public key properly : below code will generate privae and public key effectively
package com.example.usermanagement.security;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Component;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.MalformedJwtException;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.UnsupportedJwtException;
import io.jsonwebtoken.security.SignatureException;
@Component
public class JwtUtil {
// The key pair will be generated once and used throughout the app
private final KeyPair keyPair;
public JwtUtil() {
this.keyPair = generateKeyPair(); // Generate the key pair when the component is initialized
}
/**
* Generate an RSA key pair for signing and verifying JWTs
*/
private KeyPair generateKeyPair() {
try {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(2048); // Key size of 2048 bits
return keyPairGenerator.generateKeyPair();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Failed to generate RSA key pair", e);
}
}
/**
* Generate a JWT token for the given username.
*/
@SuppressWarnings("deprecation")
public String generateToken(String username) {
Map<String, Object> claims = new HashMap<>();
String token = Jwts.builder()
.setClaims(claims)
.setSubject(username)
.setIssuedAt(new Date(System.currentTimeMillis()))
.setExpiration(new Date(System.currentTimeMillis() + 86400000)) // Token expires in 1 day
.signWith(SignatureAlgorithm.RS256, keyPair.getPrivate()) // Use the generated private key
.compact();
System.out.println("Token: " + token);
return token;
}
/**
* Validate the JWT token with the given username.
*/
public boolean validateToken(String token, String username) {
String extractedUsername = extractUsername(token);
return (extractedUsername.equals(username) && !isTokenExpired(token));
}
/**
* Extract the username (subject) from the JWT token.
*/
private String extractUsername(String token) {
return extractAllClaims(token).getSubject();
}
/**
* Extract all claims from the JWT token.
*/
@SuppressWarnings("deprecation")
private Claims extractAllClaims(String token) {
try {
return Jwts.parser()
.setSigningKey(keyPair.getPublic()) // Use the generated public key to verify the token
.parseClaimsJws(token)
.getBody();
} catch (ExpiredJwtException | MalformedJwtException | UnsupportedJwtException | SignatureException | IllegalArgumentException e) {
System.out.println("Token decoding failed: " + e.getMessage());
throw e; // Handle this based on your needs
}
}
/**
* Check if the token is expired.
*/
private boolean isTokenExpired(String token) {
return extractAllClaims(token).getExpiration().before(new Date());
}
/**
* Get the private key in PEM format (for debugging purposes, or if needed for other uses).
*/
public String getPrivateKeyPem() {
return "-----BEGIN PRIVATE KEY-----\n" +
Base64.getEncoder().encodeToString(keyPair.getPrivate().getEncoded()) +
"\n-----END PRIVATE KEY-----";
}
/**
* Get the public key in PEM format (for debugging purposes, or if needed for other uses).
*/
public String getPublicKeyPem() {
return "-----BEGIN PUBLIC KEY-----\n" +
Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded()) +
"\n-----END PUBLIC KEY-----";
}
}
Hi Team, I got an issue when I was consuming the rest call from different services. For code ref - https://github.com/koushikkothagal/spring-boot-microservices-workshop/tree/master/movie-catalog-service
Below is the snippet of my code.
please see below error