Skip to content

Sms Verification Scope Validation

Yugang Zhou edited this page Apr 24, 2019 · 1 revision

什么是Sms Verification Scope (以下简称SVS)

在应用中,可能存在多个功能需要短信验证保护。安全起见,希望验证码专码专用。如,尽管是同一个手机号,短信登录的验证码,和修改密码的验证码,应当独立分开使用。
Daming提供了SVS机制,在请求短信验证码验证短信验证码时,需要指定Scope,见API文档(TODO)

SVS校验机制

为避免User Agent传入非法的SVScom.thebund1st.daming.core.SmsVerificationScopePatternSVS的校验实现提供了抽象,你可以在项目中扩展该接口来定制校验机制。

默认的校验实现

DamingSmsVerificationScopePattern提供了开箱即用的实现StaticSmsVerificationScopePattern,并可以通过配置文件/环境变量设置合法的SVS

# application-{profile}.properties
# 可使用','分隔多个SVS
daming.sms.verification.scope.valid=SMS_LOGIN, VERY_IMPORTANT_OPERATION, ANOTHER

自定义的校验实现

任何注册到Spring ApplicationContextSmsVerificationScopePattern都可以替换Daming的默认实现:

@Component
public class MySmsVerificationScopePattern implements SmsVerificationScopePattern {

    @Override
    public boolean matches(SmsVerificationScope value) {...}
}

Clone this wiki locally