Skip to content

Commit

Permalink
Merge pull request #22 from ligangty/main
Browse files Browse the repository at this point in the history
Auth support: enable oidc and add access token in client request filter
  • Loading branch information
ligangty authored Apr 3, 2023
2 parents 25489f8 + 59e0740 commit 5eb91c2
Show file tree
Hide file tree
Showing 23 changed files with 33 additions and 111 deletions.
14 changes: 2 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@
</properties>

<dependencies>
<!--
<dependency>
<groupId>org.commonjava.indy.service</groupId>
<artifactId>indy-security</artifactId>
<version>${indysecurity.verison}</version>
</dependency>
-->

</dependency>

<!-- quarkus deps start -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -123,14 +121,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc-client-filter</artifactId>
</dependency>
<!-- quarkus-security end -->

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
*/
package org.commonjava.indy.service.ui.client;


import io.quarkus.oidc.client.OidcClient;
import io.quarkus.oidc.IdToken;
import io.quarkus.oidc.RefreshToken;
import org.eclipse.microprofile.jwt.JsonWebToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Priority;
import javax.inject.Inject;
Expand All @@ -26,18 +29,36 @@
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.ext.Provider;

//@Provider
//@Priority(Priorities.AUTHENTICATION)
public class CustomClientRequestFilter
@Provider
@Priority( Priorities.AUTHENTICATION )
public class AuthClientRequestFilter
implements ClientRequestFilter
{
private final Logger logger = LoggerFactory.getLogger( this.getClass() );

@Inject
@IdToken
JsonWebToken idToken;

@Inject
JsonWebToken accessToken;

@Inject
OidcClient client;
RefreshToken refreshToken;

@Override
public void filter( ClientRequestContext requestContext )
{
requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, "Bearer " + client.getTokens().await().indefinitely().getAccessToken());
if ( idToken != null )
{
Object userName = this.idToken.getClaim( "preferred_username" );
logger.debug( "User: {}", userName );
}
if ( accessToken != null )
{
String token = accessToken.getRawToken();
logger.debug( "Access Token: {}", token );
requestContext.getHeaders().add( HttpHeaders.AUTHORIZATION, String.format( "Bearer %s", token ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

@Path( "/api/admin/maint" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface MaintenanceServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@Path( "/api/browse/{packageType}/{type: (hosted|group|remote)}/{name}" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface ContentBrowseServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

@Path( "/api/content/generic-http/{type: (hosted|group|remote)}/{name}" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface GenericContentAccessServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

@Path( "/api/content/maven/{type: (hosted|group|remote)}/{name}" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider(CustomClientRequestFilter.class)
public interface MavenContentAccessServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

@Path( "/api/content/npm/{type: (hosted|group|remote)}/{name}" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface NPMContentAccessServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
@Path( "/api/repair/koji" )
@Produces( APPLICATION_JSON )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface KojiRepairServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

@Path( "/api/nfc" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider(CustomClientRequestFilter.class)
public interface NFCServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

@Path( "/api/admin/pathmapped" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface PathMappedServiceClient
{
String BROWSE_BASE = "/browse/{packageType}/{type: (hosted|group|remote)}/{name}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

@Path( PromoteAdminServiceClient.PROMOTION_ADMIN_API )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider(CustomClientRequestFilter.class)
public interface PromoteAdminServiceClient
{
String PROMOTION_ADMIN_API = "/api/promotion/admin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
@Path( "/api/promotion" )
@Produces( APPLICATION_JSON )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider(CustomClientRequestFilter.class)
public interface PromoteServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

@Path( "/api/admin/stores/{packageType}/{type: (hosted|group|remote)}" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider(CustomClientRequestFilter.class)
public interface RepositoryAdminServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

@Path( "/api/admin/stores/maint" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider(CustomClientRequestFilter.class)
public interface RepositoryMaintServiceClient
{
String MEDIATYPE_APPLICATION_ZIP = "application/zip";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,21 @@
*/
package org.commonjava.indy.service.ui.client.repository;

import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.jboss.resteasy.spi.HttpRequest;

import javax.ws.rs.Consumes;
import javax.ws.rs.Encoded;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static javax.ws.rs.core.Response.ok;

@Path( "/api/admin/stores/query" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider(CustomClientRequestFilter.class)
public interface RepositoryQueryServiceClient
{
Response getAll( @QueryParam( "packageType" ) final String packageType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
@Path( "/api/admin/schedule" )
@Produces( APPLICATION_JSON )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface SchedulerServiceClient
{
@Path( "store/{type}/{name}/disable-timeout" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.commonjava.indy.service.ui.client.stats;

import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import javax.ws.rs.GET;
Expand All @@ -29,7 +28,6 @@

@Path( "/api/stats" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface StatsClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

@Path( "/api/folo/track/{id}/generic-http/{type: (hosted|group|remote)}/{name}" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface FoloGenericContentAccessServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

@Path( "/api/folo/track/{id}/maven/{type: (hosted|group|remote)}/{name}" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface FoloMavenContentAccessServiceClient
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

@Path( "/api/folo/track/{id}/npm/{type: (hosted|group|remote)}/{name}" )
@RegisterRestClient( configKey = "service-api" )
//@RegisterProvider( CustomClientRequestFilter.class)
public interface FoloNPMContentAccessServiceClient
{

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@Startup
@ConfigMapping( prefix = "keycloak" )
@ApplicationScoped
@Deprecated
interface KeycloakConfig
{
boolean DEFAULT_ENABLED = false;
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ quarkus:
strict-ssl: false
install: "npm config set strict-ssl false && npm ci"

# These REST APIs are not needed to show in rest docs
mp:
openapi:
scan:
Expand Down Expand Up @@ -121,7 +122,7 @@ service-api/mp-rest/uri: http://localhost:8080/
service-api/mp-rest/scope: javax.inject.Singleton
#service-api/mp-rest/connectTimeout: 60000
#service-api/mp-rest/readTimeout: 60000
#service-api/mp-rest/providers: org.commonjava.indy.service.ui.client.CustomClientRequestFilter
#service-api/mp-rest/providers: org.commonjava.indy.service.ui.client.AuthClientRequestFilter

"%dev":
quarkus:
Expand Down

0 comments on commit 5eb91c2

Please sign in to comment.