Skip to content

Instantly share code, notes, and snippets.

View greenyleaf's full-sized avatar

whatsABetterNick greenyleaf

View GitHub Profile
@greenyleaf
greenyleaf / CustomRealm.java
Created June 14, 2020 07:54
customized Apache Shiro, Remember Me Manager code, persistent storage based on Spring-myBatis JDBC
package top.sdrkyj.custom.shiro;
import top.sdrkyj.custom.entity.Account;
import top.sdrkyj.custom.entity.Role;
import top.sdrkyj.custom.service.AccountService;
import top.sdrkyj.custom.service.PermissionService;
import top.sdrkyj.custom.service.RoleService;
import org.apache.commons.codec.binary.Base64;
import org.apache.shiro.authc.*;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
@greenyleaf
greenyleaf / CustomRemeberMeManager.java
Created June 14, 2020 07:40
customized Apache Shiro, Remember Me Manager code, with spring-mybatis JDBC based persistent login, references some posts on Stackoverflow.
package top.sdrkyj.custom.shiro;
import top.sdrkyj.custom.entity.Account;
import top.sdrkyj.custom.entity.PersistentLogin;
import top.sdrkyj.custom.service.PersistentLoginService;
import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.Sha512Hash;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.SimplePrincipalCollection;
@greenyleaf
greenyleaf / persistent_logins.ddl.sql
Last active June 14, 2020 07:49
the persistent_logins table in MySQL, references Spring Security's, and some posts on Stackoverflow.
create table persistent_logins
(
id bigint auto_increment
primary key,
account_id char(32) not null,
series char(48) not null comment 'generated user identity, 生成的用户标识',
token char(128) not null comment 'the hashed token used for login, 哈希后的登录令牌',
last_used timestamp default CURRENT_TIMESTAMP not null,
constraint persistent_logins_series_uindex
unique (series),