Skip to content

Commit

Permalink
rename refresh_token & fix ticket permissions (#83)
Browse files Browse the repository at this point in the history
* change refresh-token generation

* return error

* refresh_token -> refresh-token

* refresh_token -> refreshToken

* Dialog fixes.

* Ticket assignment.

* wider assignment button

* changed ticket permissions
  • Loading branch information
snicki13 authored Oct 19, 2021
1 parent 3ed3244 commit 80c6295
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ClassroomApiController(
}.map {
val refreshToken = generateRefreshToken(auth.principal)
// Set refresh_token header
val refreshTokenSet = setHeader("refresh_token", refreshToken, originalExchange)
val refreshTokenSet = setHeader("refreshToken", refreshToken, originalExchange)
// Set Authorization header
setHeader(HttpHeaders.AUTHORIZATION, "Bearer ${auth.credentials}", refreshTokenSet).response
}.doOnNext {
Expand All @@ -61,7 +61,7 @@ class ClassroomApiController(
fun refreshToken(
auth: ClassroomAuthentication,
originalExchange: ServerWebExchange,
@RequestHeader("refresh_token") refreshToken: String
@RequestHeader("refreshToken") refreshToken: String
): Mono<ServerHttpResponse> {
return classroomTokenRepository
.findRefreshToken(refreshToken)
Expand All @@ -71,18 +71,23 @@ class ClassroomApiController(
}.switchIfEmpty(Mono.error(UnauthorizedException("Owner of refresh token does not match requester!")))
.map { user ->
val newRefreshToken = generateRefreshToken(user)
Pair(user, setHeader("refresh_token", newRefreshToken, originalExchange))
Pair(user, setHeader("refreshToken", newRefreshToken, originalExchange))
}.flatMap { (user, exchange) ->
Mono.zip(jwtService.createToken(user), Mono.just(exchange))
}.map { (jwt, exchange) ->
setHeader(HttpHeaders.AUTHORIZATION, "Bearer $jwt", exchange).response
}.doOnNext {
logger.info("${auth.principal} refreshed his JWT!")
}.onErrorResume { error ->
logger.error(error.message)
originalExchange.response.statusCode = HttpStatus.BAD_REQUEST
originalExchange.response.bufferFactory().wrap(error.message!!.encodeToByteArray())
Mono.just(originalExchange.response)
}
}

private fun generateRefreshToken(userCredentials: UserCredentials): String {
val newRefreshToken = RandomStringUtils.randomAscii(30)
val newRefreshToken = RandomStringUtils.randomAlphanumeric(30)
classroomTokenRepository.insertRefreshToken(newRefreshToken, userCredentials)
return newRefreshToken
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<h2 mat-dialog-title>Neue Konferenz erstellen</h2>
<div class="dialog">
<div class="container">
<div class="dialogTitle" matDialogTitle>Neue Konferenz erstellen</div>
<mat-dialog-content>
<form [formGroup]="form" class="grid-container">
<form [formGroup]="form">
<mat-form-field appearance="fill">
<mat-label>Konferenz Name</mat-label>
<mat-label>Konferenzname</mat-label>
<input matInput type="text" [formControl]="conferenceSubject" required>
</mat-form-field>
<div class="checkbox-form">
Expand All @@ -12,8 +12,8 @@ <h2 mat-dialog-title>Neue Konferenz erstellen</h2>
</div>
</form>
</mat-dialog-content>
<mat-dialog-actions>
<button class="mat-raised-button" (click)="close()">Schließen</button>
<button class="mat-raised-button mat-primary" (click)="createConference()">Erstellen</button>
</mat-dialog-actions>
<mat-action-row>
<button mat-raised-button (click)="close()">Schließen</button>
<button mat-raised-button class="mat-primary" (click)="createConference()">Erstellen</button>
</mat-action-row>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@ button {
margin: 3px;
}

.container {
width: 20rem;

}

form {
display: flex;
flex-direction: column;
}

mat-dialog-content {
display: unset;
width: 20rem;
display: flex;
flex-direction: column;
overflow: hidden;
}

.checkbox-form {
margin-bottom: 10px;
}

mat-action-row {
width: unset;
margin-top: 10px;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<h2 mat-dialog-title>{{title}}</h2>

<mat-dialog-content [formGroup]="form">
<mat-form-field appearance="standard">
<mat-label>Beschreibung</mat-label>
<textarea maxlength="160" formControlName="desc" matInput required cdkTextareaAutosize></textarea>
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions>
<button class="mat-raised-button" (click)="close()">Schließen</button>
<button class="mat-raised-button mat-primary" (click)="editTicket()">Erstellen</button>
</mat-dialog-actions>
<div class="container">
<div class="dialogTitle" matDialogTitle>{{title}}</div>
<mat-dialog-content [formGroup]="form">
<mat-form-field appearance="standard">
<mat-label>Beschreibung</mat-label>
<textarea maxlength="160" formControlName="desc" matInput required cdkTextareaAutosize></textarea>
</mat-form-field>
</mat-dialog-content>
<mat-action-row>
<button mat-raised-button (click)="close()">Schließen</button>
<button mat-raised-button class="mat-primary" (click)="editTicket()">Erstellen</button>
</mat-action-row>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</app-choose-conference-dialog>
</mat-dialog-content>
<mat-action-row>
<button color="primary" mat-flat-button (click)="newConference()">Neue Konferenz</button>
<button color="warn" mat-flat-button (click)="close()">Abbrechen</button>
<button color="primary" mat-raised-button (click)="newConference()">Neue Konferenz</button>
<button color="warn" mat-raised-button (click)="close()">Abbrechen</button>
</mat-action-row>
</div>
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
<mat-select [disabled]="!classroomService.isCurrentUserPrivileged()" [(ngModel)]="assigneeId" class="user-select" (ngModelChange)="assignUser()">
<mat-select-trigger class="user-select">
<ng-container *ngIf="this.assigneeId !== '†none'; then userDisplay else assign"></ng-container>
</mat-select-trigger>
<mat-option value="†none">
<ng-container *ngTemplateOutlet="assign"></ng-container>
</mat-option>
<mat-option *ngFor="let supervisor of this.users" [value]="supervisor.userId">
<app-ticket-user-display label="" [user]="supervisor"></app-ticket-user-display>
</mat-option>
</mat-select>
<div class="ticket-user">
<mat-select [disabled]="!classroomService.isCurrentUserPrivileged()" [(ngModel)]="assigneeId" class="user-select" (ngModelChange)="assignUser()">
<mat-select-trigger class="user-select">
<ng-container *ngIf="this.assigneeId !== '†none'; then userDisplay else assign"></ng-container>
</mat-select-trigger>
<mat-option value="†none">
<ng-container *ngTemplateOutlet="assign"></ng-container>
</mat-option>
<mat-option *ngFor="let supervisor of this.users | isPrivileged" [value]="supervisor.userId">
<app-ticket-user-display label="" [user]="supervisor"></app-ticket-user-display>
</mat-option>
</mat-select>
</div>

<ng-template #assign>
<div class="assign-user" *ngIf="this.classroomService.isCurrentUserPrivileged()">
<mat-icon class="assign-icon">add_circle_outline</mat-icon>&nbsp;
<mat-icon class="assign-icon">add_circle_outline</mat-icon>
<span class="assign-text">zuweisen</span>
</div>
<div class="assign-user" *ngIf="!this.classroomService.isCurrentUserPrivileged()">
<mat-icon class="assign-icon">person_off</mat-icon>&nbsp;
<span class="assign-text"> n/a </span>
<mat-icon class="assign-icon">person_off</mat-icon>
<div class="user-text">
<span class="label">zugewiesen</span>
<span class="user-name">Niemand</span>
</div>
</div>
</ng-template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
display: flex;
flex-flow: row nowrap;
align-items: center;
min-width: 132px;
height: 38px;
}

.user-select {
min-width: 132px;
width: 210px;
height: 38px;
}

Expand Down Expand Up @@ -62,3 +57,6 @@ mat-select-trigger {
display: none;
}

.container {
width: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
flex-flow: row nowrap;
align-items: center;
min-width: 132px;
max-width: 200px;
height: 38px;
.user-avatar {
height: 32px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
<p class="ticket-time">{{this.getTicketTime(ticket)}}</p>
</div>
</div>
<div class="ticket-row ticket-details">{{ticket.description}}</div>
<div class="ticket-row">
<div class="ticket-users ticket-row">
<div class="ticket-users">
<app-ticket-assign label="zugewiesen" [ticket]="ticket" [users]="this.users"></app-ticket-assign>
<app-ticket-user-display label="ersteller" [user]="this.fullUser(this.ticket.creator)"></app-ticket-user-display>
</div>
<div class="ticket-buttons" [ngSwitch]="determineButton()">
<div *ngIf="mayDeleteTicket()" class="ticket-buttons" [ngSwitch]="determineButton()">
<ng-container *ngSwitchCase="'invite'" [ngTemplateOutlet]="inviteToConferenceTemplate"></ng-container>
<ng-container *ngSwitchCase="'join'" [ngTemplateOutlet]="joinConferenceTemplate"></ng-container>
<ng-container *ngSwitchCase="'link'" [ngTemplateOutlet]="linkConferenceTemplate"></ng-container>
<mat-icon class="edit-icon functional-icon" (click)="this.editTicket()">edit</mat-icon>
<mat-icon class="delete-icon functional-icon" (click)="this.closeTicket()">delete</mat-icon>
<mat-icon *ngIf="mayEditTicket()" class="edit-icon functional-icon" (click)="this.editTicket()">edit</mat-icon>
<mat-icon *ngIf="mayDeleteTicket()" class="delete-icon functional-icon" (click)="this.closeTicket()">delete</mat-icon>
</div>
</div>
</mat-card-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ mat-card-content {
font-size: 14px;
color: #6D6D6D;
}
.ticket-users {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
padding-left: 5px;
}
.ticket-meta {
alignment: left;
width: 78px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export class TicketComponent implements OnInit {
return "invite"
}

public mayDeleteTicket(): boolean {
return this.classroomService.isSelf(this.ticket?.creator!!) ||
this.classroomService.isCurrentUserPrivileged()
}

public mayEditTicket(): boolean {
return this.classroomService.isSelf(this.ticket?.creator!!)
}

editTicket() {
this.classroomService.createOrEditTicket(this.ticket)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<mat-icon>supervised_user_circle</mat-icon> {{parseCourseRole(currentUser?.userRole)}}
</div>

<div class="menu-bar-section">
<mat-icon>meeting_room</mat-icon> {{classroomInfo?.classroomName}}
<div class="menu-bar-section room-label" >
<mat-icon>meeting_room</mat-icon> <span class="room-name">{{classroomInfo?.classroomName}}</span>
</div>

<div class="menu-bar-section" (click)="this.toggleMenu()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
align-items: center;
padding: 5px 5px;
box-shadow: none;
border: 1px solid rgba(0, 0, 0, 0.12);

.menu-bar-section {
display: flex;
flex-flow: row nowrap;
align-items: center;
justify-content: space-evenly;
margin: 0 5px 0 5px;
}

Expand All @@ -26,12 +26,11 @@
}
}

mat-icon {
/* Adjust these values accordingly */
left: 0;
right: 0;
.room-name {
margin-left: 3px;
}


.user-avatar {
position: relative;
margin-right: 8px;
Expand Down
8 changes: 4 additions & 4 deletions web-gui/src/app/service/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export class AuthService {
}

private static extractRefreshTokenFromHeader(response: HttpResponse<any>): string {
if (!response.headers.has('refresh_token')) {
throw Error("No refresh_token token in HttpResponse!")
if (!response.headers.has('refreshToken')) {
throw Error("No refreshToken token in HttpResponse!")
}
return response.headers.get('refresh_token')!!;
return response.headers.get('refreshToken')!!;
}

/**
Expand Down Expand Up @@ -93,7 +93,7 @@ export class AuthService {
}

public requestNewToken() {
const headers = new HttpHeaders().set('refresh_token', this.loadRefreshToken())
const headers = new HttpHeaders().set('refreshToken', this.loadRefreshToken())
return this.http.get<void>('/classroom-api/refresh', {headers: headers, observe: 'response'})
.pipe(
tap(res => AuthService.storeToken(AuthService.extractJwtFromHeader(res))),
Expand Down
8 changes: 0 additions & 8 deletions web-gui/src/app/service/classroom.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,6 @@ export class ClassroomService {
return user.conferences.length !== 0
}

public findOrCreateConferenceOfTicket(ticket: Ticket): ConferenceInfo {
let conference = this.findConferenceOfTicket(ticket)
if (conference === undefined) {
conference = this.configureNewConferenceForTicket(ticket)
}
return conference
}

public createNewConferenceForTicket(ticket: Ticket): Observable<ConferenceInfo> {
const info = this.configureNewConferenceForTicket(ticket)
return this.conferenceService.createConference(info).pipe(
Expand Down

0 comments on commit 80c6295

Please sign in to comment.