Skip to content

Commit

Permalink
enhancement/user-badge-added
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-zip committed Jun 1, 2024
1 parent b9f0a0f commit c321687
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.bloggios.authentication-config</groupId>
<artifactId>authentication-configuration-jar</artifactId>
<version>2.0</version>
<version>2.1</version>
<name>authentication-configuration-jar</name>
<description>authentication-configuration-jar</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,18 @@ private void addAuthentication(HttpServletRequest request, String token) {
String userId = jwtDecoderUtil.extractUserId(token);
String email = jwtDecoderUtil.extractEmail(token);
String username = jwtDecoderUtil.extractUsername(token);
String userBadge = jwtDecoderUtil.extractBadge(token);
boolean isBadge = false;
if (StringUtils.hasText(userBadge)) {
isBadge = Boolean.parseBoolean(userBadge);
}
Collection<? extends GrantedAuthority> grantedAuthorities = jwtDecoderUtil.extractAuthorities(token);
authenticatedUser.setUserId(userId);
authenticatedUser.setEmail(email);
authenticatedUser.setAuthorities(grantedAuthorities);
authenticatedUser.setClientIp(jwtDecoderUtil.extractClientIp(token));
authenticatedUser.setUsername(username);
authenticatedUser.setBadge(isBadge);
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(authenticatedUser, null, grantedAuthorities);
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(authentication);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ public class AuthenticatedUser {
private String email;
private String clientIp;
public String username;
private boolean isBadge;
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public String extractUsername(String token) {
}
}

public String extractTokenType(String token) {
public String extractBadge(String token) {
try {
Jwt jwt = jwtDecoder.decode(token);
return jwt.getClaimAsString("type");
return jwt.getClaimAsString("is-badge");
} catch (Exception e) {
logger.error("Exception Occurred while extracting Token Type from token with default message as : {}", e.getMessage());
throw new AuthenticationConfigException("Unable to extract Token Type from the Token");
logger.error("Exception Occurred while extracting User Badge from token with default message as : {}", e.getMessage());
throw new AuthenticationConfigException("Unable to extract User Badge from the Token");
}
}
}

0 comments on commit c321687

Please sign in to comment.