{"record":{"id":"02a00c76ef63b4be","repo":"hs-web/hsweb-framework","slug":"embedauthenticationproperties","errorCode":null,"errorMessage":"不支持的授权请求:","messagePattern":"不支持的授权请求:","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/embed/EmbedAuthenticationProperties.java","lineNumber":83,"sourceCode":"\n    public Authentication authenticate(AuthenticationRequest request) {\n        if (MapUtils.isEmpty(users)) {\n            return null;\n        }\n        if (request instanceof PlainTextUsernamePasswordAuthenticationRequest) {\n            PlainTextUsernamePasswordAuthenticationRequest pwdReq = ((PlainTextUsernamePasswordAuthenticationRequest) request);\n            for (EmbedAuthenticationInfo user : users.values()) {\n                if (pwdReq.getUsername().equals(user.getUsername())) {\n                    if (pwdReq.getPassword().equals(user.getPassword())) {\n                        return user.toAuthentication(dataAccessConfigBuilderFactory);\n                    }\n                    return null;\n                }\n            }\n            return null;\n        }\n\n        throw new UnsupportedOperationException(\"不支持的授权请求:\" + request);\n    }\n\n    public Optional<Authentication> getAuthentication(String userId) {\n        return Optional.ofNullable(authentications.get(userId));\n    }\n\n\n}\n","sourceCodeStart":65,"sourceCodeEnd":92,"githubUrl":"https://github.com/hs-web/hsweb-framework/blob/b2cfc85a57c70bf5b5cf6e7edae2d37102652ec8/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/embed/EmbedAuthenticationProperties.java#L65-L92","documentation":"EmbedAuthenticationProperties implements an embedded (config-file based) AuthorizationServer. Its authenticate(request) method only supports the embedded token/username-password request styles; any other GrantRequest type falls through to the final statement and throws UnsupportedOperationException including the request's toString.","triggerScenarios":"Calling embedAuthorizationServer.authenticate(...) with a request type other than the supported embedded ones — e.g. an OAuth2 client-credentials or refresh-token request instead of embedded username/password or token authentication.","commonSituations":"Pointing a generic OAuth2 client at the embedded authorization server; sending new request types after an hsweb upgrade; wiring the embed server where a full OAuth2 authorization server is expected.","solutions":["Only send username/password or token-based grant requests to the embedded authorization server.","Use the full OAuth2 authorization server implementation for other grant types instead of EmbedAuthenticationProperties.","Inspect the request object printed in the message and adjust the client code to construct a supported request type.","Catch UnsupportedOperationException and fall back to the appropriate authentication service."],"exampleFix":"// before\nAuthentication auth = embedAuthorizationServer.authenticate(\n    new ClientCredentialsGrantRequest(clientId, clientSecret)); // throws\n// after\nAuthentication auth = embedAuthorizationServer.authenticate(\n    new UsernamePasswordAuthenticationRequest(username, password));","handlingStrategy":"type-guard","validationCode":"if (!(request instanceof PasswordAuthRequest) && !(request instanceof TokenAuthRequest)) {\n    throw new IllegalArgumentException(\"embed server only supports password/token requests\");\n}","typeGuard":"boolean isSupportedGrant(GrantRequest r) {\n    return r instanceof PasswordAuthRequest || r instanceof TokenAuthRequest;\n}","tryCatchPattern":"try {\n    return embedServer.authenticate(request);\n} catch (UnsupportedOperationException e) {\n    log.warn(\"unsupported auth request for embed server: {}\", e.getMessage());\n    return delegateFullServer.authenticate(request); // fallback\n}","preventionTips":["Only point embedded-token/username-password flows at EmbedAuthenticationProperties.","Route OAuth2 grant types to a full authorization server implementation.","Check the hsweb version's supported request types before sending new grant types to the embed server."],"tags":["java","unsupported-operation","authentication","oauth"],"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"}