Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSimpleAuthorizationQuery()
        public virtual void testSimpleAuthorizationQuery()
        {
            IList <Authorization> mockAuthorizations = MockProvider.createMockGlobalAuthorizations();
            AuthorizationQuery    mockQuery          = setUpMockQuery(mockAuthorizations);

            Response response = given().queryParam("type", org.camunda.bpm.engine.authorization.Authorization_Fields.AUTH_TYPE_GLOBAL).then().expect().statusCode(Status.OK.StatusCode).when().get(SERVICE_PATH);

            InOrder inOrder = inOrder(mockQuery);

            inOrder.verify(mockQuery).authorizationType(org.camunda.bpm.engine.authorization.Authorization_Fields.AUTH_TYPE_GLOBAL);
            inOrder.verify(mockQuery).list();

            string         content   = response.asString();
            IList <string> instances = from(content).getList("");

            Assert.assertEquals("There should be one authorization returned.", 1, instances.Count);
            Assert.assertNotNull("The returned authorization should not be null.", instances[0]);

            Authorization mockAuthorization = mockAuthorizations[0];

            Assert.assertEquals(mockAuthorization.Id, from(content).getString("[0].id"));
            Assert.assertEquals(mockAuthorization.AuthorizationType, from(content).getInt("[0].type"));
            Assert.assertEquals(Permissions.READ.Name, from(content).getString("[0].permissions[0]"));
            Assert.assertEquals(Permissions.UPDATE.Name, from(content).getString("[0].permissions[1]"));
            Assert.assertEquals(mockAuthorization.UserId, from(content).getString("[0].userId"));
            Assert.assertEquals(mockAuthorization.GroupId, from(content).getString("[0].groupId"));
            Assert.assertEquals(mockAuthorization.ResourceType, from(content).getInt("[0].resourceType"));
            Assert.assertEquals(mockAuthorization.ResourceId, from(content).getString("[0].resourceId"));
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testCompleteGetParameters()
        public virtual void testCompleteGetParameters()
        {
            IList <Authorization> mockAuthorizations = MockProvider.createMockGlobalAuthorizations();
            AuthorizationQuery    mockQuery          = setUpMockQuery(mockAuthorizations);

            IDictionary <string, string> queryParameters = CompleteStringQueryParameters;

            RequestSpecification requestSpecification = given().contentType(POST_JSON_CONTENT_TYPE);

            foreach (KeyValuePair <string, string> paramEntry in queryParameters.SetOfKeyValuePairs())
            {
                requestSpecification.parameter(paramEntry.Key, paramEntry.Value);
            }

            requestSpecification.expect().statusCode(Status.OK.StatusCode).when().get(SERVICE_PATH);

            verify(mockQuery).authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID);
            verify(mockQuery).authorizationType(MockProvider.EXAMPLE_AUTHORIZATION_TYPE);
            verify(mockQuery).userIdIn(new string[] { MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_ID2 });
            verify(mockQuery).groupIdIn(new string[] { MockProvider.EXAMPLE_GROUP_ID, MockProvider.EXAMPLE_GROUP_ID2 });
            verify(mockQuery).resourceType(MockProvider.EXAMPLE_RESOURCE_TYPE_ID);
            verify(mockQuery).resourceId(MockProvider.EXAMPLE_RESOURCE_ID);

            verify(mockQuery).list();
        }
Beispiel #3
0
        protected internal virtual CountResultDto getAuthorizationCount(AuthorizationQueryDto queryDto)
        {
            AuthorizationQuery query = queryDto.toQuery(ProcessEngine);
            long count = query.count();

            return(new CountResultDto(count));
        }
Beispiel #4
0
        //logout user using their authorization token
        public async Task <bool> Logout(string token)
        {
            await Db.Connection.ChangeDataBaseAsync("users");

            using (var cmd = Db.Connection.CreateCommand())
            {
                //get AuthorizationTokenModel from db and if it exists, delete is and return true
                var authorizationQuery = new AuthorizationQuery(Db);
                var authorizationToken = await authorizationQuery.GetTokenModel(token);

                if (authorizationToken != null)
                {
                    //attempt to delete token and return true if token is deleted
                    cmd.CommandText = "DELETE FROM authorization_tokens WHERE token = @token";
                    cmd.Parameters.AddWithValue("@token", token);
                    if (await cmd.ExecuteNonQueryAsync() > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testQueryCount()
        public virtual void testQueryCount()
        {
            AuthorizationQuery mockQuery = setUpMockQuery(MockProvider.createMockAuthorizations());

            expect().statusCode(Status.OK.StatusCode).body("count", equalTo(3)).when().get(SERVICE_COUNT_PATH);

            verify(mockQuery).count();
        }
Beispiel #6
0
 public PostsController(AppDb db)
 {
     Db                 = db;
     userQuery          = new UserDbQuery(Db);
     postQuery          = new PostDbQuery(Db);
     authorizationQuery = new AuthorizationQuery(Db);
     threadQuery        = new ThreadDbQuery(Db);
     locationQuery      = new LocationQuery(Db);
 }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testNoParametersQuery()
        public virtual void testNoParametersQuery()
        {
            AuthorizationQuery mockQuery = setUpMockQuery(MockProvider.createMockAuthorizations());

            expect().statusCode(Status.OK.StatusCode).when().get(SERVICE_PATH);

            verify(mockQuery).list();
            verifyNoMoreInteractions(mockQuery);
        }
Beispiel #8
0
        private AuthorizationQuery setUpMockQuery(IList <Authorization> list)
        {
            AuthorizationQuery query = mock(typeof(AuthorizationQuery));

            when(query.list()).thenReturn(list);
            when(query.count()).thenReturn((long)list.Count);

            when(processEngine.AuthorizationService.createAuthorizationQuery()).thenReturn(query);

            return(query);
        }
Beispiel #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSuccessfulPagination()
        public virtual void testSuccessfulPagination()
        {
            AuthorizationQuery mockQuery = setUpMockQuery(MockProvider.createMockAuthorizations());

            int firstResult = 0;
            int maxResults  = 10;

            given().queryParam("firstResult", firstResult).queryParam("maxResults", maxResults).then().expect().statusCode(Status.OK.StatusCode).when().get(SERVICE_PATH);

            verify(mockQuery).listPage(firstResult, maxResults);
        }
Beispiel #10
0
        // utility methods //////////////////////////////////////

        protected internal virtual IList <Authorization> executePaginatedQuery(AuthorizationQuery query, int?firstResult, int?maxResults)
        {
            if (firstResult == null)
            {
                firstResult = 0;
            }
            if (maxResults == null)
            {
                maxResults = int.MaxValue;
            }
            return(query.listPage(firstResult, maxResults));
        }
Beispiel #11
0
        public virtual IList <AuthorizationDto> queryAuthorizations(AuthorizationQueryDto queryDto, int?firstResult, int?maxResults)
        {
            queryDto.ObjectMapper = ObjectMapper;
            AuthorizationQuery query = queryDto.toQuery(ProcessEngine);

            IList <Authorization> resultList;

            if (firstResult != null || maxResults != null)
            {
                resultList = executePaginatedQuery(query, firstResult, maxResults);
            }
            else
            {
                resultList = query.list();
            }

            return(AuthorizationDto.fromAuthorizationList(resultList, processEngine.ProcessEngineConfiguration));
        }
Beispiel #12
0
        // clear authorization /////////////////////////////////////

        public virtual void testClearAuthorizationOnDeleteDeployment()
        {
            // given
            createGrantAuthorization(DEPLOYMENT, ANY, userId, CREATE);
            Deployment deployment = repositoryService.createDeployment().addClasspathResource(FIRST_RESOURCE).deploy();

            string deploymentId = deployment.Id;

            AuthorizationQuery query = authorizationService.createAuthorizationQuery().userIdIn(userId).resourceId(deploymentId);

            Authorization authorization = query.singleResult();

            assertNotNull(authorization);

            // when
            repositoryService.deleteDeployment(deploymentId);

            authorization = query.singleResult();
            assertNull(authorization);

            deleteDeployment(deploymentId);
        }
 public async Task <ActionResult <AuthorizationResponse> > AuthorizationAsync(AuthorizationQuery query)
 {
     return(await Mediator.Send(query));
 }
Beispiel #14
0
 public UsersController(AppDb db)
 {
     Db                 = db;
     userQuery          = new UserDbQuery(Db);
     authorizationQuery = new AuthorizationQuery(Db);
 }