diff --git a/src/main/java/at/ac/uibk/gitsearch/security/jwt/TokenProvider.java b/src/main/java/at/ac/uibk/gitsearch/security/jwt/TokenProvider.java index 669d94c90862337710a98b006b88753c28ff0d9e..e181046fb0c8c20b0d8c40b433963596677fecce 100644 --- a/src/main/java/at/ac/uibk/gitsearch/security/jwt/TokenProvider.java +++ b/src/main/java/at/ac/uibk/gitsearch/security/jwt/TokenProvider.java @@ -21,9 +21,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; -import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; import org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken; -import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; diff --git a/src/main/java/at/ac/uibk/gitsearch/service/SearchService.java b/src/main/java/at/ac/uibk/gitsearch/service/SearchService.java index 371236fcd279e5a88a1d8b04e6974b95540565e1..97075fba6ee2e895d0c61b969719e16af5321106 100644 --- a/src/main/java/at/ac/uibk/gitsearch/service/SearchService.java +++ b/src/main/java/at/ac/uibk/gitsearch/service/SearchService.java @@ -4,25 +4,21 @@ import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.security.Principal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.function.Predicate; import java.util.stream.Collectors; +import org.gitlab4j.api.Constants.TokenType; import org.gitlab4j.api.GitLabApi; import org.gitlab4j.api.GitLabApiException; import org.gitlab4j.api.models.AccessLevel; import org.gitlab4j.api.models.Permissions; import org.gitlab4j.api.models.Project; -import org.gitlab4j.api.Constants.TokenType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.oauth2.client.registration.ClientRegistration.ProviderDetails; import org.springframework.stereotype.Service; import org.springframework.util.FileCopyUtils; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; @@ -31,8 +27,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import at.ac.uibk.gitsearch.repository.search.MetaDataRepository; -import at.ac.uibk.gitsearch.repository.search.SearchRepositoryConstants; -import at.ac.uibk.gitsearch.security.SecurityUtils; import at.ac.uibk.gitsearch.security.jwt.TokenProvider; import at.ac.uibk.gitsearch.service.dto.SearchInputDTO; import at.ac.uibk.gitsearch.service.dto.SearchResultsDTO; diff --git a/src/main/webapp/app/layouts/navbar/navbar.component.html b/src/main/webapp/app/layouts/navbar/navbar.component.html index 05406b28702ab39b658df1ab347bdf72294a98df..400f7067ec6883d9c87160b3cc548659157307e5 100644 --- a/src/main/webapp/app/layouts/navbar/navbar.component.html +++ b/src/main/webapp/app/layouts/navbar/navbar.component.html @@ -43,15 +43,16 @@ <!-- Menu Entities --> + <!-- <div class="nav-item dropdown"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#"> - <!-- Icon --> + <!-X- Icon -X-> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-collection-fill" viewBox="0 0 16 16"> <path d="M0 13a1.5 1.5 0 0 0 1.5 1.5h13A1.5 1.5 0 0 0 16 13V6a1.5 1.5 0 0 0-1.5-1.5h-13A1.5 1.5 0 0 0 0 6v7zM2 3a.5.5 0 0 0 .5.5h11a.5.5 0 0 0 0-1h-11A.5.5 0 0 0 2 3zm2-2a.5.5 0 0 0 .5.5h7a.5.5 0 0 0 0-1h-7A.5.5 0 0 0 4 1z"/> </svg> - <!-- Icon End --> + <!-X- Icon End -X-> Entities </a> (Vorlage) <div class="dropdown-menu"> @@ -63,17 +64,18 @@ <span class="spawn-submenu">This is a short description of the link 3</span> </div> </div> - + --> <!-- Menu Programs --> + <!-- <div class="nav-item dropdown"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#"> - <!-- Icon --> + <!-X- Icon -X-> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-grid-3x3-gap-fill" viewBox="0 0 16 16"> <path d="M1 2a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V2zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1V2zM1 7a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V7zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V7zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1V7zM1 12a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1v-2zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1v-2zm5 0a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1v-2z"/> </svg> - <!-- Icon End --> + <! -X- Icon End -X- > Programs </a> (Vorlage) <div class="dropdown-menu dropdown-large"> @@ -115,7 +117,7 @@ </div> </div> </div> - + --> <!-- Search --> <div class="nav-item" > <span class="nav-link"> @@ -221,14 +223,14 @@ </a> <div class="dropdown-menu"> <div class="search-container" *ngSwitchCase="false"> - <div *ngSwitchCase="false"> + <div *ngSwitchCase="false" > <!-- Quick Search --> - <div class="dropdown-item"> - <img src="/content/img/gitLab.png" style="width: 50px;"/> + <div class="dropdown-item" *ngFor="let config of configs"> + <img src="{{'oauth2.'+config.registrationId + '.icon'| translate}}" style="width: 50px;"/> <button type="submit" class="btn btn-outline-secondary" - *ngSwitchCase="false" (click)="loginWithGitLab()" - jhiTranslate="global.menu.account.loginViaGitLab">Sign in with GitLab - Account + *ngSwitchCase="false" (click)="loginWithGitLab(config.registrationId)" + jhiTranslate="oauth2.{{config.registrationId}}.text">Sign in with GitLab + Account </button> </div> <!-- Menu Divider --> diff --git a/src/main/webapp/app/layouts/navbar/navbar.component.ts b/src/main/webapp/app/layouts/navbar/navbar.component.ts index 9f088e49e90d7c1a43bcfa5caa80614498962102..493782784c59a761c4d3df073972534754194cfb 100644 --- a/src/main/webapp/app/layouts/navbar/navbar.component.ts +++ b/src/main/webapp/app/layouts/navbar/navbar.component.ts @@ -11,6 +11,8 @@ import { LANGUAGES } from 'app/core/language/language.constants'; import { AccountService } from 'app/core/auth/account.service'; import { LoginService } from 'app/core/login/login.service'; import { ProfileService } from 'app/layouts/profiles/profile.service'; +import { OAuth2ConfigService } from 'app/core/auth/oauth2-config.service'; +import { OAuth2Config } from 'app/core/auth/oauth2-config.model'; import { Location } from '@angular/common'; @@ -35,6 +37,9 @@ export class NavbarComponent implements OnInit { rememberMe: [false], }); + public configs: OAuth2Config[] ; + + constructor( private loginService: LoginService, public searchComponent: SearchComponent, @@ -45,9 +50,17 @@ export class NavbarComponent implements OnInit { // private loginModalService: LoginModalService, private profileService: ProfileService, private router: Router, - private location: Location // for redirect in OAuth2 - ) { - this.version = VERSION ? (VERSION.toLowerCase().startsWith('v') ? VERSION : 'v' + VERSION) : ''; + private location: Location, // for redirect in OAuth2 + public oAuth2ConfigService: OAuth2ConfigService) { + this.configs = []; + + this.oAuth2ConfigService.getAllConfigs().subscribe( + (loadedConfigs: OAuth2Config[]) => { + this.configs = loadedConfigs; + }); + + + this.version = VERSION ? (VERSION.toLowerCase().startsWith('v') ? VERSION : 'v' + VERSION) : ''; } ngOnInit(): void { @@ -97,13 +110,12 @@ export class NavbarComponent implements OnInit { } - loginWithGitLab(): void { - // If you have configured multiple OIDC providers, then, you can update this URL to /login. + loginWithGitLab(registrationId:string): void { + location.href = `${location.origin}${this.location.prepareExternalUrl('oauth2/authorization/'+ registrationId)}`; + // If you have configured multiple OIDC providers, then, you can update this URL to /login. // It will show a Spring Security generated login page with links to configured OIDC providers. - location.href = `${location.origin}${this.location.prepareExternalUrl('oauth2/authorization/gitlabOidc')}`; - - } + } searchChanged(): void { this.searchComponent.searchChanged();