Skip to content

Instantly share code, notes, and snippets.

View greenyleaf's full-sized avatar

whatsABetterNick greenyleaf

View GitHub Profile
@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),
@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 / 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 / china-national-radio.m3u8
Last active April 9, 2021 05:18
China National Radio streams
#EXTM3U
#EXTINF:60,中国之声
#EXTVLCOPT:network-caching=1000
http://ngcdn001.cnr.cn/live/zgzs/index.m3u8
#EXTINF:60,中国之声 low resolution
#EXTVLCOPT:network-caching=1000
http://ngcdn001.cnr.cn/live/zgzs48/index.m3u8
#EXTINF:60,经济之声
#EXTVLCOPT:network-caching=1000
http://ngcdn002.cnr.cn/live/jjzs/index.m3u8
@greenyleaf
greenyleaf / ajax-file-upload.js
Last active March 29, 2021 12:30
Upload files using ajax. Using FormData only if there are file fields in the form, to reduce the upload size when not needed.
$.ajax('http://custom.sdrkyj.top/form-action-url', {
contentType: hasFiles ? false : undefined,
data: hasFiles ? new FormData(formDom) : $(formDom).serialize(),
method: 'post',// 'patch'
dataType: 'json',
processData: !hasFiles,
xhr: function () {
let xhr = $.ajaxSettings.xhr();
hasFiles && xhr.upload.addEventListener('progress', function (e) {
if (e.lengthComputable && e.total > 1 << 17) {
@greenyleaf
greenyleaf / AccessInterceptor.java
Last active June 19, 2020 11:47
an interceptor in Spring MVC for logging user access, using DAO persistence and Logback logging. Process the forwarded request.
package top.sdrkyj.custom.config;
import top.sdrkyj.custom.entity.AccessLog;
import top.sdrkyj.custom.entity.Account;
import top.sdrkyj.custom.service.AccessLogService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@greenyleaf
greenyleaf / CkMsg.java
Last active June 19, 2020 12:53
Response entity class for returning messages after uploading files from CKEditor 4.
package top.sdrkyj.custom.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
public class CkMsg {
/**
* null is permitted。 the filename for the uploaded file
*/
private String fileName;
@greenyleaf
greenyleaf / InvoiceDao.java
Last active June 19, 2020 12:30
a MyBatis DAO interface, CRUD
package top.sdrkyj.custom.dao;
import top.sdrkyj.custom.entity.Invoice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
@greenyleaf
greenyleaf / WxController.java
Last active June 19, 2020 13:27
a Spring controller for Weixin(wechat) page authorization, enhanced security.
package top.sdrkyj.custom.controller;
import top.sdrkyj.custom.config.WxAuthInterceptor;
import top.sdrkyj.custom.dto.RestMsg;
import top.sdrkyj.custom.entity.weixin.WxUserInfo;
import top.sdrkyj.custom.service.WxService;
import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@greenyleaf
greenyleaf / WxService.java
Created June 19, 2020 13:27
a Spring service for Weixin(wechat) oauth2
package top.sdrkyj.custom.service;
import com.alibaba.fastjson.JSON;
import top.sdrkyj.custom.dao.weixin.WxUserInfoDao;
import top.sdrkyj.custom.entity.weixin.WxAccessToken;
import top.sdrkyj.custom.entity.weixin.WxUserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;