-
Notifications
You must be signed in to change notification settings - Fork 21
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
jwt api implementation #48
base: develop
Are you sure you want to change the base?
Changes from 5 commits
fbe6878
54236e3
ba5afd4
fd0eb9a
0ca92ba
4c392fe
45d7218
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ [email protected]_API_BASE_URL@/beneficiary/create | |
|
||
##Beneficiary Edit Url | ||
beneficiaryEditUrl [email protected]_API_BASE_URL@/beneficiary/update | ||
[email protected]_SECRET_KEY@ |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,11 +22,19 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package com.iemr.ecd.config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.beans.factory.annotation.Value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.cache.annotation.EnableCaching; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.context.annotation.Bean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.context.annotation.Configuration; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.data.redis.core.RedisTemplate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import com.iemr.ecd.dao.Users; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@EnableCaching | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π‘ Codebase verification Redis security configuration needs enhancement The Redis configuration is currently using default settings with no security measures:
This setup is insufficient for a production environment, especially when handling JWT session data. Consider adding the following properties to
π Analysis chainVerify Redis security configuration The Redis configuration lacks security settings. When implementing JWT authentication, it's crucial to secure the Redis instance that might store sensitive session data. Consider adding:
π Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check if Redis security configuration exists in properties files
rg -l "spring.redis.(password|ssl|timeout)" --type properties
Length of output: 98 Script: #!/bin/bash
# Search for application properties/yaml files and Redis configuration
fd -e properties -e yml -e yaml | xargs rg -l "spring.redis"
Length of output: 102 Script: #!/bin/bash
# Search for any Redis-related security configuration in Java files
rg -l "RedisPassword|RedisSsl|RedisTimeout|RedisSecur" --type java
Length of output: 68 Script: #!/bin/bash
# Look for Redis configuration beans and security settings
ast-grep --pattern 'class $_ {
$$$
@Bean
$$$RedisTemplate$$$
$$$
}'
Length of output: 77 Script: #!/bin/bash
# Check for any Redis security configuration in XML files
fd -e xml | xargs rg -l "spring.redis|redis.security"
Length of output: 55 Script: #!/bin/bash
# Check the content of application.properties for Redis configuration
cat src/main/resources/application.properties
Length of output: 1840 Script: #!/bin/bash
# Look for Redis connection configuration in Java files
rg "spring.redis" --type java -A 3
Length of output: 765 Script: #!/bin/bash
# Search for Redis connection properties being set programmatically
ast-grep --pattern 'RedisStandaloneConfiguration $_ = new RedisStandaloneConfiguration();'
Length of output: 92 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public class RedisConfig { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private @Value("${spring.redis.host}") String redisHost; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -37,4 +45,19 @@ LettuceConnectionFactory lettuceConnectionFactory() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return new LettuceConnectionFactory(redisHost, redisPort); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Bean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public RedisTemplate<String, Users> redisTemplate(RedisConnectionFactory factory) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RedisTemplate<String, Users> template = new RedisTemplate<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
template.setConnectionFactory(factory); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Use StringRedisSerializer for keys (userId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
template.setKeySerializer(new StringRedisSerializer()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Use Jackson2JsonRedisSerializer for values (Users objects) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Jackson2JsonRedisSerializer<Users> serializer = new Jackson2JsonRedisSerializer<>(Users.class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
template.setValueSerializer(serializer); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+56
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security consideration: Add type information to Jackson serializer The current Jackson serializer configuration might be vulnerable to deserialization attacks. Consider enabling default typing for proper polymorphic type handling. Jackson2JsonRedisSerializer<Users> serializer = new Jackson2JsonRedisSerializer<>(Users.class);
+ObjectMapper mapper = new ObjectMapper();
+mapper.activateDefaultTyping(mapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL);
+serializer.setObjectMapper(mapper);
template.setValueSerializer(serializer); π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return template; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+48
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential bean conflict with EcdApiApplication RedisTemplate There are two
This could lead to autowiring conflicts and unexpected behavior. Consider:
@Bean
+@Qualifier("usersRedisTemplate")
public RedisTemplate<String, Users> redisTemplate(RedisConnectionFactory factory) { π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.iemr.ecd.dao; | ||
|
||
import java.io.Serializable; | ||
import java.sql.Timestamp; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.google.gson.annotations.Expose; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Entity | ||
@Table(name = "m_user") | ||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Add validation constraints The entity lacks input validation annotations for critical fields. Add appropriate validations: @Data
@Entity
@Table(name = "m_user")
+@EntityListeners(AuditingEntityListener.class)
public class Users { Example field validations: + @NotBlank(message = "Username is required")
+ @Size(min = 3, max = 50)
private String userName;
+ @Email(message = "Invalid email format")
private String emailID;
+ @Pattern(regexp = "^[0-9]{12}$", message = "Invalid Aadhaar format")
private String aadhaarNo;
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class Users implements Serializable { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Expose | ||
@Column(name = "UserID") | ||
private Long userID; | ||
@Expose | ||
@Column(name = "TitleID") private Short titleID; | ||
@Expose | ||
@Column(name = "FirstName") | ||
private String firstName; | ||
@Expose | ||
@Column(name = "MiddleName") | ||
private String middleName; | ||
@Expose | ||
@Column(name = "lastName") | ||
private String lastName; | ||
@Expose | ||
@Column(name = "GenderID") | ||
private Short genderID; | ||
@Expose | ||
@Column(name = "MaritalStatusID") | ||
private Short maritalStatusID; | ||
@Expose | ||
@Column(name = "AadhaarNo") | ||
private String aadhaarNo; | ||
@Expose | ||
@Column(name = "PAN") | ||
private String pan; | ||
Comment on lines
+45
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: PII data protection required Aadhaar and PAN are sensitive PII (Personally Identifiable Information) that require special handling:
Recommendations:
|
||
@Expose | ||
@Column(name = "DOB") | ||
private Timestamp dob; | ||
@Expose | ||
@Column(name = "DOJ") | ||
private Timestamp doj; | ||
@Expose | ||
@Column(name = "QualificationID") | ||
private Integer qualificationID; | ||
@Expose | ||
@Column(name = "UserName") | ||
private String userName; | ||
@Expose | ||
@Column(name = "Password") | ||
private String password; | ||
Comment on lines
+63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Secure password handling required The password field lacks proper security measures:
Add password hashing and remove @expose: - @Expose
@Column(name = "Password")
private String password; Consider using:
|
||
@Expose | ||
@Column(name = "AgentID") | ||
private String agentID; | ||
@Expose | ||
@Column(name = "AgentPassword") | ||
private String agentPassword; | ||
@Expose | ||
@Column(name = "EmailID") | ||
private String emailID; | ||
@Expose | ||
@Column(name = "StatusID") | ||
private Short statusID; | ||
@Expose | ||
@Column(name = "EmergencyContactPerson") | ||
private String emergencyContactPerson; | ||
@Expose | ||
@Column(name = "EmergencyContactNo") | ||
private String emergencyContactNo; | ||
@Expose | ||
@Column(name = "IsSupervisor") | ||
private Boolean isSupervisor; | ||
@Expose | ||
@Column(name = "Deleted") | ||
private Boolean deleted; | ||
@Expose | ||
@Column(name = "CreatedBy") | ||
private String createdBy; | ||
@Expose | ||
@Column(name = "CreatedDate") | ||
private Timestamp createdDate; | ||
@Expose | ||
@Column(name = "ModifiedBy") | ||
private String modifiedBy; | ||
@Expose | ||
@Column(name = "LastModDate") | ||
private Timestamp lastModDate; | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.iemr.ecd.utils.mapper; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import jakarta.servlet.http.Cookie; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
@Service | ||
public class CookieUtil { | ||
|
||
public Optional<String> getCookieValue(HttpServletRequest request, String cookieName) { | ||
Cookie[] cookies = request.getCookies(); | ||
if (cookies != null) { | ||
for (Cookie cookie : cookies) { | ||
if (cookieName.equals(cookie.getName())) { | ||
return Optional.of(cookie.getValue()); | ||
} | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
public String getJwtTokenFromCookie(HttpServletRequest request) { | ||
return Arrays.stream(request.getCookies()).filter(cookie -> "Jwttoken".equals(cookie.getName())) | ||
.map(Cookie::getValue).findFirst().orElse(null); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.iemr.ecd.utils.mapper; | ||
|
||
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class FilterConfig { | ||
|
||
@Bean | ||
public FilterRegistrationBean<JwtUserIdValidationFilter> jwtUserIdValidationFilter( | ||
JwtAuthenticationUtil jwtAuthenticationUtil) { | ||
FilterRegistrationBean<JwtUserIdValidationFilter> registrationBean = new FilterRegistrationBean<>(); | ||
registrationBean.setFilter(new JwtUserIdValidationFilter(jwtAuthenticationUtil)); | ||
registrationBean.addUrlPatterns("/*"); // Apply filter to all API endpoints | ||
return registrationBean; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
Move Redis configuration to RedisConfig class
Redis configuration should be centralized in the
RedisConfig
class rather than split across multiple files. This violates the Single Responsibility Principle.