-
Notifications
You must be signed in to change notification settings - Fork 32
Jwt api implementation #62
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
859956b
jwt implementation
4456916
application prop
f1127a9
Formatting and dependency upgrade
3a922e1
corrected coderabbit comments
2b3b5e3
fixed issues
700b0b7
userId fetch from redis concept
0c78525
user class modify
3e5f540
user fetch concept modify
803cdcc
Merge branch 'develop' into jwt-api
indraniBan f1a62ce
Merge branch 'develop' into jwt-api
indraniBan fc1f083
Update package.yml
sandipkarmakar3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| target/ | ||
| !.mvn/wrapper/maven-wrapper.jar | ||
|
|
||
| ### STS ### | ||
| .apt_generated | ||
| .classpath | ||
| .factorypath | ||
| .project | ||
| .settings | ||
| .springBeans | ||
|
|
||
| ### IntelliJ IDEA ### | ||
| .idea | ||
| *.iws | ||
| *.iml | ||
| *.ipr | ||
|
|
||
| ### NetBeans ### | ||
| nbproject/private/ | ||
| build/ | ||
| nbbuild/ | ||
| dist/ | ||
| nbdist/ | ||
| .nb-gradle/ | ||
|
|
||
| #Config | ||
| config.service.ts | ||
| config.json | ||
|
|
||
| # Other entries | ||
| /Piramal - Shortcut.lnk | ||
| .tern-project | ||
| mvnw | ||
| mvnw.cmd | ||
| .mvn/ | ||
|
|
||
| # Properties | ||
| src/main/environment/admin_local.properties |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package com.iemr.admin.config; | ||
|
|
||
| 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.core.RedisTemplate; | ||
| import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | ||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
| import org.springframework.session.data.redis.config.ConfigureRedisAction; | ||
|
|
||
| import com.iemr.admin.data.user.M_User; | ||
|
|
||
|
|
||
| @Configuration | ||
| @EnableCaching | ||
| public class RedisConfig { | ||
|
|
||
| @Bean | ||
| public ConfigureRedisAction configureRedisAction() { | ||
| return ConfigureRedisAction.NO_OP; | ||
| } | ||
|
|
||
| @Bean | ||
| public RedisTemplate<String, M_User> redisTemplate(RedisConnectionFactory factory) { | ||
| RedisTemplate<String, M_User> template = new RedisTemplate<>(); | ||
| template.setConnectionFactory(factory); | ||
|
|
||
| // Use StringRedisSerializer for keys (userId) | ||
| template.setKeySerializer(new StringRedisSerializer()); | ||
|
|
||
| // Use Jackson2JsonRedisSerializer for values (Users objects) | ||
| Jackson2JsonRedisSerializer<M_User> serializer = new Jackson2JsonRedisSerializer<>(M_User.class); | ||
| template.setValueSerializer(serializer); | ||
|
|
||
| return template; | ||
| } | ||
sandipkarmakar3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/iemr/admin/repository/user/UserLoginRepo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.iemr.admin.repository.user; | ||
|
|
||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.CrudRepository; | ||
| import org.springframework.data.repository.query.Param; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import com.iemr.admin.data.user.M_User; | ||
|
|
||
| @Repository | ||
| public interface UserLoginRepo extends CrudRepository<M_User, Long> { | ||
sandipkarmakar3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Query(" SELECT u FROM M_User u WHERE u.userID = :userID AND u.Deleted = false ") | ||
| public M_User getUserByUserID(@Param("userID") Long userID); | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.iemr.admin.utils; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import jakarta.servlet.http.Cookie; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
|
|
||
| @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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.iemr.admin.utils; | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.