use of org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext in project carbon-apimgt by wso2.
the class DataProcessAndPublishingAgentTest method testEnableQueryParamConditionWithoutQueryParams.
@Test
public void testEnableQueryParamConditionWithoutQueryParams() throws Exception {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableQueryParamConditions(true);
throttleProperties.setEnableJwtConditions(true);
DataProcessAndPublishingAgent dataProcessAndPublishingAgent = new DataProcessAndPublishingAgentWrapper(throttleProperties);
AuthenticationContext authenticationContext = new AuthenticationContext();
MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
Mockito.when(axis2MsgCntxt.getProperty(NhttpConstants.REST_URL_POSTFIX)).thenReturn("");
TreeMap headers = new TreeMap();
headers.put(APIMgtGatewayConstants.X_FORWARDED_FOR, "192.168.1.1");
Mockito.when(axis2MsgCntxt.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS)).thenReturn(headers);
VerbInfoDTO verbInfoDTO = new VerbInfoDTO();
verbInfoDTO.setContentAware(false);
ArrayList<VerbInfoDTO> list = new ArrayList<VerbInfoDTO>();
list.add(verbInfoDTO);
API api = new API();
api.setUuid(UUID.randomUUID().toString());
api.setApiName(apiName);
api.setApiVersion(apiVersion);
api.setApiProvider("admin");
Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API_OBJECT)).thenReturn(api);
Mockito.when(messageContext.getProperty(APIConstants.VERB_INFO_DTO)).thenReturn(list);
dataProcessAndPublishingAgent.setDataReference(applicationLevelThrottleKey, applicationLevelTier, apiLevelThrottleKey, null, subscriptionLevelThrottleKey, subscriptionLevelTier, resourceLevelThrottleKey, resourceLevelTier, authorizedUser, apiContext, apiVersion, appTenant, apiTenant, appId, messageContext, authenticationContext);
dataProcessAndPublishingAgent.run();
}
use of org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext in project carbon-apimgt by wso2.
the class DataProcessAndPublishingAgentTest method setDataReferenceWithoutApiLevelTier.
@Test
public void setDataReferenceWithoutApiLevelTier() throws Exception {
ThrottleProperties throttleProperties = new ThrottleProperties();
DataProcessAndPublishingAgent dataProcessAndPublishingAgent = new DataProcessAndPublishingAgentWrapper(throttleProperties);
AuthenticationContext authenticationContext = new AuthenticationContext();
MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
API api = new API();
api.setUuid(UUID.randomUUID().toString());
api.setApiName(apiName);
api.setApiVersion(apiVersion);
api.setApiProvider("admin");
Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API_OBJECT)).thenReturn(api);
dataProcessAndPublishingAgent.setDataReference(applicationLevelThrottleKey, applicationLevelTier, apiLevelThrottleKey, null, subscriptionLevelThrottleKey, subscriptionLevelTier, resourceLevelThrottleKey, resourceLevelTier, authorizedUser, apiContext, apiVersion, appTenant, apiTenant, appId, messageContext, authenticationContext);
}
use of org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithJWTConditionNegative.
@Test
public void testGetThrottledInConditionWithJWTConditionNegative() {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableJwtConditions(true);
ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
String jwt = "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3c28yLm9yZy9wcm9kdWN0cy9hbSIsImV4cCI6MTM0NTE4MzQ5MjE4MSwiaHR0cD" + "ovL3dzbzIub3JnL2NsYWltcy9hYmMiOiJjZCIsImh0dHA6Ly93c28yLm9yZy9jbGFpbXMvYmNkIjoieHl6In0=.yg-FAt9-h7CR" + "p7DCM6m4x5xWGxwj4mwXHH4b4sUP9h0";
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.setCallerToken(jwt);
Map<String, List<ConditionDto>> conditionMap = new HashMap<>();
conditionMap.put("condition1", Arrays.asList(new ConditionDto[] { getJWTCondition(false) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getJWTCondition(false) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, authenticationContext, conditionMap);
Assert.assertEquals(condition, "default");
}
use of org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfMatchingJWTClaimsCondition.
@Test
public void testApplicabilityOfMatchingJWTClaimsCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("JWTClaimsConditionGroup");
ConditionDTO matchingCondition = new ConditionDTO();
matchingCondition.setConditionType("JWTClaims");
matchingCondition.setConditionName("http://wso2.org/claims/subscriber");
matchingCondition.setConditionValue("admin");
ConditionDTO[] conditionDTOS = { matchingCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.setCallerToken(JWTToken);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(messageContext, authenticationContext, conditionGroupDTOS);
Assert.assertEquals(matchingConditionGroups.get(0).getConditionGroupId(), "JWTClaimsConditionGroup");
}
use of org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfInvertedJWTClaimsCondition.
@Test
public void testApplicabilityOfInvertedJWTClaimsCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("JWTClaimsConditionGroup");
ConditionDTO invertedCondition = new ConditionDTO();
invertedCondition.setConditionType("JWTClaims");
invertedCondition.setConditionName("http://wso2.org/claims/subscriber");
invertedCondition.setConditionValue("admin");
invertedCondition.isInverted(true);
ConditionDTO[] conditionDTOS = { invertedCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.setCallerToken(JWTToken);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(messageContext, authenticationContext, conditionGroupDTOS);
Assert.assertNull(matchingConditionGroups.get(0));
}
Aggregations