Merge branch 'develop' into stable
This commit is contained in:
commit
dc63abc272
@ -29,6 +29,20 @@ public interface ClientConfiguration {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The client ID for Client Enforcement authentication.
|
||||
*/
|
||||
default String getClientId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The corresponding client secret for the client ID in Client Enforcement authentication.
|
||||
*/
|
||||
default String getClientSecret() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The token for BEARER authorization.
|
||||
*/
|
||||
@ -47,14 +61,14 @@ public interface ClientConfiguration {
|
||||
* @return The client ID provided by the OAuth IdP administrator.
|
||||
*/
|
||||
default String getOAuthClientId() {
|
||||
return null;
|
||||
return this.getClientId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The corresponding client secret for the client ID provided by the OAuth IdP administrator.
|
||||
*/
|
||||
default String getOAuthClientSecret() {
|
||||
return null;
|
||||
return this.getClientSecret();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,6 +129,8 @@ public interface ClientConfiguration {
|
||||
return new OAuthClientCredentialAuthorizationFilter(this.getOAuthTokenUrl(),
|
||||
this.getOAuthClientId(), this.getOAuthClientSecret());
|
||||
}
|
||||
} else if (this.getClientId() != null) {
|
||||
return new ClientEnforcementAuthorizationFilter(this.getClientId(), this.getClientSecret());
|
||||
} else if (this.getBasicAuthUsername() != null) {
|
||||
return new BasicAuthorizationFilter(this.getBasicAuthUsername(), this.getBasicAuthPassword());
|
||||
} else {
|
||||
|
@ -0,0 +1,49 @@
|
||||
package com.inteligr8.rs;
|
||||
|
||||
import javax.ws.rs.client.ClientRequestContext;
|
||||
|
||||
/**
|
||||
* This class is the base for implementations of client authorization similar
|
||||
* to OAuth-based flows.
|
||||
*
|
||||
* @author brian@inteligr8.com
|
||||
*/
|
||||
public class ClientEnforcementAuthorizationFilter implements AuthorizationFilter {
|
||||
|
||||
private final String clientId;
|
||||
private final String clientSecret;
|
||||
|
||||
/**
|
||||
* This constructor creates a client authorization filter using a client ID
|
||||
* registered with the endpoint.
|
||||
*
|
||||
* @param clientId An endpoint provided client ID.
|
||||
*/
|
||||
public ClientEnforcementAuthorizationFilter(String clientId) {
|
||||
this(clientId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor creates a client authorization filter using a client ID
|
||||
* registered with the endpoint, and the corresponding client secret.
|
||||
*
|
||||
* @param clientId An endpoint provided client ID.
|
||||
* @param clientSecret A secret corresponding to the client ID.
|
||||
*/
|
||||
public ClientEnforcementAuthorizationFilter(String clientId, String clientSecret) {
|
||||
this.clientId = clientId;
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method applies the client headers to the {@link ClientRequestContext}.
|
||||
*
|
||||
* @param requestContext A request context.
|
||||
*/
|
||||
@Override
|
||||
public void filter(ClientRequestContext requestContext) {
|
||||
requestContext.getHeaders().add("client_id", this.clientId);
|
||||
requestContext.getHeaders().add("client_secret", this.clientSecret);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user