Skip to content

Commit

Permalink
SHIBUI-1062 Fixed merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jan 30, 2019
2 parents 8a62ede + b9e3942 commit 9479df3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public List<User> getAll() {

@Transactional(readOnly = true)
@GetMapping("/current")
public Principal getCurrentUser(Principal principal) {
return principal;
public User getCurrentUser(Principal principal) {
// TODO: fix this
return userService.getCurrentUser();
}

@PreAuthorize("hasRole('ADMIN')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public User getCurrentUser() {
//TODO: Consider returning an Optional here
User user = null;
if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) {
String principal = (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String principal = SecurityContextHolder.getContext().getAuthentication().getName();
if (StringUtils.isNotBlank(principal)) {
Optional<User> persistedUser = userRepository.findByUsername(principal);
if (persistedUser.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def emptyRecordsFromRepository = [].stream()
def expectedEmptyListResponseBody = '[]'
Expand All @@ -118,7 +118,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedCreationDate = '2017-10-23T11:11:11'
def entityDescriptor = new EntityDescriptor(resourceId: 'uuid-1', entityID: 'eid1', serviceProviderName: 'sp1', serviceEnabled: true,
Expand Down Expand Up @@ -168,7 +168,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedCreationDate = '2017-10-23T11:11:11'
def entityDescriptorOne = new EntityDescriptor(resourceId: 'uuid-1', entityID: 'eid1', serviceProviderName: 'sp1',
Expand Down Expand Up @@ -242,7 +242,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'someUser'
def role = 'ROLE_USER'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedCreationDate = '2017-10-23T11:11:11'
def entityDescriptorOne = new EntityDescriptor(resourceId: 'uuid-1', entityID: 'eid1', serviceProviderName: 'sp1',
Expand Down Expand Up @@ -293,7 +293,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedCreationDate = '2017-10-23T11:11:11'
def expectedEntityId = 'https://shib'
Expand Down Expand Up @@ -376,7 +376,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'someUser'
def role = 'ROLE_USER'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedEntityId = 'https://shib'
def expectedSpName = 'sp1'
Expand Down Expand Up @@ -453,7 +453,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def providedResourceId = 'uuid-1'

Expand All @@ -470,7 +470,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedCreationDate = '2017-10-23T11:11:11'
def providedResourceId = 'uuid-1'
Expand Down Expand Up @@ -521,7 +521,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'someUser'
def role = 'ROLE_USER'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedCreationDate = '2017-10-23T11:11:11'
def providedResourceId = 'uuid-1'
Expand Down Expand Up @@ -573,7 +573,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'someUser'
def role = 'ROLE_USER'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedCreationDate = '2017-10-23T11:11:11'
def providedResourceId = 'uuid-1'
Expand All @@ -599,7 +599,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedCreationDate = '2017-10-23T11:11:11'
def providedResourceId = 'uuid-1'
Expand Down Expand Up @@ -634,7 +634,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'someUser'
def role = 'ROLE_USER'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedCreationDate = '2017-10-23T11:11:11'
def providedResourceId = 'uuid-1'
Expand Down Expand Up @@ -670,7 +670,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'someUser'
def role = 'ROLE_USER'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def expectedCreationDate = '2017-10-23T11:11:11'
def providedResourceId = 'uuid-1'
Expand Down Expand Up @@ -700,7 +700,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def postedBody = '''<?xml version="1.0" encoding="UTF-8"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="http://test.scaldingspoon.org/test1">
Expand Down Expand Up @@ -820,7 +820,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def postedMetadataUrl = "http://test.scaldingspoon.org/test1"
def restXml = '''<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -903,7 +903,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def entityDescriptor = generator.buildEntityDescriptor()
def updatedEntityDescriptor = generator.buildEntityDescriptor()
Expand Down Expand Up @@ -934,7 +934,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'someUser'
def role = 'ROLE_USER'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def entityDescriptor = generator.buildEntityDescriptor()
entityDescriptor.serviceEnabled = false
Expand Down Expand Up @@ -964,7 +964,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'someUser'
def role = 'ROLE_USERN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def entityDescriptor = generator.buildEntityDescriptor()
entityDescriptor.createdBy = 'someoneElse'
Expand All @@ -990,7 +990,7 @@ class EntityDescriptorControllerTests extends Specification {
given:
def username = 'admin'
def role = 'ROLE_ADMIN'
authentication.getPrincipal() >> username
authentication.getName() >> username
userRepository.findByUsername(username) >> TestHelpers.generateOptionalUser(username, role)
def entityDescriptor = generator.buildEntityDescriptor()
def updatedEntityDescriptor = generator.buildEntityDescriptor()
Expand Down
6 changes: 4 additions & 2 deletions ui/src/app/admin/component/user-management.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
<td>{{ user.firstName }} {{ user.lastName }}</td>
<td>{{ user.emailAddress }}</td>
<td>
<select [name]="user.username" [ngModel]="user.role" class="form-control" (change)="setUserRole(user, $event.target.value)">
<select [name]="user.username" [ngModel]="user.role" class="form-control"
[disabled]="currentUser.username === user.username"
(change)="setUserRole(user, $event.target.value)">
<option *ngFor="let role of roles$ | async" [value]="role">{{ role }}</option>
</select>
</td>
<td>
<button class="btn btn-link" (click)="deleteUser(user.username)">
<button class="btn btn-link" (click)="deleteUser(user.username)" *ngIf="!(currentUser.username === user.username)">
<span class="sr-only" translate="label.delete-user">
Delete User
</span>
Expand Down
8 changes: 7 additions & 1 deletion ui/src/app/admin/component/user-management.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable, of } from 'rxjs';
import { Observable, Subscription } from 'rxjs';

import * as fromRoot from '../../app.reducer';
import * as fromCore from '../../core/reducer';
Expand All @@ -21,6 +21,8 @@ import { map } from 'rxjs/operators';
export class UserManagementComponent implements OnInit {

users$: Observable<Admin[]>;
currentUser: Admin;
userSub: Subscription;
roles$: Observable<string[]>;

hasUsers$: Observable<boolean>;
Expand All @@ -35,6 +37,10 @@ export class UserManagementComponent implements OnInit {
ngOnInit(): void {
this.users$ = this.store.select(fromAdmin.getAllConfiguredUsers);
this.hasUsers$ = this.users$.pipe(map(userList => userList.length > 0));
this.users$ = this.store.select(fromAdmin.getAllAdmins);
let user$ = this.store.select(fromCore.getUser);

this.userSub = user$.subscribe(u => this.currentUser = u);
}

setUserRole(user: Admin, change: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
"description": "tooltip.refresh-delay-factor",
"type": "string",
"widget": {
"id": "number",
"step": 0.01
"id": "string",
"help": "message.real-number"
},
"placeholder": "label.real-number",
"minimum": 0,
"maximum": 1,
"default": null,
"pattern": "^([0]*(\\.[0-9]+)?|[0]*\\.[0-9]*[1-9][0-9]*)$"
"default": "",
"pattern": "^(?:([0]*(\\.[0-9]+)?|[0]*\\.[0-9]*[1-9][0-9]*)|)$"
}
}
}
Expand Down

0 comments on commit 9479df3

Please sign in to comment.