-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor security implementation and other minors (#58)
- Loading branch information
1 parent
523e865
commit aa99fc3
Showing
16 changed files
with
92 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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 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
2 changes: 1 addition & 1 deletion
2
commons/src/main/java/io/flowinquiry/modules/fss/service/ResourceRemoveListener.java
This file contains 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
2 changes: 1 addition & 1 deletion
2
...uiry/modules/fss/ResourceRemoveEvent.java → ...ss/service/event/ResourceRemoveEvent.java
This file contains 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
9 changes: 9 additions & 0 deletions
9
commons/src/main/java/io/flowinquiry/modules/shared/Constants.java
This file contains 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,9 @@ | ||
package io.flowinquiry.modules.shared; | ||
|
||
/** Application constants. */ | ||
public final class Constants { | ||
|
||
public static final String DEFAULT_LANGUAGE = "en"; | ||
|
||
private Constants() {} | ||
} |
This file contains 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
2 changes: 1 addition & 1 deletion
2
commons/src/main/java/io/flowinquiry/modules/teams/controller/TeamController.java
This file contains 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 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
2 changes: 1 addition & 1 deletion
2
.../src/main/java/io/flowinquiry/modules/usermanagement/controller/PublicUserController.java
This file contains 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
14 changes: 0 additions & 14 deletions
14
commons/src/main/java/io/flowinquiry/security/Constants.java
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
commons/src/main/java/io/flowinquiry/security/service/JwtService.java
This file contains 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,60 @@ | ||
package io.flowinquiry.security.service; | ||
|
||
import static io.flowinquiry.security.SecurityUtils.AUTHORITIES_KEY; | ||
import static io.flowinquiry.security.SecurityUtils.JWT_ALGORITHM; | ||
import static io.flowinquiry.security.SecurityUtils.USER_ID; | ||
|
||
import io.flowinquiry.modules.usermanagement.service.dto.FwUserDetails; | ||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.oauth2.jwt.JwsHeader; | ||
import org.springframework.security.oauth2.jwt.JwtClaimsSet; | ||
import org.springframework.security.oauth2.jwt.JwtEncoder; | ||
import org.springframework.security.oauth2.jwt.JwtEncoderParameters; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class JwtService { | ||
private final JwtEncoder jwtEncoder; | ||
|
||
@Value("${flowinquiry.security.authentication.jwt.token-validity-in-seconds:0}") | ||
private long tokenValidityInSeconds; | ||
|
||
public JwtService(JwtEncoder jwtEncoder) { | ||
this.jwtEncoder = jwtEncoder; | ||
} | ||
|
||
public String generateToken(Authentication authentication) { | ||
return generateToken( | ||
((FwUserDetails) authentication.getPrincipal()).getUserId(), | ||
authentication.getName(), | ||
authentication.getAuthorities()); | ||
} | ||
|
||
public String generateToken( | ||
Long userId, String email, Collection<? extends GrantedAuthority> grantedAuthorities) { | ||
String authorities = | ||
grantedAuthorities.stream() | ||
.map(GrantedAuthority::getAuthority) | ||
.collect(Collectors.joining(" ")); | ||
|
||
Instant now = Instant.now(); | ||
Instant validity = now.plus(this.tokenValidityInSeconds, ChronoUnit.SECONDS); | ||
JwtClaimsSet claims = | ||
JwtClaimsSet.builder() | ||
.issuedAt(now) | ||
.expiresAt(validity) | ||
.subject(email) | ||
.claim(AUTHORITIES_KEY, authorities) | ||
.claim(USER_ID, userId) | ||
.build(); | ||
|
||
JwsHeader jwsHeader = JwsHeader.with(JWT_ALGORITHM).build(); | ||
return this.jwtEncoder.encode(JwtEncoderParameters.from(jwsHeader, claims)).getTokenValue(); | ||
} | ||
} |
This file contains 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 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
Binary file not shown.
This file contains 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 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