优化jwt

This commit is contained in:
zhouhao
2017-08-31 00:00:36 +08:00
parent a932d5171e
commit 851e66fbe2
7 changed files with 52 additions and 6 deletions

View File

@@ -24,7 +24,7 @@ public class SessionIdUserTokenGenerator implements UserTokenGenerator ,Serializ
if(null==request)throw new UnsupportedOperationException();
int timeout =request.getSession().getMaxInactiveInterval();
int timeout =request.getSession().getMaxInactiveInterval()*1000;
String sessionId = request.getSession().getId();

View File

@@ -0,0 +1,28 @@
package org.hswebframework.web.authorization.jwt;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author zhouhao
*/
@Configuration
public class JwtAutoConfiguration {
@Bean
@ConfigurationProperties(prefix = "hsweb.authorize.jwt")
public JwtConfig jwtConfig(){
return new JwtConfig();
}
@Bean
public JwtTokenGenerator jwtTokenGenerator(JwtConfig config){
return new JwtTokenGenerator(config);
}
@Bean
public JwtTokenParser jwtTokenParser(JwtConfig config){
return new JwtTokenParser(config);
}
}

View File

@@ -11,20 +11,18 @@ import org.hswebframework.web.authorization.basic.web.UserTokenGenerator;
import org.hswebframework.web.id.IDGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* Created by zhouhao on 2017/8/30.
*
*/
public class JwtTokenGenarator implements UserTokenGenerator {
public class JwtTokenGenerator implements UserTokenGenerator {
private JwtConfig jwtConfig;
public JwtTokenGenarator(JwtConfig jwtConfig) {
public JwtTokenGenerator(JwtConfig jwtConfig) {
this.jwtConfig = jwtConfig;
}
@@ -43,6 +41,7 @@ public class JwtTokenGenarator implements UserTokenGenerator {
String jwtToken = createJWT(jwtConfig.getId(),token,jwtConfig.getTtl());
String refreshToken = createJWT(jwtConfig.getId(),token,jwtConfig.getRefreshTtl());
int timeout = jwtConfig.getTtl();
return new TokenResult() {

View File

@@ -0,0 +1,3 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.hswebframework.web.authorization.jwt.JwtAutoConfiguration

View File

@@ -120,6 +120,12 @@
<artifactId>hsweb-authorization-basic</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-authorization-jwt</artifactId>
<version>${project.version}</version>
</dependency>
<!--组织架构-->
<dependency>

View File

@@ -1,6 +1,7 @@
package org.hswebframework.web.example.simple;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.codec.digest.DigestUtils;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.Permission;
import org.hswebframework.web.authorization.annotation.Authorize;
@@ -20,6 +21,7 @@ import org.hswebframework.web.service.QueryByEntityService;
import org.hswebframework.web.service.QueryService;
import org.springframework.web.bind.annotation.*;
import java.util.Base64;
import java.util.List;
@@ -133,4 +135,9 @@ public class TestController implements QueryController<UserEntity, String, Query
return null;
}
}
public static void main(String[] args) {
String id =org.apache.commons.codec.binary.Base64.encodeBase64String("test".getBytes());
System.out.println(id);
}
}

View File

@@ -17,6 +17,9 @@ spring:
hsweb:
authorize:
jwt:
id: test
secret: dGVzdA==
# filters:
# "/swagger-ui.html": "authc"
app: