Search in sources :

Example 1 with ApplicationTypeEntity

use of io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationTypeServiceImpl method getFilteredApplicationTypes.

public ApplicationTypesEntity getFilteredApplicationTypes(JsonNode jsonTypes) {
    ApplicationTypesEntity applicationTypesEntity = this.getApplicationTypesEntity();
    List<ApplicationTypeEntity> filteredData = applicationTypesEntity.getData().stream().filter(typeEntity -> jsonTypes.get(typeEntity.getId()).get("enabled").asBoolean(false)).collect(Collectors.toList());
    applicationTypesEntity.setData(filteredData);
    return applicationTypesEntity;
}
Also used : ConfigService(io.gravitee.rest.api.service.ConfigService) Charset.defaultCharset(java.nio.charset.Charset.defaultCharset) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApplicationTypeService(io.gravitee.rest.api.service.configuration.application.ApplicationTypeService) Autowired(org.springframework.beans.factory.annotation.Autowired) ApplicationTypeNotFoundException(io.gravitee.rest.api.service.exceptions.ApplicationTypeNotFoundException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Application(io.gravitee.rest.api.model.settings.Application) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Component(org.springframework.stereotype.Component) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) JsonNode(com.fasterxml.jackson.databind.JsonNode) ApplicationTypesEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity) InputStream(java.io.InputStream) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) ApplicationTypesEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity)

Example 2 with ApplicationTypeEntity

use of io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationService_CreateTest method shouldNotCreateBecauseRedirectURIsNotFound.

@Test(expected = ApplicationRedirectUrisNotFound.class)
public void shouldNotCreateBecauseRedirectURIsNotFound() {
    ApplicationSettings settings = new ApplicationSettings();
    OAuthClientSettings clientSettings = new OAuthClientSettings();
    clientSettings.setApplicationType("web");
    clientSettings.setGrantTypes(Arrays.asList("foobar"));
    settings.setoAuthClient(clientSettings);
    ApplicationTypeEntity applicationType = mock(ApplicationTypeEntity.class);
    ApplicationGrantTypeEntity foobar = new ApplicationGrantTypeEntity();
    foobar.setType("foobar");
    when(applicationType.getRequires_redirect_uris()).thenReturn(true);
    when(applicationType.getAllowed_grant_types()).thenReturn(Arrays.asList(foobar));
    when(applicationTypeService.getApplicationType(any())).thenReturn(applicationType);
    when(newApplication.getSettings()).thenReturn(settings);
    when(parameterService.findAsBoolean(Key.APPLICATION_REGISTRATION_ENABLED, "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.TRUE);
    when(parameterService.findAsBoolean(Key.APPLICATION_TYPE_WEB_ENABLED, "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.TRUE);
    applicationService.create(newApplication, USER_NAME);
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) ApplicationGrantTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationGrantTypeEntity) Test(org.junit.Test)

Example 3 with ApplicationTypeEntity

use of io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationServiceImpl method checkClientSettings.

private void checkClientSettings(OAuthClientSettings oAuthClientSettings) {
    if (oAuthClientSettings.getGrantTypes() == null || oAuthClientSettings.getGrantTypes().isEmpty()) {
        throw new ApplicationGrantTypesNotFoundException();
    }
    ApplicationTypeEntity applicationType = applicationTypeService.getApplicationType(oAuthClientSettings.getApplicationType());
    List<String> targetGrantTypes = oAuthClientSettings.getGrantTypes();
    List<String> allowedGrantTypes = applicationType.getAllowed_grant_types().stream().map(applicationGrantTypeEntity -> applicationGrantTypeEntity.getType()).collect(toList());
    if (!allowedGrantTypes.containsAll(targetGrantTypes)) {
        throw new ApplicationGrantTypesNotAllowedException(oAuthClientSettings.getApplicationType(), targetGrantTypes);
    }
    List<String> redirectUris = oAuthClientSettings.getRedirectUris();
    if (applicationType.getRequires_redirect_uris() && (redirectUris == null || redirectUris.isEmpty())) {
        throw new ApplicationRedirectUrisNotFound();
    }
    List<String> responseTypes = applicationType.getAllowed_grant_types().stream().filter(applicationGrantTypeEntity -> targetGrantTypes.contains(applicationGrantTypeEntity.getType())).map(applicationGrantTypeEntity -> applicationGrantTypeEntity.getResponse_types()).flatMap(Collection::stream).distinct().collect(toList());
    oAuthClientSettings.setResponseTypes(responseTypes);
}
Also used : io.gravitee.rest.api.service(io.gravitee.rest.api.service) java.util(java.util) AuditEvent(io.gravitee.repository.management.model.Application.AuditEvent) Page(io.gravitee.common.data.domain.Page) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ApplicationTypeService(io.gravitee.rest.api.service.configuration.application.ApplicationTypeService) LoggerFactory(org.slf4j.LoggerFactory) MembershipRepository(io.gravitee.repository.management.api.MembershipRepository) HookScope(io.gravitee.rest.api.service.notification.HookScope) Autowired(org.springframework.beans.factory.annotation.Autowired) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) RoleScope(io.gravitee.rest.api.model.permissions.RoleScope) Collections.singletonList(java.util.Collections.singletonList) ClientRegistrationService(io.gravitee.rest.api.service.configuration.application.ClientRegistrationService) io.gravitee.rest.api.model(io.gravitee.rest.api.model) ApplicationRepository(io.gravitee.repository.management.api.ApplicationRepository) Collectors.toSet(java.util.stream.Collectors.toSet) MembershipMemberType(io.gravitee.rest.api.model.MembershipMemberType) ApplicationHook(io.gravitee.rest.api.service.notification.ApplicationHook) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) UuidString(io.gravitee.rest.api.service.common.UuidString) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ClientRegistrationResponse(io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationResponse) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) Key(io.gravitee.rest.api.model.parameters.Key) Consumer(java.util.function.Consumer) MembershipReferenceType(io.gravitee.rest.api.model.MembershipReferenceType) Collectors.toList(java.util.stream.Collectors.toList) ApplicationCriteria(io.gravitee.repository.management.api.search.ApplicationCriteria) GenericNotificationConfigEntity(io.gravitee.rest.api.model.notification.GenericNotificationConfigEntity) Component(org.springframework.stereotype.Component) io.gravitee.repository.management.model(io.gravitee.repository.management.model) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) SubscriptionQuery(io.gravitee.rest.api.model.subscription.SubscriptionQuery) NotNull(org.jetbrains.annotations.NotNull) DatatypeConverter(javax.xml.bind.DatatypeConverter) ClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity) SystemRole(io.gravitee.rest.api.model.permissions.SystemRole) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) UuidString(io.gravitee.rest.api.service.common.UuidString)

Example 4 with ApplicationTypeEntity

use of io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationResource method getApplicationType.

@GET
@Path("configuration")
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.READ) })
public Response getApplicationType(@PathParam("applicationId") String applicationId) {
    ApplicationEntity applicationEntity = applicationService.findById(applicationId);
    ApplicationTypeEntity applicationType = applicationTypeService.getApplicationType(applicationEntity.getType());
    return Response.ok(applicationType).build();
}
Also used : ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 5 with ApplicationTypeEntity

use of io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity in project gravitee-management-rest-api by gravitee-io.

the class ConfigurationResourceTest method shouldGetApplicationTypes.

@Test
public void shouldGetApplicationTypes() throws TechnicalException {
    resetAllMocks();
    ApplicationTypesEntity typesEntity = new ApplicationTypesEntity();
    List<ApplicationTypeEntity> data = new ArrayList<>();
    ApplicationTypeEntity simple = new ApplicationTypeEntity();
    simple.setId("simple");
    simple.setAllowed_grant_types(new ArrayList<>());
    simple.setDefault_grant_types(new ArrayList<>());
    simple.setMandatory_grant_types(new ArrayList<>());
    simple.setName("Simple");
    simple.setDescription("Simple type");
    data.add(simple);
    ApplicationTypeEntity web = new ApplicationTypeEntity();
    web.setId("web");
    List<ApplicationGrantTypeEntity> grantTypes = new ArrayList<>();
    ApplicationGrantTypeEntity grantType = new ApplicationGrantTypeEntity();
    grantType.setName("name");
    List<String> responses_types = new ArrayList<>();
    responses_types.add("token");
    grantType.setResponse_types(responses_types);
    grantTypes.add(grantType);
    web.setAllowed_grant_types(grantTypes);
    web.setDefault_grant_types(new ArrayList<>());
    web.setMandatory_grant_types(new ArrayList<>());
    web.setName("Web");
    web.setDescription("Web type");
    data.add(web);
    typesEntity.setData(data);
    when(applicationTypeService.getEnabledApplicationTypes()).thenReturn(typesEntity);
    final Response response = target().path("applications").path("types").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    final ConfigurationApplicationTypesResponse appTypes = response.readEntity(ConfigurationApplicationTypesResponse.class);
    assertNotNull(appTypes);
    @Valid List<ApplicationType> types = appTypes.getData();
    assertNotNull(types);
    assertEquals(2, types.size());
    assertEquals("web", types.get(1).getId());
    assertEquals(1, types.get(1).getAllowedGrantTypes().size());
}
Also used : ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) ApplicationGrantTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationGrantTypeEntity) Response(javax.ws.rs.core.Response) Valid(javax.validation.Valid) ApplicationTypesEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity) Test(org.junit.Test)

Aggregations

ApplicationTypeEntity (io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity)7 ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)3 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)3 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)3 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ApplicationGrantTypeEntity (io.gravitee.rest.api.model.configuration.application.ApplicationGrantTypeEntity)2 ApplicationTypesEntity (io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity)2 ApplicationTypeService (io.gravitee.rest.api.service.configuration.application.ApplicationTypeService)2 IOException (java.io.IOException)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Page (io.gravitee.common.data.domain.Page)1 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 ApplicationRepository (io.gravitee.repository.management.api.ApplicationRepository)1 MembershipRepository (io.gravitee.repository.management.api.MembershipRepository)1 ApplicationCriteria (io.gravitee.repository.management.api.search.ApplicationCriteria)1 io.gravitee.repository.management.model (io.gravitee.repository.management.model)1