Hi Srikar,
I was able to write below Java service to get all the claims from the messageContext.
First we need to add WmAPIGateway as dependency of our package to put application model classes in path for java service.
[size=9]import com.softwareag.pg.rest.RestMessageContext;
import com.softwareag.apigateway.API.model.application.Application;
import com.softwareag.apigateway.API.model.application.ApplicationIdentifier;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public static final void getClaims(IData pipeline) throws ServiceException {
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
Object MessageContext = IDataUtil.get( pipelineCursor, "MessageContext" );
pipelineCursor.destroy();
RestMessageContext synCtx = (RestMessageContext)MessageContext;
Application identifiedApp=(Application)synCtx.getProperty("gateway.identifiedApplication");
ApplicationIdentifier appIdentifier=identifiedApp.getIdentifiers().get(0);
List<ApplicationIdentifier.NamedPair> npList=appIdentifier.getNamedValues();
// pipeline
pipelineCursor = pipeline.getCursor();
// Claims
IData Claims = IDataFactory.create();
IDataCursor ClaimsCursor = Claims.getCursor();
for (ApplicationIdentifier.NamedPair namedPair : npList) {
String claimName=namedPair.getName();
// Claims.JWT ClaimSet
IData ClaimSet = IDataFactory.create();
IDataCursor ClaimSetCursor = ClaimSet.getCursor();
List<String> values=namedPair.getValues();
Map<String,String> valueMap=JsonToMap(values.get(0));
Object keys[]=valueMap.keySet().toArray();
for (Object key : keys) {
IDataUtil.put( ClaimSetCursor, (String)key, valueMap.get((String)key));
}
ClaimSetCursor.destroy();
IDataUtil.put( ClaimsCursor, claimName, ClaimSet );
ClaimsCursor.destroy();
}
IDataUtil.put( pipelineCursor, "Claims", Claims );
pipelineCursor.destroy();
}
public static Map<String,String> JsonToMap(String JSON){
ObjectMapper mapper = new ObjectMapper();
Map<String, String> namedPair=null;
try {
namedPair = mapper.readValue(JSON, new TypeReference<Map<String, String>>() {});
} catch (Exception e) {
e.printStackTrace();
}
return namedPair;
}[/size]
Please let me know if there is any other SAG recommended way to do it.
Regards,
Vineet Sharma.
#API-Management#webMethods#API-Gateway