11package io .jsonwebtoken .jjwtfun .controller ;
22
3- import io .jsonwebtoken .Claims ;
4- import io .jsonwebtoken .Jws ;
53import io .jsonwebtoken .JwtBuilder ;
64import io .jsonwebtoken .JwtException ;
75import io .jsonwebtoken .Jwts ;
86import io .jsonwebtoken .SignatureAlgorithm ;
97import io .jsonwebtoken .impl .compression .CompressionCodecs ;
108import io .jsonwebtoken .jjwtfun .model .JwtResponse ;
11- import org .springframework .beans .factory .annotation .Value ;
9+ import io .jsonwebtoken .jjwtfun .service .SecretService ;
10+ import org .springframework .beans .factory .annotation .Autowired ;
1211import org .springframework .web .bind .annotation .RequestBody ;
1312import org .springframework .web .bind .annotation .RequestMapping ;
14- import org .springframework .web .bind .annotation .RequestParam ;
1513import org .springframework .web .bind .annotation .RestController ;
1614
1715import java .io .UnsupportedEncodingException ;
2018import java .util .Map ;
2119
2220import static org .springframework .web .bind .annotation .RequestMethod .POST ;
23- import static org .springframework .web .bind .annotation .RequestMethod .GET ;
2421
2522@ RestController
2623public class DynamicJWTController extends BaseController {
27- @ Value ("#{ @environment['jjwtfun.secret'] ?: 'secret' }" )
28- String secret ;
24+
25+ @ Autowired
26+ SecretService secretService ;
2927
3028 @ RequestMapping (value = "/dynamic-builder-general" , method = POST )
3129 public JwtResponse dynamicBuilderGeneric (@ RequestBody Map <String , Object > claims ) throws UnsupportedEncodingException {
3230 String jws = Jwts .builder ()
3331 .setClaims (claims )
3432 .signWith (
3533 SignatureAlgorithm .HS256 ,
36- secret . getBytes ( "UTF-8" )
34+ secretService . getHS256Secret ( )
3735 )
3836 .compact ();
3937 return new JwtResponse (jws );
@@ -46,7 +44,7 @@ public JwtResponse dynamicBuildercompress(@RequestBody Map<String, Object> claim
4644 .compressWith (CompressionCodecs .DEFLATE )
4745 .signWith (
4846 SignatureAlgorithm .HS256 ,
49- secret . getBytes ( "UTF-8" )
47+ secretService . getHS256Secret ( )
5048 )
5149 .compact ();
5250 return new JwtResponse (jws );
@@ -91,7 +89,7 @@ public JwtResponse dynamicBuilderSpecific(@RequestBody Map<String, Object> claim
9189 }
9290 });
9391
94- builder .signWith (SignatureAlgorithm .HS256 , secret . getBytes ( "UTF-8" ));
92+ builder .signWith (SignatureAlgorithm .HS256 , secretService . getHS256Secret ( ));
9593
9694 return new JwtResponse (builder .compact ());
9795 }
0 commit comments