Search in sources :

Example 11 with ApplicationEntity

use of io.gravitee.management.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class AnalyticsServiceImpl method getApplicationMetadata.

private Map<String, String> getApplicationMetadata(String application) {
    Map<String, String> metadata = new HashMap<>();
    try {
        ApplicationEntity applicationEntity = applicationService.findById(application);
        metadata.put("name", applicationEntity.getName());
        if (ApplicationStatus.ARCHIVED.toString().equals(applicationEntity.getStatus())) {
            metadata.put("deleted", "true");
        }
    } catch (ApplicationNotFoundException anfe) {
        metadata.put("deleted", "true");
        if (application.equals(APPLICATION_KEYLESS)) {
            metadata.put("name", "Unknown application (keyless)");
        } else {
            metadata.put("name", "Deleted application");
        }
    }
    return metadata;
}
Also used : ApplicationEntity(io.gravitee.management.model.ApplicationEntity)

Example 12 with ApplicationEntity

use of io.gravitee.management.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationMembersResource method getPermissions.

@GET
@Path("/permissions")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get application members", notes = "User must have the APPLICATION_MEMBER permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Application member's permissions", response = MemberEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_MEMBER, acls = RolePermissionAction.READ) })
public Response getPermissions(@PathParam("application") String application) {
    Map<String, char[]> permissions = new HashMap<>();
    if (isAuthenticated()) {
        final String username = getAuthenticatedUser();
        final ApplicationEntity applicationEntity = applicationService.findById(application);
        if (isAdmin()) {
            final char[] rights = new char[] { CREATE.getId(), READ.getId(), UPDATE.getId(), DELETE.getId() };
            for (ApplicationPermission perm : ApplicationPermission.values()) {
                permissions.put(perm.getName(), rights);
            }
        } else {
            permissions = membershipService.getMemberPermissions(applicationEntity, username);
        }
    }
    return Response.ok(permissions).build();
}
Also used : HashMap(java.util.HashMap) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) ApplicationPermission(io.gravitee.management.model.permissions.ApplicationPermission) Permissions(io.gravitee.management.rest.security.Permissions)

Example 13 with ApplicationEntity

use of io.gravitee.management.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApiSubscribersResource method listApiSubscribers.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List subscribers for the API", notes = "User must have the MANAGE_SUBSCRIPTIONS permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Paged result of API subscribers", response = ApplicationEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_SUBSCRIPTION, acls = RolePermissionAction.READ) })
public Collection<ApplicationEntity> listApiSubscribers(@PathParam("api") String api) {
    SubscriptionQuery subscriptionQuery = new SubscriptionQuery();
    subscriptionQuery.setApi(api);
    Collection<SubscriptionEntity> subscriptions = subscriptionService.search(subscriptionQuery);
    return subscriptions.stream().map(SubscriptionEntity::getApplication).distinct().map(application -> applicationService.findById(application)).sorted((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName())).collect(Collectors.toList());
}
Also used : SubscriptionQuery(io.gravitee.management.model.subscription.SubscriptionQuery) Permission(io.gravitee.management.rest.security.Permission) PathParam(javax.ws.rs.PathParam) Context(javax.ws.rs.core.Context) SubscriptionService(io.gravitee.management.service.SubscriptionService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Collection(java.util.Collection) RolePermission(io.gravitee.management.model.permissions.RolePermission) RolePermissionAction(io.gravitee.management.model.permissions.RolePermissionAction) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Permissions(io.gravitee.management.rest.security.Permissions) ApiResponses(io.swagger.annotations.ApiResponses) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ApplicationService(io.gravitee.management.service.ApplicationService) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(io.gravitee.common.http.MediaType) ApiResponse(io.swagger.annotations.ApiResponse) ResourceContext(javax.ws.rs.container.ResourceContext) SubscriptionEntity(io.gravitee.management.model.SubscriptionEntity) Api(io.swagger.annotations.Api) SubscriptionEntity(io.gravitee.management.model.SubscriptionEntity) SubscriptionQuery(io.gravitee.management.model.subscription.SubscriptionQuery) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.management.rest.security.Permissions) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with ApplicationEntity

use of io.gravitee.management.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationService_FindByUserTest method shouldFindByUser.

@Test
public void shouldFindByUser() throws Exception {
    when(appMembership.getReferenceId()).thenReturn(APPLICATION_ID);
    when(application.getId()).thenReturn(APPLICATION_ID);
    when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
    when(membershipRepository.findByUserAndReferenceType(USERNAME, MembershipReferenceType.APPLICATION)).thenReturn(Collections.singleton(appMembership));
    when(applicationRepository.findByIds(Collections.singletonList(APPLICATION_ID))).thenReturn(Collections.singleton(application));
    when(membershipRepository.findByUserAndReferenceType(USERNAME, MembershipReferenceType.GROUP)).thenReturn(Collections.emptySet());
    when(applicationRepository.findByGroups(Collections.emptyList(), ApplicationStatus.ACTIVE)).thenReturn(Collections.emptySet());
    Membership po = new Membership(USERNAME, APPLICATION_ID, MembershipReferenceType.APPLICATION);
    po.setRoles(Collections.singletonMap(RoleScope.APPLICATION.getId(), SystemRole.PRIMARY_OWNER.name()));
    when(membershipRepository.findByReferencesAndRole(any(), any(), eq(RoleScope.APPLICATION), any())).thenReturn(Collections.singleton(po));
    when(userService.findByUsername(USERNAME, false)).thenReturn(new UserEntity());
    Set<ApplicationEntity> apps = applicationService.findByUser(USERNAME);
    Assert.assertNotNull(apps);
    Assert.assertFalse("should find app", apps.isEmpty());
    Assert.assertEquals(APPLICATION_ID, apps.iterator().next().getId());
}
Also used : ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Membership(io.gravitee.repository.management.model.Membership) UserEntity(io.gravitee.management.model.UserEntity) Test(org.junit.Test)

Example 15 with ApplicationEntity

use of io.gravitee.management.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationService_FindByUserTest method shouldNotFindByUserBecauseOfArchived.

@Test
public void shouldNotFindByUserBecauseOfArchived() throws Exception {
    when(appMembership.getReferenceId()).thenReturn(APPLICATION_ID);
    when(application.getId()).thenReturn(APPLICATION_ID);
    when(application.getStatus()).thenReturn(ApplicationStatus.ARCHIVED);
    when(membershipRepository.findByUserAndReferenceType(USERNAME, MembershipReferenceType.APPLICATION)).thenReturn(Collections.singleton(appMembership));
    when(applicationRepository.findByIds(Collections.singletonList(APPLICATION_ID))).thenReturn(Collections.singleton(application));
    when(membershipRepository.findByUserAndReferenceType(USERNAME, MembershipReferenceType.GROUP)).thenReturn(Collections.emptySet());
    when(applicationRepository.findByGroups(Collections.emptyList(), ApplicationStatus.ACTIVE)).thenReturn(Collections.emptySet());
    Membership po = new Membership(USERNAME, APPLICATION_ID, MembershipReferenceType.APPLICATION);
    po.setRoles(Collections.singletonMap(RoleScope.APPLICATION.getId(), SystemRole.PRIMARY_OWNER.name()));
    when(membershipRepository.findByReferencesAndRole(any(), any(), eq(RoleScope.APPLICATION), any())).thenReturn(Collections.singleton(po));
    when(userService.findByUsername(USERNAME, false)).thenReturn(new UserEntity());
    Set<ApplicationEntity> apps = applicationService.findByUser(USERNAME);
    Assert.assertNotNull(apps);
    Assert.assertTrue("should not find app", apps.isEmpty());
}
Also used : ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Membership(io.gravitee.repository.management.model.Membership) UserEntity(io.gravitee.management.model.UserEntity) Test(org.junit.Test)

Aggregations

ApplicationEntity (io.gravitee.management.model.ApplicationEntity)16 Test (org.junit.Test)9 Membership (io.gravitee.repository.management.model.Membership)6 UserEntity (io.gravitee.management.model.UserEntity)5 Permission (io.gravitee.management.rest.security.Permission)4 RolePermission (io.gravitee.management.model.permissions.RolePermission)3 Permissions (io.gravitee.management.rest.security.Permissions)3 MediaType (io.gravitee.common.http.MediaType)2 ApiEntity (io.gravitee.management.model.ApiEntity)2 UpdateApplicationEntity (io.gravitee.management.model.UpdateApplicationEntity)2 RolePermissionAction (io.gravitee.management.model.permissions.RolePermissionAction)2 ApplicationService (io.gravitee.management.service.ApplicationService)2 Application (io.gravitee.repository.management.model.Application)2 Api (io.swagger.annotations.Api)2 Principal (java.security.Principal)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2