Easyopen1.4.0 started to support custom session management. Create session
After successful login, create session and return to SessionID
Custom session
@PostMapping ("Managedsessionlogin") public
String Managedsessionlogin (httpservletrequest Request) {
//Assuming the login succeeds, create a SessionID return to the client
sessionmanager SessionManager = Apicontext.getapiconfig (). Getsessionmanager ();
HttpSession session = Sessionmanager.getsession (null);
Session.setattribute ("username", "Tom");
return Session.getid ();
}
Use session
The client needs to pass the Access_token parameter with a value of SessionID
Request Parameters:
{
"Access_token": "4191fb1d8356495d98eccf91c615a530",
"App_key": "Test",
"data": "{}",
"sign": " F7ab6bc059dfca93ca2328c9baf236ba ",
" Sign_method ":" MD5 ",
" name ":" Manager.session.get ",
" format ": "JSON",
"version": "",
"timestamp": "2018-03-13 13:48:45"
}
Service side via HttpSession session = Apicontext.getmanagedsession (); Get session
@Api (name = "Manager.session.get") public
Object managersetsession () {
HttpSession session = Apicontext.getmanagedsession ();
System.out.println (Session.getid ());
Object user = Session.getattribute ("username");
return user;
}
using Redis to manage session
EasyOpen uses Google's guava cache for session management by default, but there is a problem with the cluster, so EasyOpen also provides a redis version. The configuration is as follows: Pom Add Redis dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> Spring-boot-starter-data-redis</artifactid>
</dependency>
Adding Redis Parameters
################ #redis基础配置 #################
spring.redis.database=0
spring.redis.host=10.1.11.48
Spring.redis.password=0987654321rfvujmtgbyhn
spring.redis.port=6379
# Connection time-out unit MS (MS)
spring.redis.timeout=3000
################ #redis线程池设置 #################
# The maximum idle connection in the connection pool, the default value is also 8.
spring.redis.pool.max-idle=500
#连接池中的最小空闲连接, the default value is also 0.
spring.redis.pool.min-idle=50
# If the assignment is 1, it means no limit, and if the pool is already assigned a maxactive Jedis instance, the pool's status is exhausted (exhausted).
spring.redis.pool.max-active=2000
# The maximum time to wait for an available connection, in milliseconds, and the default value is-1, which means never time out. If the wait time is exceeded, the Jedisconnectionexception spring.redis.pool.max-wait=1000 is thrown directly
Set Apiconfig
@Controller @RequestMapping (value = "/api") public class Indexcontroller extends Apicontroller {@Autowired private redistemplate redistemplate;//1 declaring Redis template @Override protected void Initapiconfig (Apiconfig apiconfig) {//config key value pair map<string, string> appsecretstore = new hashmap<
String, string> ();
Appsecretstore.put ("Test", "123456");
2 configuration SessionManager Apiconfig.setsessionmanager (new Redissessionmanager (redistemplate));
Apiconfig.addappsecret (Appsecretstore); }
}