use of org.wso2.carbon.identity.core.model.Node in project module-ballerinax-aws.lambda by ballerina-platform.
the class AWSLambdaPlugin method validateLambdaFunction.
private boolean validateLambdaFunction(BLangFunction node) {
List<BLangSimpleVariable> defaultableParams = new ArrayList<>();
for (BLangSimpleVariable var : node.requiredParams) {
if (var.symbol.isDefaultable) {
defaultableParams.add(var);
}
}
if (node.requiredParams.size() != 2 || defaultableParams.size() > 0 || node.restParam != null) {
return false;
}
BLangType type1 = node.requiredParams.get(0).getTypeNode();
BLangType type2 = node.requiredParams.get(1).getTypeNode();
if (!type1.getBType().tsymbol.name.value.equals("Context")) {
return false;
}
if (!type1.getBType().tsymbol.pkgID.orgName.value.equals(AWS_LAMBDA_PACKAGE_ORG) || !type1.getBType().tsymbol.pkgID.name.value.equals(AWS_LAMBDA_PACKAGE_NAME)) {
return false;
}
if (type2 == null) {
return false;
}
BLangType retType = node.returnTypeNode;
if (retType instanceof BLangUnionTypeNode) {
BLangUnionTypeNode unionType = (BLangUnionTypeNode) retType;
Set<Integer> typeTags = new HashSet<>();
for (BLangType memberTypeNode : unionType.memberTypeNodes) {
typeTags.add(memberTypeNode.getBType().tag);
}
typeTags.remove(TypeTags.JSON_TAG);
typeTags.remove(TypeTags.ERROR_TAG);
typeTags.remove(TypeTags.NULL_TAG);
return typeTags.isEmpty();
} else {
return retType.getBType().tag == TypeTags.JSON_TAG || retType.getBType().tag == TypeTags.ERROR_TAG || retType.getBType().tag == TypeTags.NULL_TAG;
}
}
use of org.wso2.carbon.identity.core.model.Node in project product-is by wso2.
the class OAuth2TokenRevokeAfterCacheTimeOutTestCase method testRevokeTokenAfterCacheTimedOut.
/**
* This tests written for test for token revocation after cache timed out CARBON-15028
* This test needed two APIM nodes with clustering enabled
* During the test one node is use to generate the token and other node use to revoke the token
* After cache timeout new token should issued after it revoked
*
* @throws Exception
*/
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
@Test(description = "Revoke token after cache timed out")
public void testRevokeTokenAfterCacheTimedOut() throws Exception {
// Application utils
OAuthConsumerAppDTO appDto = createApplication();
consumerKey = appDto.getOauthConsumerKey();
consumerSecret = appDto.getOauthConsumerSecret();
// request for token
String token = requestAccessToken(consumerKey, consumerSecret, TOKEN_API_ENDPOINT, "admin", "admin");
// Sleep for 1m for cache timeout
Thread.sleep(60 * 1000);
// Revoke access token
revokeAccessToken(consumerKey, consumerSecret, token, REVOKE_TOKEN_API_ENDPOINT);
// Generate new token
String newToken = requestAccessToken(consumerKey, consumerSecret, TOKEN_API_ENDPOINT, "admin", "admin");
Assert.assertNotEquals(token, newToken, "Token revocation failed");
}
use of org.wso2.carbon.identity.core.model.Node in project product-is by wso2.
the class OAuth2TokenRevokeWithInvalidClientCredentialsTestCase method testRevokeTokenAfterCacheTimedOut.
/**
* This tests written for test for token revocation after cache timed out CARBON-15028
* This test needed two APIM nodes with clustering enabled
* During the test one node is use to generate the token and other node use to revoke the token
* After cache timeout new token should issued after it revoked
*
* @throws Exception
*/
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
@Test(description = "Revoke token with invalid sending of client credentials.")
public void testRevokeTokenAfterCacheTimedOut() throws Exception {
String clientKey = "dummyConsumerKey";
String clientSecret = "dummyConsumerSecret";
String accessToken = "dummyAccessToken";
// Revoke access token
ArrayList<NameValuePair> postParameters;
HttpClient client = new DefaultHttpClient();
HttpPost httpRevoke = new HttpPost(REVOKE_TOKEN_API_ENDPOINT);
// Generate revoke token post request
httpRevoke.setHeader("Authorization", "Basic " + getInvalidBase64EncodedString(clientKey, clientSecret));
httpRevoke.setHeader("Content-Type", "application/x-www-form-urlencoded");
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("token", accessToken));
httpRevoke.setEntity(new UrlEncodedFormEntity(postParameters));
HttpResponse response = client.execute(httpRevoke);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
Object obj = JSONValue.parse(rd);
Assert.assertNotNull(obj, "Returned error response should have produced a valid JSON.");
Assert.assertNotNull(((JSONObject) obj).get("error"), "Returned error response should have 'error' defined.");
String errorMessage = ((JSONObject) obj).get("error").toString();
EntityUtils.consume(response.getEntity());
Assert.assertEquals("invalid_client", errorMessage, "Invalid format in sending client credentials, should have produced : " + OAuth2Constant.INVALID_CLIENT + "error code");
}
use of org.wso2.carbon.identity.core.model.Node in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMUserManagerTest method testListGroupsWithFilter.
@Test(dataProvider = "groupNameWithFilters")
public void testListGroupsWithFilter(String filter, String roleName, String userStoreDomain) throws Exception {
ExpressionNode node = new ExpressionNode(filter);
List<String> list = new ArrayList<>();
list.add(roleName);
List<org.wso2.carbon.user.core.common.User> users = new ArrayList<>();
org.wso2.carbon.user.core.common.User user = new org.wso2.carbon.user.core.common.User();
user.setUserID(UUID.randomUUID().toString());
user.setUserStoreDomain(userStoreDomain);
user.setUsername("testUser");
users.add(user);
Map<String, Boolean> requiredAttributes = null;
Map<String, String> attributes = new HashMap<String, String>() {
{
put(SCIMConstants.CommonSchemaConstants.ID_URI, "1");
}
};
whenNew(GroupDAO.class).withAnyArguments().thenReturn(mockedGroupDAO);
when(mockedGroupDAO.getGroupNameList(anyString(), anyString(), anyInt(), anyString())).thenReturn(list.toArray(new String[0]));
mockStatic(IdentityUtil.class);
when(mockedGroupDAO.isExistingGroup("testRole", 0)).thenReturn(true);
when(mockedGroupDAO.getSCIMGroupAttributes(0, "testRole")).thenReturn(attributes);
when(IdentityUtil.extractDomainFromName(anyString())).thenReturn(userStoreDomain);
mockedUserStoreManager = PowerMockito.mock(AbstractUserStoreManager.class);
MemberModifier.field(AbstractUserStoreManager.class, "userStoreManagerHolder").set(mockedUserStoreManager, new HashMap<String, UserStoreManager>());
when(mockedUserStoreManager.isExistingRole(anyString(), anyBoolean())).thenReturn(true);
when(mockedUserStoreManager.getRealmConfiguration()).thenReturn(mockRealmConfig);
when(mockedUserStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(mockedUserStoreManager);
when(mockedUserStoreManager.isSCIMEnabled()).thenReturn(true);
when(mockedUserStoreManager.getUserListWithID(anyString(), anyString(), anyString())).thenReturn(users);
when(mockedUserStoreManager.getRoleListOfUserWithID(anyString())).thenReturn(list);
org.wso2.carbon.user.core.common.Group[] groupsArray = { buildUserCoreGroupResponse(roleName, "1234", "dummyDomain") };
when(mockedUserStoreManager.listGroups(any(Condition.class), anyString(), anyInt(), anyInt(), anyString(), anyString())).thenReturn(Arrays.asList(groupsArray.clone()));
when(mockedUserStoreManager.getGroupByGroupName(roleName, null)).thenReturn(buildUserCoreGroupResponse(roleName, "123456789", null));
whenNew(RealmConfiguration.class).withAnyArguments().thenReturn(mockRealmConfig);
when(mockRealmConfig.getAdminRoleName()).thenReturn("admin");
when(mockRealmConfig.isPrimary()).thenReturn(false);
when(mockRealmConfig.getUserStoreProperty(anyString())).thenReturn("value");
when(mockRealmConfig.getEveryOneRoleName()).thenReturn("admin");
when(mockIdentityUtil.extractDomainFromName(anyString())).thenReturn("value");
Map<String, String> scimToLocalClaimsMap = new HashMap<>();
scimToLocalClaimsMap.put("urn:ietf:params:scim:schemas:core:2.0:User:userName", "http://wso2.org/claims/username");
mockStatic(SCIMCommonUtils.class);
when(SCIMCommonUtils.getSCIMtoLocalMappings()).thenReturn(scimToLocalClaimsMap);
SCIMUserManager scimUserManager = new SCIMUserManager(mockedUserStoreManager, mockedClaimManager);
List<Object> roleList = scimUserManager.listGroupsWithGET(node, 1, 1, null, null, null, requiredAttributes);
assertEquals(roleList.size(), 2);
}
use of org.wso2.carbon.identity.core.model.Node in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMUserManagerTest method testFilterApplicationRolesWithDomainParam.
@Test(dataProvider = "applicationDomainWithFilters")
public void testFilterApplicationRolesWithDomainParam(String filter, String[] roles, Map<String, String> attributes) throws Exception {
ExpressionNode node = new ExpressionNode(filter);
Map<String, Boolean> requiredAttributes = null;
AbstractUserStoreManager abstractUserStoreManager = mock(AbstractUserStoreManager.class);
when(abstractUserStoreManager.getRoleNames(anyString(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(roles);
when(abstractUserStoreManager.isExistingRole(anyString(), anyBoolean())).thenReturn(true);
for (String role : roles) {
when(abstractUserStoreManager.getGroupByGroupName(role, null)).thenReturn(buildUserCoreGroupResponse(role, "123456", "dummyDomain"));
}
mockStatic(UserCoreUtil.class);
when(UserCoreUtil.isEveryoneRole("role", mockedRealmConfig)).thenReturn(false);
whenNew(GroupDAO.class).withAnyArguments().thenReturn(mockedGroupDAO);
when(mockedGroupDAO.isExistingGroup(anyString(), anyInt())).thenReturn(true);
when(mockedGroupDAO.getSCIMGroupAttributes(anyInt(), anyString())).thenReturn(attributes);
mockStatic(SCIMCommonUtils.class);
when(SCIMCommonUtils.getSCIMGroupURL()).thenReturn("https://localhost:9443/scim2/Groups");
SCIMUserManager scimUserManager = new SCIMUserManager(abstractUserStoreManager, mockedClaimManager);
List<Object> roleList = scimUserManager.listGroupsWithGET(node, 1, null, null, null, "Application", requiredAttributes);
// The first entry is the count of roles.
roleList.remove(0);
assertEquals("Application/MyApp", ((Group) roleList.get(0)).getDisplayName());
assertEquals(roleList.size(), 1);
}
Aggregations