Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger UI does not load while using JWT authentication #25436

Closed
1 task done
jamie87u7 opened this issue Mar 7, 2024 · 1 comment
Closed
1 task done

Swagger UI does not load while using JWT authentication #25436

jamie87u7 opened this issue Mar 7, 2024 · 1 comment

Comments

@jamie87u7
Copy link

Overview of the issue

A microservices app generated based on the sample jdl microservice-ecommerce-store.jdl does not load the Swagger UI under Administration -> API . Two changes were made to the sample JDL (build tool was changed to maven and docker deployment added). The gateway and microservices are running fine using docker compose with entities being created.

The browser (chrome on windows) throws two errors

  1. http://localhost:8080/management/health/discoveryComposite returns 404 not found with request headers below
GET /management/health/discoveryComposite HTTP/1.1
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Host: localhost:8080
Referer: http://localhost:8080/swagger-ui/index.html
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
sec-ch-ua: "Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
  1. http://localhost:8080/management/jhiopenapigroups returns 401 Unauthorized with request headers below
GET /management/jhiopenapigroups HTTP/1.1
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Host: localhost:8080
Referer: http://localhost:8080/swagger-ui/index.html
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
sec-ch-ua: "Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"

There seems to be no Authorization headers set. Swagger UI works when the authentication type is set to oauth2 in the same JDL

Motivation for or Use Case

To use the swagger ui

Reproduce the error
  1. Download microservice-ecommerce-store.jdl
  2. Change build tool from gradle to maven
  3. Add deployment section
deployment {
  deploymentType docker-compose
  serviceDiscoveryType consul
  appsFolders [store, invoice, notification]
}
  1. Generate the app jhipster jdl jhipster-jdl.jdl --monorepository --workspaces
  2. Generate docker images for store, invoice and notification ./mvnw -ntp -Pprod verify jib:dockerBuild
  3. Run docker compose
  4. Login as Admin
  5. Go to Administration -> API
Related issues

Possibly #5501

Suggest a Fix

Total JHipster newbie here. Looking at related issues and their fixes

JHipster Version(s)

8.1.0

JHipster configuration
JDL

/*

  • This is a microservice e-commerce store sample with Gateway and two microservice applications
  • This uses Consul for service discovery
    */

application {
config {
baseName store
applicationType gateway
packageName com.jhipster.demo.store
serviceDiscoveryType consul
authenticationType jwt
prodDatabaseType mysql
cacheProvider no
buildTool maven
clientFramework react
testFrameworks [cypress]
reactive true
}
entities *
}

application {
config {
baseName invoice
applicationType microservice
packageName com.jhipster.demo.invoice
serviceDiscoveryType consul
authenticationType jwt
prodDatabaseType mysql
buildTool maven
serverPort 8081
skipUserManagement true
}
entities Invoice, Shipment
}

application {
config {
baseName notification
applicationType microservice
packageName com.jhipster.demo.notification
serviceDiscoveryType consul
authenticationType jwt
databaseType mongodb
prodDatabaseType mongodb
devDatabaseType mongodb
cacheProvider no
enableHibernateCache false
buildTool maven
serverPort 8082
skipUserManagement true
}
entities Notification
}

/* Entities for Store Gateway */

/** Product sold by the Online store */
entity Product {
name String required
description String
price BigDecimal required min(0)
productSize Size required
image ImageBlob
}

enum Size {
S, M, L, XL, XXL
}

entity ProductCategory {
name String required
description String
}

entity Customer {
firstName String required
lastName String required
gender Gender required
email String required pattern(/^[^@\s]+@[^@\s]+.[^@\s]+$/)
phone String required
addressLine1 String required
addressLine2 String
city String required
country String required
}

enum Gender {
MALE, FEMALE, OTHER
}

entity ProductOrder {
placedDate Instant required
status OrderStatus required
code String required
invoiceId Long
}

enum OrderStatus {
COMPLETED, PENDING, CANCELLED
}

entity OrderItem {
quantity Integer required min(0)
totalPrice BigDecimal required min(0)
status OrderItemStatus required
}

enum OrderItemStatus {
AVAILABLE, OUT_OF_STOCK, BACK_ORDER
}

relationship OneToOne {
Customer{user(login) required} to User with builtInEntity
}

relationship ManyToOne {
OrderItem{product(name) required} to Product
}

relationship OneToMany {
Customer{order} to ProductOrder{customer(email) required},
ProductOrder{orderItem} to OrderItem{order(code) required} ,
ProductCategory{product} to Product{productCategory(name)}
}

service Product, ProductCategory, Customer, ProductOrder, OrderItem with serviceClass
paginate Product, Customer, ProductOrder, OrderItem with pagination

/* Entities for Invoice microservice */
entity Invoice {
code String required
date Instant required
details String
status InvoiceStatus required
paymentMethod PaymentMethod required
paymentDate Instant required
paymentAmount BigDecimal required
}

enum InvoiceStatus {
PAID, ISSUED, CANCELLED
}

entity Shipment {
trackingCode String
date Instant required
details String
}

enum PaymentMethod {
CREDIT_CARD, CASH_ON_DELIVERY, PAYPAL
}

relationship OneToMany {
Invoice{shipment} to Shipment{invoice(code) required}
}

service Invoice, Shipment with serviceClass
paginate Invoice, Shipment with pagination
microservice Invoice, Shipment with invoice

/* Entities for notification microservice */

entity Notification {
date Instant required
details String
sentDate Instant required
format NotificationType required
userId Long required
productId Long required
}

enum NotificationType {
EMAIL, SMS, PARCEL
}

microservice Notification with notification

deployment {
deploymentType docker-compose
serviceDiscoveryType consul
appsFolders [store, invoice, notification]
}

.yo-rc.json file
{
  "generator-jhipster": {
    "appsFolders": [
      "store",
      "invoice",
      "notification"
    ],
    "baseName": "workspaces",
    "clientPackageManager": "npm",
    "directoryPath": "./",
    "dockerCompose": true,
    "jhipsterVersion": "8.1.0",
    "monorepository": true
  }
}
.yo-rc.json file for store
{
  "generator-jhipster": {
    "applicationIndex": 0,
    "applicationType": "gateway",
    "applications": {
      "invoice": {
        "applicationIndex": 1,
        "serverPort": "8081"
      },
      "notification": {
        "applicationIndex": 2,
        "serverPort": "8082"
      }
    },
    "authenticationType": "jwt",
    "baseName": "store",
    "buildTool": "maven",
    "cacheProvider": "no",
    "clientFramework": "react",
    "devServerPort": 9060,
    "entities": [
      "Product",
      "ProductCategory",
      "Customer",
      "ProductOrder",
      "OrderItem",
      "Invoice",
      "Shipment",
      "Notification"
    ],
    "jhipsterVersion": "8.1.0",
    "languages": [
      "en"
    ],
    "lastLiquibaseTimestamp": 1709803308000,
    "monorepository": true,
    "nativeLanguage": "en",
    "packageFolder": "com/jhipster/demo/store",
    "packageName": "com.jhipster.demo.store",
    "prodDatabaseType": "mysql",
    "reactive": true,
    "serviceDiscoveryType": "consul",
    "skipCommitHook": true,
    "testFrameworks": [
      "cypress"
    ]
  }
}
.yo-rc.json file for invoice
{
  "generator-jhipster": {
    "applicationIndex": 1,
    "applicationType": "microservice",
    "authenticationType": "jwt",
    "baseName": "invoice",
    "buildTool": "maven",
    "entities": [
      "Invoice",
      "Shipment"
    ],
    "jhipsterVersion": "8.1.0",
    "languages": [
      "en"
    ],
    "lastLiquibaseTimestamp": 1709802948000,
    "monorepository": true,
    "nativeLanguage": "en",
    "packageFolder": "com/jhipster/demo/invoice",
    "packageName": "com.jhipster.demo.invoice",
    "prodDatabaseType": "mysql",
    "serverPort": "8081",
    "serviceDiscoveryType": "consul",
    "skipClient": true,
    "skipCommitHook": true,
    "skipUserManagement": true
  }
}
.yo-rc.json file for notification
{
  "generator-jhipster": {
    "applicationIndex": 2,
    "applicationType": "microservice",
    "authenticationType": "jwt",
    "baseName": "notification",
    "buildTool": "maven",
    "cacheProvider": "no",
    "databaseType": "mongodb",
    "devDatabaseType": "mongodb",
    "enableHibernateCache": false,
    "entities": [
      "Notification"
    ],
    "jhipsterVersion": "8.1.0",
    "languages": [
      "en"
    ],
    "lastLiquibaseTimestamp": 1709802888000,
    "monorepository": true,
    "nativeLanguage": "en",
    "packageFolder": "com/jhipster/demo/notification",
    "packageName": "com.jhipster.demo.notification",
    "prodDatabaseType": "mongodb",
    "serverPort": "8082",
    "serviceDiscoveryType": "consul",
    "skipClient": true,
    "skipCommitHook": true,
    "skipUserManagement": true
  }
}
Environment and Tools

openjdk version "21.0.1" 2023-10-17 LTS
OpenJDK Runtime Environment Zulu21.30+15-CA (build 21.0.1+12-LTS)
OpenJDK 64-Bit Server VM Zulu21.30+15-CA (build 21.0.1+12-LTS, mixed mode, sharing)

git version 2.42.0.windows.2

node: v20.10.0
npm: 10.2.3

Docker version 25.0.3, build 4debf41

Chrome Version 121.0.6167.189 (Official Build) (64-bit)
Windows 11

  • Checking this box is mandatory (this is just to show you read everything)
@jamie87u7 jamie87u7 changed the title Swagger UI does not load while using a sample jdl with JWT authentication Swagger UI does not load while using JWT authentication Mar 7, 2024
@mraible
Copy link
Contributor

mraible commented Mar 19, 2024

I believe this is fixed on the main branch. I tried your steps to reproduce and was unable to. Screenshots for proof.

Screenshot 2024-03-19 at 8 37 27 AM Screenshot 2024-03-19 at 8 37 33 AM

Please reopen if this is still an issue for you after the 8.2 release.

@mraible mraible closed this as completed Mar 19, 2024
@deepu105 deepu105 added this to the 8.2.0 milestone Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants