Add OpenAPI documentation generation and update security configuration
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -33,3 +33,4 @@ build/
|
||||
.vscode/
|
||||
/generated/
|
||||
/.mvn/
|
||||
/app/
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 1. Spring Boot starten
|
||||
echo "Starte Spring Boot..."
|
||||
./mvnw spring-boot:run &
|
||||
|
||||
# Prozess-ID speichern, um später ggf. zu stoppen
|
||||
SPRING_PID=$!
|
||||
|
||||
# Warten, bis der Server verfügbar ist
|
||||
echo "Warte auf Serverstart..."
|
||||
until curl -s http://localhost:8080/v3/api-docs.yaml -o /dev/null; do
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# 2. OpenAPI-Spezifikation herunterladen
|
||||
echo "Lade OpenAPI-Spezifikation herunter..."
|
||||
curl http://localhost:8080/v3/api-docs.yaml -o openapi.yaml
|
||||
|
||||
# 3. Swift-Client generieren
|
||||
echo "Generiere Swift-Client..."
|
||||
openapi-generator-cli generate -i openapi.yaml -g swift5 -o app/ios-api
|
||||
|
||||
# 4. Kotlin-Client generieren
|
||||
echo "Generiere Kotlin-Client..."
|
||||
openapi-generator-cli generate -i openapi.yaml -g kotlin -o app/android-api
|
||||
|
||||
# Optional: Spring Boot stoppen
|
||||
echo "Stoppe Spring Boot..."
|
||||
kill $SPRING_PID
|
||||
|
||||
echo "Fertig!"
|
||||
+642
@@ -0,0 +1,642 @@
|
||||
openapi: 3.1.0
|
||||
info:
|
||||
title: SuMoC API
|
||||
description: API-Dokumentation für SuMoC
|
||||
version: "1.0"
|
||||
servers:
|
||||
- url: http://localhost:8080
|
||||
description: Generated server url
|
||||
security:
|
||||
- bearerAuth: []
|
||||
paths:
|
||||
/user/setVisibilityPrivacy:
|
||||
put:
|
||||
tags:
|
||||
- user-controller
|
||||
summary: Nutzer ändert seine Sichtbarkeits- und Datenschutzeinstellungen
|
||||
description: "Ein Nutzer kann seine Sichtbarkeits- und Datenschutzeinstellungen\
|
||||
\ ändern, um zu steuern, wer seine Informationen sehen kann."
|
||||
operationId: setVisibilityPrivacy
|
||||
parameters:
|
||||
- name: visibilityPrivacy
|
||||
in: query
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
enum:
|
||||
- NONE
|
||||
- FRIENDS_ONLY
|
||||
- PUBLIC
|
||||
responses:
|
||||
"200":
|
||||
description: Sichtbarkeits- und Datenschutzeinstellungen erfolgreich geändert
|
||||
content:
|
||||
application/json: {}
|
||||
"400":
|
||||
description: Ungültige Eingabedaten
|
||||
content:
|
||||
application/json: {}
|
||||
/user/setPrivateName/{id}:
|
||||
put:
|
||||
tags:
|
||||
- user-controller
|
||||
summary: Update a users private name.
|
||||
description: A user can change it's own private name that is shown to friends.
|
||||
operationId: setPrivateName
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
- name: newPrivateName
|
||||
in: query
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
/user/setPassword/{id}:
|
||||
put:
|
||||
tags:
|
||||
- user-controller
|
||||
summary: Nutzer ändert sein Passwort
|
||||
description: "Ein Nutzer kann sein Passwort ändern, um die Sicherheit seines\
|
||||
\ Kontos zu gewährleisten."
|
||||
operationId: setPassword
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
- name: newPassword
|
||||
in: query
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: Passwort erfolgreich geändert
|
||||
content:
|
||||
application/json: {}
|
||||
"400":
|
||||
description: Ungültige Eingabedaten
|
||||
content:
|
||||
application/json: {}
|
||||
/user/setEmail/{id}:
|
||||
put:
|
||||
tags:
|
||||
- user-controller
|
||||
summary: Nutzer ändert seine E-Mail-Adresse
|
||||
description: "Ein Nutzer kann seine E-Mail-Adresse ändern, um sicherzustellen,\
|
||||
\ dass seine Kontaktdaten aktuell sind."
|
||||
operationId: setEmail
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
- name: newEmail
|
||||
in: query
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: E-Mail-Adresse erfolgreich geändert
|
||||
content:
|
||||
application/json: {}
|
||||
"400":
|
||||
description: Ungültige Eingabedaten
|
||||
content:
|
||||
application/json: {}
|
||||
/trip/uploadTrip:
|
||||
post:
|
||||
tags:
|
||||
- trip-controller
|
||||
summary: User uploads a new trip from the App.
|
||||
operationId: uploadTrip
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/NewTripDTO"
|
||||
required: true
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
/routing/alternative/request:
|
||||
post:
|
||||
tags:
|
||||
- routing-alternative-controller
|
||||
operationId: requestAlternativeRoutes
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/RouteAlternativeRequestDTO"
|
||||
required: true
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'*/*':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/RouteAlternativeDTO"
|
||||
/friendship/unblock/{friendId}:
|
||||
post:
|
||||
tags:
|
||||
- friendship-controller
|
||||
summary: Unblock a user.
|
||||
description: Unblocks the user with friendId for the logged in user.
|
||||
operationId: unblockUser
|
||||
parameters:
|
||||
- name: friendId
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
/friendship/request/{friendId}:
|
||||
post:
|
||||
tags:
|
||||
- friendship-controller
|
||||
summary: Request a friendship with another user.
|
||||
description: Sends a friendship request to another user from the logged in user.
|
||||
operationId: requestFriendship
|
||||
parameters:
|
||||
- name: friendId
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
/friendship/reject/{friendId}:
|
||||
post:
|
||||
tags:
|
||||
- friendship-controller
|
||||
summary: Reject a friendship request.
|
||||
description: Rejects a pending friendship request for the logged in user from
|
||||
user with friendId.
|
||||
operationId: rejectFriendship
|
||||
parameters:
|
||||
- name: friendId
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
/friendship/block/{friendId}:
|
||||
post:
|
||||
tags:
|
||||
- friendship-controller
|
||||
summary: Block a user.
|
||||
description: Blocks the user with friendId for the logged in user.
|
||||
operationId: blockUser
|
||||
parameters:
|
||||
- name: friendId
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
/friendship/accept/{friendId}:
|
||||
post:
|
||||
tags:
|
||||
- friendship-controller
|
||||
summary: Accept a friendship request.
|
||||
description: Accepts a pending friendship request for the logged in user from
|
||||
user with friendId.
|
||||
operationId: acceptFriendship
|
||||
parameters:
|
||||
- name: friendId
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
/auth/user/registration:
|
||||
post:
|
||||
tags:
|
||||
- user-authentication-controller
|
||||
summary: Registriert einen neuen Benutzer
|
||||
description: Erstellt einen neuen Benutzer und gibt die Benutzerdaten zurück
|
||||
operationId: registerUser
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/UserRegistrationDTO"
|
||||
required: true
|
||||
responses:
|
||||
"200":
|
||||
description: Benutzer erfolgreich registriert
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/LoginResponseDTO"
|
||||
"400":
|
||||
description: Ungültige Eingabedaten
|
||||
content:
|
||||
application/json: {}
|
||||
/auth/user/login:
|
||||
post:
|
||||
tags:
|
||||
- user-authentication-controller
|
||||
summary: Authentifiziert einen Benutzer
|
||||
description: Prüft den Benutzernamen und das Passwort und gibt ein JWT zurück
|
||||
operationId: login
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/UserAuthenticationPairDTO"
|
||||
required: true
|
||||
responses:
|
||||
"200":
|
||||
description: Erfolgreiche Anmeldung
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/LoginResponseDTO"
|
||||
"401":
|
||||
description: Ungültiger Benutzername oder Passwort
|
||||
content:
|
||||
application/json: {}
|
||||
/user/profile:
|
||||
get:
|
||||
tags:
|
||||
- user-controller
|
||||
summary: Nutzer fragt sein eigenes Profil an
|
||||
description: "Ein Nutzer kann sein eigenes Profil anfragen, um dessen Informationen\
|
||||
\ einzusehen."
|
||||
operationId: getUser
|
||||
responses:
|
||||
"200":
|
||||
description: Nutzerprofil erfolgreich abgerufen
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/MinimalUserDTO"
|
||||
"404":
|
||||
description: Nutzerprofil nicht gefunden
|
||||
content:
|
||||
application/json: {}
|
||||
/user/profile/{id}:
|
||||
get:
|
||||
tags:
|
||||
- user-controller
|
||||
summary: Nutzer fragt ein fremdes Nutzerprofil an
|
||||
description: "Ein Nutzer kann das Profil eines anderen Nutzers anfragen, um\
|
||||
\ dessen öffentliche Informationen einzusehen."
|
||||
operationId: getUser_1
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
"200":
|
||||
description: Nutzerprofil erfolgreich abgerufen
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/MinimalUserDTO"
|
||||
"404":
|
||||
description: Nutzerprofil nicht gefunden
|
||||
content:
|
||||
application/json: {}
|
||||
/trip/getAllUserTrips:
|
||||
get:
|
||||
tags:
|
||||
- trip-controller
|
||||
summary: Retrieve all trips of the authenticated user.
|
||||
operationId: getAllUserTrips
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'*/*':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/TripDTO"
|
||||
/friendship/blocked:
|
||||
get:
|
||||
tags:
|
||||
- friendship-controller
|
||||
summary: Get all users the logged in user has blocked.
|
||||
description: Returns a list of all users that have been blocked by the logged
|
||||
in user.
|
||||
operationId: blockedUsers
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'*/*':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/MinimalUserDTO"
|
||||
/friendship/all:
|
||||
get:
|
||||
tags:
|
||||
- friendship-controller
|
||||
summary: Return all friendships of the logged in user.
|
||||
description: |2
|
||||
Returns all friendships of all statuses (pending, accepted, rejected, blocked) for the logged in user.
|
||||
A friendship between two users always consists of one or two entries in the database. One for each direction.
|
||||
The user is always the one to whom the status applies.
|
||||
- If A requests friendship from B, B -> A = PENDING, A -> B = REQUESTED
|
||||
- If A accepts friendship from B, B -> A = ACCEPTED, A -> B = ACCEPTED
|
||||
- If A rejects friendship from B, B -> A = REJECTED
|
||||
- If A blocks B, B -> A = BLOCKED
|
||||
Per friendship system logic the logged in user is to whom the statuses apply.
|
||||
Meaning a blocked status indicates that the logged in user has been blocked by the other user.
|
||||
operationId: getFriendships
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'*/*':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/FriendshipDTO"
|
||||
/friendship/accepted:
|
||||
get:
|
||||
tags:
|
||||
- friendship-controller
|
||||
summary: Return all accepted friends of the logged in user.
|
||||
description: Returns all friends with accepted status.
|
||||
operationId: getAcceptedFriendships
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
'*/*':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/FriendshipDTO"
|
||||
/user/delete/{id}:
|
||||
delete:
|
||||
tags:
|
||||
- user-controller
|
||||
summary: Nutzer löscht sein eigenes Profil
|
||||
description: Ein Nutzer kann sein eigenes Profil löschen. Dies entfernt alle
|
||||
seine Daten aus dem System.
|
||||
operationId: deleteUser
|
||||
parameters:
|
||||
- name: id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
"200":
|
||||
description: Nutzerprofil erfolgreich gelöscht
|
||||
content:
|
||||
application/json: {}
|
||||
"404":
|
||||
description: Nutzerprofil nicht gefunden
|
||||
content:
|
||||
application/json: {}
|
||||
/friendship/unfriend/{friendId}:
|
||||
delete:
|
||||
tags:
|
||||
- friendship-controller
|
||||
summary: Unfriend a user.
|
||||
description: Removes an accepted friendship between the logged in user and user
|
||||
with friendId.
|
||||
operationId: unfriend
|
||||
parameters:
|
||||
- name: friendId
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
components:
|
||||
schemas:
|
||||
NewTripDTO:
|
||||
type: object
|
||||
description: DTO for creating a new Trip
|
||||
properties:
|
||||
startPlace:
|
||||
type: string
|
||||
endPlace:
|
||||
type: string
|
||||
startTime:
|
||||
type: string
|
||||
format: date-time
|
||||
endTime:
|
||||
type: string
|
||||
format: date-time
|
||||
mobilityScore:
|
||||
type: number
|
||||
format: float
|
||||
tripSegments:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/NewTripSegmentDTO"
|
||||
maxItems: 2147483647
|
||||
minItems: 1
|
||||
uniqueItems: true
|
||||
required:
|
||||
- tripSegments
|
||||
NewTripSegmentDTO:
|
||||
type: object
|
||||
properties:
|
||||
modality:
|
||||
type: string
|
||||
enum:
|
||||
- IDLE
|
||||
- WALKING
|
||||
- BIKE
|
||||
- ESCOOTER
|
||||
- BUS
|
||||
- TRAM
|
||||
- TRAIN
|
||||
- CAR
|
||||
startTime:
|
||||
type: string
|
||||
format: date-time
|
||||
distanceMeters:
|
||||
type: number
|
||||
format: float
|
||||
RouteAlternativeRequestDTO:
|
||||
type: object
|
||||
RouteAlternativeDTO:
|
||||
type: object
|
||||
UserRegistrationDTO:
|
||||
type: object
|
||||
properties:
|
||||
privateName:
|
||||
type: string
|
||||
publicName:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
password:
|
||||
type: string
|
||||
required:
|
||||
- email
|
||||
- password
|
||||
- privateName
|
||||
- publicName
|
||||
LoginResponseDTO:
|
||||
type: object
|
||||
properties:
|
||||
userDTO:
|
||||
$ref: "#/components/schemas/UserDTO"
|
||||
jwt:
|
||||
type: string
|
||||
UserDTO:
|
||||
type: object
|
||||
properties:
|
||||
userId:
|
||||
type: integer
|
||||
format: int64
|
||||
privateName:
|
||||
type: string
|
||||
publicName:
|
||||
type: string
|
||||
roles:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
enum:
|
||||
- USER
|
||||
- ADMIN
|
||||
uniqueItems: true
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
UserAuthenticationPairDTO:
|
||||
type: object
|
||||
properties:
|
||||
email:
|
||||
type: string
|
||||
password:
|
||||
type: string
|
||||
required:
|
||||
- email
|
||||
- password
|
||||
MinimalUserDTO:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
displayName:
|
||||
type: string
|
||||
TripDTO:
|
||||
type: object
|
||||
properties:
|
||||
tripId:
|
||||
type: integer
|
||||
format: int64
|
||||
userId:
|
||||
type: integer
|
||||
format: int32
|
||||
startPlace:
|
||||
type: string
|
||||
endPlace:
|
||||
type: string
|
||||
startTime:
|
||||
type: string
|
||||
format: date-time
|
||||
endTime:
|
||||
type: string
|
||||
format: date-time
|
||||
mobilityScore:
|
||||
type: number
|
||||
format: float
|
||||
tripSegments:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/TripSegmentDTO"
|
||||
TripSegmentDTO:
|
||||
type: object
|
||||
properties:
|
||||
tripSegmentId:
|
||||
type: integer
|
||||
format: int64
|
||||
tripId:
|
||||
type: integer
|
||||
format: int64
|
||||
modality:
|
||||
type: string
|
||||
enum:
|
||||
- IDLE
|
||||
- WALKING
|
||||
- BIKE
|
||||
- ESCOOTER
|
||||
- BUS
|
||||
- TRAM
|
||||
- TRAIN
|
||||
- CAR
|
||||
startTime:
|
||||
type: string
|
||||
format: date-time
|
||||
distanceMeters:
|
||||
type: number
|
||||
format: float
|
||||
FriendshipDTO:
|
||||
type: object
|
||||
properties:
|
||||
friendshipId:
|
||||
type: integer
|
||||
format: int64
|
||||
userId:
|
||||
type: integer
|
||||
format: int64
|
||||
friend:
|
||||
$ref: "#/components/schemas/MinimalUserDTO"
|
||||
status:
|
||||
type: string
|
||||
enum:
|
||||
- REQUESTED
|
||||
- PENDING
|
||||
- ACCEPTED
|
||||
- REJECTED
|
||||
- BLOCKED
|
||||
createdAt:
|
||||
type: string
|
||||
format: date-time
|
||||
securitySchemes:
|
||||
bearerAuth:
|
||||
type: http
|
||||
name: bearerAuth
|
||||
scheme: bearer
|
||||
bearerFormat: JWT
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
|
||||
"spaces": 2,
|
||||
"generator-cli": {
|
||||
"version": "7.14.0"
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,28 @@
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- SpringDoc plugin to generate OpenAPI spec without running server -->
|
||||
<plugin>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-maven-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-openapi-spec</id>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<apiDocsUrl>http://localhost:8080/v3/api-docs.yaml</apiDocsUrl>
|
||||
<outputFileName>openapi.yaml</outputFileName>
|
||||
<outputDir>${project.basedir}</outputDir>
|
||||
<skip>false</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
|
||||
@@ -88,13 +88,13 @@ public class SecurityConfiguration {
|
||||
.cors(withDefaults())
|
||||
//.authorizeHttpRequests(auth -> auth.anyRequest().permitAll()) //allows Access To ALL APIs, Security is off
|
||||
.authorizeHttpRequests(auth -> {
|
||||
auth.requestMatchers(AUTH_WHITELIST).permitAll();
|
||||
auth.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll();
|
||||
auth.requestMatchers("/auth/user/**").permitAll();
|
||||
auth.requestMatchers("/admin/**").hasRole("ADMIN"); //looks for "ROLE_ADMIN" //alternative: hasAuthoritiy("ADMIN")
|
||||
auth.requestMatchers("/user/**").hasAnyRole("ADMIN", "USER");
|
||||
auth.requestMatchers("/friendship/**").hasAnyRole("ADMIN", "USER");
|
||||
auth.requestMatchers("/trip/**").hasAnyRole("USER", "ADMIN");
|
||||
auth.requestMatchers(AUTH_WHITELIST).permitAll();
|
||||
//auth.requestMatchers("/error").permitAll();
|
||||
auth.anyRequest().authenticated();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user