Search in sources :

Example 96 with Node

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;
    }
}
Also used : BLangUnionTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangUnionTypeNode) ArrayList(java.util.ArrayList) BLangType(org.wso2.ballerinalang.compiler.tree.types.BLangType) BLangSimpleVariable(org.wso2.ballerinalang.compiler.tree.BLangSimpleVariable) HashSet(java.util.HashSet)

Example 97 with Node

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");
}
Also used : OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test)

Example 98 with Node

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");
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpPost(org.apache.http.client.methods.HttpPost) InputStreamReader(java.io.InputStreamReader) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) BufferedReader(java.io.BufferedReader) HttpResponse(org.apache.http.HttpResponse) JSONObject(org.json.simple.JSONObject) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test)

Example 99 with Node

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);
}
Also used : Group(org.wso2.charon3.core.objects.Group) User(org.wso2.charon3.core.objects.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Condition(org.wso2.carbon.user.core.model.Condition) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 100 with Node

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);
}
Also used : ExpressionNode(org.wso2.charon3.core.utils.codeutils.ExpressionNode) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ArrayList (java.util.ArrayList)33 Operation (io.swagger.v3.oas.annotations.Operation)26 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)26 Response (javax.ws.rs.core.Response)26 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)25 Test (org.testng.annotations.Test)24 Node (org.wso2.charon3.core.utils.codeutils.Node)22 ExpressionNode (org.wso2.charon3.core.utils.codeutils.ExpressionNode)20 IOException (java.io.IOException)19 Node (org.w3c.dom.Node)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 List (java.util.List)16 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)16 OperationNode (org.wso2.charon3.core.utils.codeutils.OperationNode)16 Artifacts (org.wso2.ei.dashboard.core.rest.model.Artifacts)15 CAppArtifacts (org.wso2.ei.dashboard.core.rest.model.CAppArtifacts)15 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)13 Ack (org.wso2.ei.dashboard.core.rest.model.Ack)13 Map (java.util.Map)12 NodeList (org.w3c.dom.NodeList)12