{"record":{"id":"49296f9f03fc5cc3","repo":"hs-web/hsweb-framework","slug":"unsupportedtwofactorvalidator","errorCode":null,"errorMessage":"不支持的验证规则:","messagePattern":"不支持的验证规则:","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/twofactor/defaults/UnsupportedTwoFactorValidator.java","lineNumber":19,"sourceCode":"package org.hswebframework.web.authorization.twofactor.defaults;\n\nimport lombok.AllArgsConstructor;\nimport lombok.Getter;\nimport org.hswebframework.web.authorization.twofactor.TwoFactorValidator;\n\n/**\n * @author zhouhao\n * @since 3.0.4\n */\n@AllArgsConstructor\npublic class UnsupportedTwoFactorValidator implements TwoFactorValidator {\n\n    @Getter\n    private String provider;\n\n    @Override\n    public boolean verify(String code, long timeout) {\n        throw new UnsupportedOperationException(\"不支持的验证规则:\" + provider);\n    }\n\n    @Override\n    public boolean expired() {\n        throw new UnsupportedOperationException(\"不支持的验证规则:\" + provider);\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/hs-web/hsweb-framework/blob/b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/twofactor/defaults/UnsupportedTwoFactorValidator.java#L1-L27","documentation":"UnsupportedTwoFactorValidator is a placeholder implementation of TwoFactorValidator used when no real two-factor provider is registered for the configured provider name. Both verify() and expired() unconditionally throw UnsupportedOperationException, embedding the provider name in the message. It signals that the requested two-factor validation rule does not exist.","triggerScenarios":"Calling TwoFactorValidatorProvider.verify(code, timeout) or expired() when the two-factor provider resolved by name is this fallback stub — i.e. the configured provider string does not match any registered validator.","commonSituations":"Misconfigured two-factor provider name in application properties; a two-factor provider module/dependency not on the classpath; calling the API before a custom TwoFactorValidator bean is registered.","solutions":["Check the provider name configured for two-factor authentication and correct it to a registered provider (e.g. 'default').","Ensure the module containing the actual TwoFactorValidator implementation (e.g. hsweb-authorization-token or a custom one) is a dependency and its bean is registered.","Register a custom TwoFactorValidator bean for the provider name your application uses.","Wrap verify()/expired() calls in try-catch for UnsupportedOperationException to fail gracefully with a clear message."],"exampleFix":"// before\ntwo-factor:\n  provider: sms   # no provider registered under 'sms'\n// after\ntwo-factor:\n  provider: default   # matches a registered TwoFactorValidator bean","handlingStrategy":"try-catch","validationCode":"// check the provider is real before use\nif (validator instanceof UnsupportedTwoFactorValidator) {\n    throw new IllegalStateException(\"two-factor provider not configured: \" + providerName);\n}","typeGuard":"boolean isRealValidator(TwoFactorValidator v) {\n    return !(v instanceof UnsupportedTwoFactorValidator);\n}","tryCatchPattern":"try {\n    boolean ok = validator.verify(code, timeout);\n} catch (UnsupportedOperationException e) {\n    log.error(\"two-factor provider unavailable: {}\", e.getMessage());\n    throw new AuthenticationException(\"two-factor validation unavailable\", e);\n}","preventionTips":["Verify the configured provider name matches a registered TwoFactorValidator bean at startup.","Include the two-factor implementation module in dependencies.","Add a startup health check that asserts the validator is not the unsupported stub."],"tags":["java","unsupported-operation","two-factor","configuration"],"backgroundTag":"unsupported-operation","analyzedSha":"b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8","analyzedAt":"2026-09-13T09:05:02.172Z","contentChangedAt":"2026-09-13T09:05:02.172Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}