There are a number of authentication libraries that already exist which cover many use cases. It'd be best to use something that's well established in the community.
Secure Social - This seems to be the most popular, with lots of documentation. (For both java and scala)
Deadbolt 2 - There are many implementation examples linked from that git repo. It seems a little more geared for java.
Play2 Auth - This is for scala only, but it is well documented and very flexible. (I personally use Play2 Auth)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…