提交 5d4bb1a1 编写于 作者: M ManongJu

OAuth2.0注销

上级 25e4d57d
......@@ -78,8 +78,8 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
tokenServices.setTokenStore(redisTokenStore());
tokenServices.setSupportRefreshToken(true);
tokenServices.setClientDetailsService(clientDetails());
tokenServices.setAccessTokenValiditySeconds(60); // token有效期自定义设置,默认12小时
tokenServices.setRefreshTokenValiditySeconds(60 * 60 * 24 * 30);//默认30天,这里修改
tokenServices.setAccessTokenValiditySeconds(60*60*12); // token有效期自定义设置,默认12小时
tokenServices.setRefreshTokenValiditySeconds(60 * 60 * 24 * 7);//默认30天,这里修改
return tokenServices;
}
......
......@@ -18,7 +18,7 @@ public class HelloController {
@RequestMapping("/hello")
public String hello() {
return "hello";
return "order";
}
@RequestMapping("/login")
public String login() {
......
package com.microservice.skeleton.auth.endpoint;
import com.microservice.skeleton.auth.model.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.endpoint.FrameworkEndpoint;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by Mr.Yangxiufeng on 2018/1/2.
* Time:9:22
* ProjectName:Mirco-Service-Skeleton
*/
@FrameworkEndpoint
public class RevokeTokenEndpoint {
@Autowired
private ConsumerTokenServices consumerTokenServices;
@RequestMapping(value = "/oauth/token", method= RequestMethod.DELETE)
public @ResponseBody
Msg revokeToken(String access_token){
Msg msg = new Msg();
if (consumerTokenServices.revokeToken(access_token)){
msg.setCode(Msg.SUCCESS);
msg.setMsg("注销成功");
}else {
msg.setCode(Msg.FAILED);
msg.setMsg("注销失败");
}
return msg;
}
}
package com.microservice.skeleton.auth.model;
import java.io.Serializable;
/**
* Created by Mr.Yangxiufeng on 2018/1/2.
* Time:9:28
* ProjectName:Mirco-Service-Skeleton
*/
public class Msg implements Serializable{
private static final long serialVersionUID = 7514826298158585250L;
public static final int SUCCESS=200;
public static final int FAILED=201;
private Integer code;
private String msg;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
package com.microservice.skeleton.hello;
package com.microservice.skeleton.order;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......
package com.microservice.skeleton.hello.controller;
package com.microservice.skeleton.order.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
package com.microservice.skeleton.hello;
package com.microservice.skeleton.order;
import org.junit.Test;
import org.junit.runner.RunWith;
......
......@@ -26,8 +26,8 @@
<modules>
<module>register</module>
<module>gateway</module>
<module>hello-service</module>
<module>micro-a-service</module>
<module>user-service</module>
<module>order-service</module>
<module>auth-center</module>
<module>resource</module>
<module>upload-service</module>
......
java -jar .\target\Micro-Service-Skeleton-Register-0.0.1-SNAPSHOT.jar --spring.profiles.active=node-1
\ No newline at end of file
java -jar .\target\Micro-Service-Skeleton-Register-0.0.1-SNAPSHOT.jar --spring.profiles.active=node-2
\ No newline at end of file
......@@ -13,7 +13,7 @@ public class UserController {
@GetMapping(value = "getUser")
public String getUser(){
return "hello";
return "order";
}
}
......@@ -7,23 +7,23 @@ spring:
base-url: http://10.10.8.2:9050
eureka:
instance:
prefer-ip-address: true #使用IP注册
prefer-ip-address: true ��IPע��
instance-id: ${spring.cloud.client.ipAddress}:${server.port}
lease-renewal-interval-in-seconds: 5 ##为了能够快速删除
lease-expiration-duration-in-seconds: 10 ##为了能够快速删除
lease-renewal-interval-in-seconds: 5 ##Ϊ���ܹ�����ɾ��
lease-expiration-duration-in-seconds: 10 ##Ϊ���ܹ�����ɾ��
client:
service-url:
defaultZone: http://register1:9010/eureka/,http://register2:9011/eureka/
###actuator监控点 start####
###actuator��ص� start####
endpoints:
health:
sensitive: false
enabled: true
##默认情况下很多端点是不允许访问的,会返回401:Unauthorized
##Ĭ������ºܶ�˵��Dz�������ʵģ��᷵��401:Unauthorized
management:
security:
enabled: false
###actuator监控点 end####
###actuator��ص� end####
security:
oauth2:
resource:
......
......@@ -21,7 +21,7 @@ public class SimpleController {
@HystrixCommand(fallbackMethod = "helloFallback",commandKey = "getWord",groupKey = "SimpleController",threadPoolKey = "SimplePool")
@CacheResult(cacheKeyMethod = "getKey")
public String getWord(){
return restTemplate.getForEntity("http://order-service/hello",String.class).getBody();
return restTemplate.getForEntity("http://order-service/order",String.class).getBody();
}
private String helloFallback(){
return "error";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册