{"record":{"id":"bd3e72bd2163b0fc","repo":"dromara/Sa-Token","slug":"error-bd3e72","errorCode":null,"errorMessage":"当前会话未登录","messagePattern":"当前会话未登录","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sa-token-demo/sa-token-demo-sso/sa-token-demo-sso3-client-resdk/src/main/java/com/pj/resdk/StpLogicForHttpSession.java","lineNumber":40,"sourceCode":"     *\n     */\n    public StpLogicForHttpSession(String type) {\n        super(type);\n    }\n\n    // 判断当前会话是否已登录\n    @Override\n    public boolean isLogin() {\n\n        return SpringMVCUtil.getRequest().getSession().getAttribute(\"userId\") != null;\n    }\n\n    // 获取当前会话的登录ID\n    @Override\n    public Object getLoginId() {\n        Object userId = SpringMVCUtil.getRequest().getSession().getAttribute(\"userId\");\n        if(userId == null) {\n            throw new RuntimeException(\"当前会话未登录\");\n        }\n        return userId;\n    }\n\n    // 获取当前登录设备 id\n    @Override\n    public String getLoginDeviceId() {\n        return null;\n    }\n\n    // 当前会话注销\n    @Override\n    public void logout(SaLogoutParameter logoutParameter) {\n        SpringMVCUtil.getRequest().getSession().removeAttribute(\"userId\");\n    }\n\n    // 当前账号id注销\n    @Override","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/dromara/Sa-Token/blob/ac2c7f6e94a78573cf0bcb932dd8b04e68fad189/sa-token-demo/sa-token-demo-sso/sa-token-demo-sso3-client-resdk/src/main/java/com/pj/resdk/StpLogicForHttpSession.java#L22-L58","documentation":"RuntimeException thrown by the SSO3 client demo's StpLogicForHttpSession.getLoginId() when the HttpSession attribute \"userId\" is absent. This demo replaces sa-token's default token logic with one backed purely by the Servlet HttpSession, so 'logged in' means session attribute userId != null; getLoginId() has no fallback and fails hard when unset.","triggerScenarios":"Calling StpUtil.getLoginId() (delegating to this StpLogic) on a session where login(userId) was never called, the session timed out, the session was invalidated (logout), or the request arrives without the JSESSIONID cookie (new session each time).","commonSituations":"SSO3-client demo accessed in a browser with cookies blocked; server restart losing in-memory sessions; calling getLoginId in a filter that runs before the SSO ticket exchange sets userId.","solutions":["Guard with isLogin() before calling getLoginId() — the sibling method returns a boolean for exactly this check.","Complete the SSO login flow (ticket validation) so the session attribute userId gets set before protected pages call getLoginId().","Ensure the JSESSIONID cookie is sent (same-domain or proper cookie config) so the session persists across requests.","Increase session timeout or use persistent sessions if restarts are frequent in dev."],"exampleFix":"// before\nObject userId = StpUtil.getLoginId(); // throws when not logged in\n\n// after\nif (!StpUtil.isLogin()) {\n    response.sendRedirect(\"/sso/login?back=\" + URLUtil.encode(currentUrl));\n    return;\n}\nObject userId = StpUtil.getLoginId();","handlingStrategy":"validation","validationCode":"if (!StpUtil.isLogin()) { // delegates to session attribute check, returns boolean\n    // redirect to SSO login instead of calling getLoginId()\n}\nObject userId = StpUtil.getLoginId();","typeGuard":"boolean isLoggedIn() { return SpringMVCUtil.getRequest().getSession().getAttribute(\"userId\") != null; }","tryCatchPattern":"try { Object id = StpUtil.getLoginId(); } catch (RuntimeException e) { if (\"当前会话未登录\".equals(e.getMessage())) { /* redirect to login */ } }","preventionTips":["Always pair this StpLogic's getLoginId with an isLogin check — the session-backed demo has no token auto-renewal.","Ensure cookies (JSESSIONID) are enabled end-to-end; each new session without login yields this error."],"tags":["sso","httpsession","not-login","demo"],"backgroundTag":null,"analyzedSha":"ac2c7f6e94a78573cf0bcb932dd8b04e68fad189","analyzedAt":"2026-08-14T14:36:10.271Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}