Skip to content

Commit

Permalink
BZ-1327632 - Support for custom authentication in RemoteRuntimeEngine…
Browse files Browse the repository at this point in the history
… configuration (#452)
  • Loading branch information
mrietveld authored and mswiderski committed Apr 25, 2016
1 parent b504f31 commit 2ccb9d5
Show file tree
Hide file tree
Showing 11 changed files with 425 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,24 @@ public interface RemoteRestRuntimeEngineBuilder extends RemoteRuntimeEngineBuild
*/
RemoteRestRuntimeEngineBuilder disableTaskSecurity();

/**
* Adds a header field that will be sent with each request.
* </p>
* Multiple calls to this method with the same header field name will *not* replace existing header fields
* with the same header field name.
*
* @param headerFieldName The header field name
* @param headerFieldValue The header field value
*
* @return An instance of this builder
*/
RemoteRestRuntimeEngineBuilder addHeader(String headerFieldName, String headerFieldValue);

/**
* Clears all existing header field values for this builder.
*
* @return An instance of this builder
*/
RemoteRestRuntimeEngineBuilder clearHeaderFields();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down Expand Up @@ -83,7 +83,7 @@ public class JaxbCommandsResponse {
@XmlSchemaType(name = "string")
private String version;

@XmlElements({
@XmlElements({
@XmlElement(name = "exception", type = JaxbExceptionResponse.class),
@XmlElement(name = "long-list", type = JaxbLongListResponse.class),
@XmlElement(name = "string-list", type = JaxbStringListResponse.class),
Expand Down Expand Up @@ -114,6 +114,7 @@ public JaxbCommandsResponse(JaxbCommandsRequest request) {
super();
this.deploymentId = request.getDeploymentId();
this.processInstanceId = request.getProcessInstanceId();
this.version = request.getVersion();
}

public String getDeploymentId() {
Expand All @@ -140,8 +141,8 @@ public void setVersion(String version) {
this.version = version;
}

private void lazyInitResponseList() {
if( this.responses == null ) {
private void lazyInitResponseList() {
if( this.responses == null ) {
this.responses = new ArrayList<JaxbCommandResponse<?>>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.kie.remote.client.api.RemoteRestRuntimeEngineBuilder;
import org.kie.remote.client.api.RemoteRestRuntimeEngineFactory;
import org.kie.remote.client.api.RemoteRuntimeEngineBuilder;
import org.kie.remote.client.api.exception.InsufficientInfoToBuildException;
import org.kie.services.client.api.command.RemoteConfiguration;
import org.kie.services.client.api.command.RemoteConfiguration.Type;
Expand Down Expand Up @@ -52,6 +53,18 @@ public RemoteRestRuntimeEngineBuilderImpl disableTaskSecurity() {
return this;
}

@Override
public RemoteRestRuntimeEngineBuilder addHeader(String headerFieldName, String headerFieldValue) {
config.addHeader(headerFieldName, headerFieldValue);
return this;
}

@Override
public RemoteRestRuntimeEngineBuilder clearHeaderFields() {
config.clearHeaders();
return this;
}

private void checkAndFinalizeConfig() {
RemoteRuntimeEngineFactory.checkAndFinalizeConfig(config, this);
}
Expand All @@ -71,4 +84,5 @@ public RemoteRuntimeEngine build() {
public static RemoteRestRuntimeEngineBuilderImpl newBuilder() {
return new RemoteRestRuntimeEngineBuilderImpl();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,17 @@ void preprocessParameterCommand( Object cmdObj, List<Object> extraClassInstanceL

void addPossiblyNullObject( Object inputObject, List<Object> objectList ) {
if( inputObject != null ) {
if( inputObject instanceof List ) {
if( inputObject instanceof List ) {
objectList.addAll((List) inputObject);
} else if( inputObject instanceof JaxbStringObjectPairArray ) {
} else if( inputObject instanceof JaxbStringObjectPairArray ) {
for( JaxbStringObjectPair stringObjectPair : ((JaxbStringObjectPairArray) inputObject).getItems() ) {
objectList.add(stringObjectPair.getValue());
}
} else if( inputObject instanceof StringKeyObjectValueMap ) {
for( Object obj : ((StringKeyObjectValueMap) inputObject).values() ) {
objectList.add(obj);
}
} else {
}
} else {
objectList.add(inputObject);
}
}
Expand Down Expand Up @@ -337,6 +337,13 @@ private <T> T executeRestCommand( Command command ) {
config.getCorrelationProperties());
KieRemoteHttpRequest httpRequest = config.createHttpRequest().relativeRequest("/execute");

List<String[]> headers = config.getHeaders();
if( headers != null ) {
for( String [] header : config.getHeaders() ) {
httpRequest.header(header[0], header[1]);
}
}

// necessary for deserialization
String deploymentId = config.getDeploymentId();
if( ! emptyDeploymentId(deploymentId) ) {
Expand Down

0 comments on commit 2ccb9d5

Please sign in to comment.