当前位置: 首页 > 知识库问答 >
问题:

扩展Jhipster JWT(Spring)整体应用程序以支持模拟

郗阳德
2023-03-14

我生成了一个使用JWT身份验证的jhipster角/html" target="_blank">java应用程序。

我现在想扩展应用程序以支持模拟。

我有兴趣实现以下目标:

>

  • 管理员模拟:允许管理员用户以任何其他用户的身份登录

    授予用户的冒充:允许已被授予冒充用户(由用户本身授予)的权利的另一个用户以该其他用户的身份登录。

    审核-记录更改(审核功能)-审核跟踪必须能够区分实际用户和模拟用户,并将其记录在审核跟踪中。

    我知道Spring支持模拟,但考虑到使用了JWT,我不清楚如何在Jhipster应用程序中正确实现它。我不确定Spring路线是否适合JHipster JWT Monolith应用程序-我认为这不是正确的方法。

    虽然在其他各种帖子上有一些不完整的信息,但经过广泛的搜索,我一直找不到一个帖子可以提供关于这方面的清晰的逐步指导。如果有人能为我做到这一点,我将不胜感激。我希望其他人也会发现这样的答案非常有用。

    先谢谢你,费戈

  • 共有1个答案

    鲁博赡
    2023-03-14

    您只需要在UserJwtController中添加以下方法。JAVA

    @PostMapping("/authenticate-externalnodes")
        public ResponseEntity<JWTToken> authenticateExternalnodes(@Valid @RequestBody LoginVM loginVM) {
            // Get Roles for user via username
            Set<Authority> authorities = userService.getUserWithAuthoritiesByLogin(loginVM.getUsername()).get()
                    .getAuthorities();
            // Create Granted Authority Rules
            Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
            for (Authority authority : authorities) {
                grantedAuthorities.add(new SimpleGrantedAuthority(authority.getName()));
            }
            UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
                    loginVM.getUsername(), "", grantedAuthorities);
            Authentication authentication = authenticationToken;
            SecurityContextHolder.getContext().setAuthentication(authentication);
            boolean rememberMe = (loginVM.isRememberMe() == null) ? false : loginVM.isRememberMe();
            String jwt = tokenProvider.createToken(authentication, rememberMe);
            HttpHeaders httpHeaders = new HttpHeaders();
            httpHeaders.add(JWTFilter.AUTHORIZATION_HEADER, "Bearer " + jwt);
            return new ResponseEntity<>(new JWTToken(jwt), httpHeaders, HttpStatus.OK);
        }
    
     类似资料:
    • The following interfaces define the APIs for extending tests at various points in the test execution lifecycle. Consult the following sections for examples and the Javadoc for each of these interfaces

    • Electron 支持 Chrome 扩展API的子集, 主要是支持 DevTools 扩展和 Chromium-internal 扩展,但它同时也支持一些其他扩展能。 注意:Electron 不支持商店中的任意 Chrome 扩展,Electron 项目的目标不是与 Chrome 的扩展实现完全兼容。 加载扩展 Electron 只支持加载未打包的扩展 (即不能使用 .crx 文件)。 插件会被

    • 我正在做一个项目,该项目将有许多JavaFX应用程序,这些应用程序具有相似但又足够不同的功能,因此我创建了一个抽象基类来扩展Application以处理常见的功能并指示它们需要做什么,还创建了一系列具体的类来扩展这些功能。然而,当我试图跑的时候,我得到 应用程序构造函数java.lang.Reflect.InvocationTargetException位于java.base/jdk.intern

    • Node.js以单线程模式运行,但它使用事件驱动的范例来处理并发。 它还有助于创建子进程,以便在基于多核CPU的系统上利用并行处理。 子进程总是有三个流child.stdin , child.stdout和child.stderr ,它们可以与父进程的stdio流共享。 Node提供了child_process模块,该模块具有以下三种创建子进程的主要方法。 exec - child_process

    • 我正在Django上做类似ERP的小项目,其中包含不同的应用程序(产品、销售、采购、会计、MRP、...)。其中一些有依赖关系(例如,销售应用程序需要产品应用程序)。 继承或抽象类似乎也是不合适的,因为我不是试图为子产品创建模型,而是在表中现有信息(条目)的基础上进行增长或扩展。 实现这一点的最佳方法是什么?我应该考虑编写自定义迁移操作吗?否则,还有更好的办法吗?谢谢!

    • 我尝试扩展ISOSTS XSD方案以支持SVG图像标记。我找到了用于SVG的XSD方案,并将其放在附近。现在我尝试扩展: 但是我在尝试加载方案时出错: 怎么啦?