generated from quarkiverse/quarkiverse-template
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support & test the case when a remote WSDL URL requires basic authent…
…ication fix #969
- Loading branch information
Showing
14 changed files
with
364 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
extensions/core/runtime/src/main/java/io/quarkiverse/cxf/QuarkusHttpConduitConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkiverse.cxf; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.Consumer; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.apache.cxf.BusFactory; | ||
import org.apache.cxf.transport.http.HTTPConduit; | ||
import org.apache.cxf.transport.http.HTTPConduitConfigurer; | ||
|
||
/** | ||
* A {@link HTTPConduitConfigurer} able to configure conduits by address. | ||
*/ | ||
@ApplicationScoped | ||
public class QuarkusHttpConduitConfigurer implements HTTPConduitConfigurer { | ||
private final Map<String, List<Consumer<HTTPConduit>>> configurersByAddress = new ConcurrentHashMap<>(); | ||
|
||
@PostConstruct | ||
void init() { | ||
BusFactory.getDefaultBus().setExtension(this, HTTPConduitConfigurer.class); | ||
} | ||
|
||
@Override | ||
public void configure(String name, String address, HTTPConduit conduit) { | ||
final List<Consumer<HTTPConduit>> configurers = configurersByAddress.get(address); | ||
if (configurers != null) { | ||
configurers.forEach(configurer -> configurer.accept(conduit)); | ||
} | ||
} | ||
|
||
/** | ||
* Add a {@code configurer} that will be applied only to the conduit associated with the given {@code address}. | ||
* | ||
* @param address the endpoint address for which the give {@code configurer} should be registered | ||
* @param configurer the {@code configurer} to apply to the conduit associated with the given {@code address}. | ||
*/ | ||
public void addConfigurer(String address, Consumer<HTTPConduit> configurer) { | ||
configurersByAddress.compute(address, (k, v) -> { | ||
if (v == null) { | ||
v = new ArrayList<>(); | ||
} | ||
v.add(configurer); | ||
return v; | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
integration-tests/client-server/src/main/java/io/quarkiverse/cxf/it/HelloService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.quarkiverse.cxf.it; | ||
|
||
import jakarta.jws.WebMethod; | ||
import jakarta.jws.WebService; | ||
|
||
@WebService(serviceName = "HelloService", targetNamespace = HelloService.NS) | ||
public interface HelloService { | ||
public static final String NS = "https://quarkiverse.github.io/quarkiverse-docs/quarkus-cxf/test"; | ||
|
||
@WebMethod | ||
public String hello(String person); | ||
} |
17 changes: 17 additions & 0 deletions
17
...ient-server/src/main/java/io/quarkiverse/cxf/it/auth/basic/BasicAuthHelloServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkiverse.cxf.it.auth.basic; | ||
|
||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.jws.WebService; | ||
|
||
import io.quarkiverse.cxf.it.HelloService; | ||
|
||
@WebService(serviceName = "HelloService", targetNamespace = HelloService.NS) | ||
@RolesAllowed("app-user") | ||
public class BasicAuthHelloServiceImpl implements HelloService { | ||
|
||
@Override | ||
public String hello(String person) { | ||
return "Hello " + person + "!"; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...tests/client-server/src/main/java/io/quarkiverse/cxf/it/auth/basic/BasicAuthResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.quarkiverse.cxf.it.auth.basic; | ||
|
||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import io.quarkiverse.cxf.annotation.CXFClient; | ||
import io.quarkiverse.cxf.it.HelloService; | ||
|
||
@Path("/client-server/basic-auth") | ||
public class BasicAuthResource { | ||
|
||
@CXFClient("basicAuth") | ||
HelloService basicAuth; | ||
|
||
@CXFClient("basicAuthSecureWsdl") | ||
HelloService basicAuthSecureWsdl; | ||
|
||
@POST | ||
@Path("/{client}/hello") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public Response hello(String body, @PathParam("client") String client) { | ||
final HelloService helloService = switch (client) { | ||
case "basicAuth": { | ||
yield basicAuth; | ||
} | ||
case "basicAuthSecureWsdl": { | ||
yield basicAuthSecureWsdl; | ||
} | ||
default: | ||
throw new IllegalArgumentException("Unexpected client: " + client); | ||
}; | ||
|
||
try { | ||
return Response.ok(helloService.hello(body)).build(); | ||
} catch (Exception e) { | ||
return Response.serverError().entity(e.getMessage()).build(); | ||
} | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...lient-server/src/main/java/io/quarkiverse/cxf/it/auth/basic/WsdlBasicAuthInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkiverse.cxf.it.auth.basic; | ||
|
||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Named; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
import org.apache.cxf.binding.soap.SoapMessage; | ||
import org.apache.cxf.interceptor.Fault; | ||
import org.apache.cxf.phase.AbstractPhaseInterceptor; | ||
import org.apache.cxf.phase.Phase; | ||
import org.apache.cxf.transport.http.AbstractHTTPDestination; | ||
|
||
@ApplicationScoped | ||
@Named("wsdlBasicAuthInterceptor") | ||
public class WsdlBasicAuthInterceptor extends AbstractPhaseInterceptor<SoapMessage> { | ||
|
||
public WsdlBasicAuthInterceptor() { | ||
super(Phase.RECEIVE); | ||
} | ||
|
||
@Override | ||
public void handleMessage(SoapMessage message) throws Fault { | ||
|
||
final HttpServletRequest req = (HttpServletRequest) message.getExchange().getInMessage() | ||
.get(AbstractHTTPDestination.HTTP_REQUEST); | ||
if ("GET".equals(req.getMethod())) { | ||
/* WSDL is the only thing served through GET */ | ||
try { | ||
auth(); | ||
} catch (io.quarkus.security.UnauthorizedException e) { | ||
handle40x(message, HttpServletResponse.SC_UNAUTHORIZED); | ||
} catch (io.quarkus.security.ForbiddenException e) { | ||
handle40x(message, HttpServletResponse.SC_FORBIDDEN); | ||
} | ||
} | ||
} | ||
|
||
private void handle40x(SoapMessage message, int code) { | ||
HttpServletResponse response = (HttpServletResponse) message.getExchange().getInMessage() | ||
.get(AbstractHTTPDestination.HTTP_RESPONSE); | ||
response.setStatus(code); | ||
message.getInterceptorChain().abort(); | ||
} | ||
|
||
@RolesAllowed("app-user") | ||
void auth() { | ||
|
||
} | ||
} |
Oops, something went wrong.