简体   繁体   中英

Jhipster swagger ui - permissions

在 Jhipster 中,允许具有角色 ROLE_USE 的用户访问嵌入式 swagger-ui 的最简单方法是什么(也许还允许他们使用通常的授权按钮自动将他们的访问令牌添加到所有请求中)

If you really need to open up this route to regular users, in my opinion the best approach is to move it out of /admin .

First open admin-routing.module.ts and remove the following lines:

      {
        path: 'docs',
        loadChildren: () => import('./docs/docs.module').then(m => m.DocsModule),
      },

Now edit app-routing.module.ts and add the /docs route:

// ...
        },
        {
          path: 'login',
          loadChildren: () => import('./login/login.module').then(m => m.LoginModule),
        },
        {
          path: 'docs',
          data: {
            authorities: [Authority.ADMIN, Authority.USER],
          },
          canActivate: [UserRouteAccessService],
          loadChildren: () => import('./admin/docs/docs.module').then(m => m.DocsModule),
        },
        ...LAYOUT_ROUTES,
      ],
      { enableTracing: DEBUG_INFO_ENABLED }
// ...

Change the old routerLink for the docs menu entry in your navbar.component.html :

          <li *ngIf="openAPIEnabled">
            <a class="dropdown-item" routerLink="docs" routerLinkActive="active" (click)="collapseNavbar()">
              <fa-icon icon="book" [fixedWidth]="true"></fa-icon>
              <span>API</span>
            </a>
          </li>

Now if you access localhost:8080/docs you should be able to use the swagger-ui as a regular user.

This is just the minimal amount of changes you require, some things to keep in mind:

  • You could move the folder \\src\\main\\webapp\\app\\admin\\docs into \\src\\main\\webapp\\app\\docs , just to keep things tidy and coherent. If you do this remember to update the reference in your app-routing.module.ts .

  • You should add a new menu entry in your navbar for regular users to navigate into swagger, this is trivial so I leave it to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM