cancel
Showing results for 
Search instead for 
Did you mean: 

Unauthorized in cap java service

davecor
Explorer
0 Kudos
328

Following a tutorial, in my cap java project I try to configure the authorization using mock data.

Below the data modified.

service.cds

using { sap.capire.bookstore as db } from '../db/schema';<br>// Define Books Service<br>service BooksService {<br>    entity Books as projection   on db.Books { *, category as genre } excluding { category, createdBy, createdAt, modifiedBy, modifiedAt };<br>    entity Authors as projection on db.Authors;<br>}<br>// Define Orders Service<br>service OrdersService {<br>    entity Orders as projection on db.Orders;<br>    entity OrderItems as projection on db.OrderItems;<br>}<br>// Reuse Admin Service<br>using { AdminService } from '@sap/capire-products';<br>extend service AdminService with {<br>    entity Authors as projection on db.Authors;<br>}<br>annotate AdminService @(requires: 'Administrators');<br>annotate BooksService @(requires: 'Administrators');

application.yml

---<br>spring:<br>  config.activate.on-profile: default<br>cds:<br>  datasource:<br>    auto-config.enabled: false<br>  security:<br>    mock:<br>      users:<br>        - name: jon<br>          password: pass_jon<br>          roles:<br>            - Administrators<br>          additional:<br>            firstName: jon<br>            lastName: jon<br>            email: jon.jr@mail.com

http requestes

### get Authors<br>GET http://localhost:8080/odata/v4/BooksService/Authors<br>Accept: application/json<br>Authorization: Basic jon:pass_jon<br>### Read Products<br>GET http://localhost:8080/odata/v4/AdminService/Products<br>Accept: application/json<br>Authorization: Basic jon:pass_jon

Why the endpoint that need Adminsitrator role return me 401?

thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

marcbecker
Product and Topic Expert
Product and Topic Expert
0 Kudos

In your configuration you set "jon_davide" as password, but in your requests you use "pass_jon" as password. You need to make sure that both are the same.

davecor
Explorer
0 Kudos

Thanks to answer me, it's a typo to not show the password, but in the original project it is correct.

In any case the error persists and I can't figure out what's wrong...