Search in sources :

Example 1 with OAuthClientSettings

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

the class ApplicationMapperTest method testConvertFromAppEntityOAuthClient.

@Test
public void testConvertFromAppEntityOAuthClient() {
    ApplicationSettings settings = new ApplicationSettings();
    OAuthClientSettings oAuthClientEntitySettings = new OAuthClientSettings();
    oAuthClientEntitySettings.setApplicationType(APPLICATION_OAUTH_APPLICATION_TYPE);
    oAuthClientEntitySettings.setClientId(APPLICATION_OAUTH_CLIENT_ID);
    oAuthClientEntitySettings.setClientSecret(APPLICATION_OAUTH_CLIENT_SECRET);
    oAuthClientEntitySettings.setClientUri(APPLICATION_OAUTH_CLIENT_URI);
    oAuthClientEntitySettings.setGrantTypes(Arrays.asList(APPLICATION_OAUTH_GRANT_TYPE));
    oAuthClientEntitySettings.setLogoUri(APPLICATION_OAUTH_LOGO_URI);
    oAuthClientEntitySettings.setRedirectUris(Arrays.asList(APPLICATION_OAUTH_REDIRECT_URI));
    oAuthClientEntitySettings.setRenewClientSecretSupported(true);
    oAuthClientEntitySettings.setResponseTypes(Arrays.asList(APPLICATION_OAUTH_RESPONSE_TYPE));
    settings.setoAuthClient(oAuthClientEntitySettings);
    applicationEntity.setSettings(settings);
    Application responseApplication = applicationMapper.convert(applicationEntity, uriInfo);
    checkApplication(now, responseApplication, AppSettingsEnum.OAUTH_SETTINGS);
}
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) Application(io.gravitee.rest.api.portal.rest.model.Application) Test(org.junit.Test)

Example 2 with OAuthClientSettings

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

the class ApplicationService_CreateTest method shouldNotCreateBecauseClientRegistrationDisable.

@Test(expected = IllegalStateException.class)
public void shouldNotCreateBecauseClientRegistrationDisable() throws TechnicalException {
    ApplicationSettings settings = new ApplicationSettings();
    OAuthClientSettings clientSettings = new OAuthClientSettings();
    clientSettings.setClientId(CLIENT_ID);
    settings.setoAuthClient(clientSettings);
    when(newApplication.getSettings()).thenReturn(settings);
    when(parameterService.findAsBoolean(Key.APPLICATION_REGISTRATION_ENABLED, "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.FALSE);
    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) Test(org.junit.Test)

Example 3 with OAuthClientSettings

use of io.gravitee.rest.api.model.application.OAuthClientSettings 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 4 with OAuthClientSettings

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

the class ApplicationService_CreateTest method shouldNotCreateBecauseGrantTypesIsEmpty.

@Test(expected = ApplicationGrantTypesNotFoundException.class)
public void shouldNotCreateBecauseGrantTypesIsEmpty() {
    ApplicationSettings settings = new ApplicationSettings();
    OAuthClientSettings clientSettings = new OAuthClientSettings();
    clientSettings.setApplicationType("web");
    settings.setoAuthClient(clientSettings);
    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) Test(org.junit.Test)

Example 5 with OAuthClientSettings

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

the class ApplicationMapper method convert.

public Application convert(ApplicationEntity applicationEntity, UriInfo uriInfo) {
    final Application application = new Application();
    application.setApplicationType(applicationEntity.getType());
    application.setCreatedAt(applicationEntity.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
    application.setDescription(applicationEntity.getDescription());
    Set<String> groupEntities = applicationEntity.getGroups();
    if (groupEntities != null && !groupEntities.isEmpty()) {
        List<Group> groups = groupEntities.stream().map(groupService::findById).map(groupEntity -> new Group().id(groupEntity.getId()).name(groupEntity.getName())).collect(Collectors.toList());
        application.setGroups(groups);
    }
    application.setId(applicationEntity.getId());
    application.setName(applicationEntity.getName());
    UserEntity primaryOwnerUserEntity = userService.findById(applicationEntity.getPrimaryOwner().getId());
    User owner = userMapper.convert(primaryOwnerUserEntity);
    owner.setLinks(userMapper.computeUserLinks(usersURL(uriInfo.getBaseUriBuilder(), primaryOwnerUserEntity.getId()), primaryOwnerUserEntity.getUpdatedAt()));
    application.setOwner(owner);
    application.setUpdatedAt(applicationEntity.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC));
    application.setPicture(applicationEntity.getPicture());
    application.setBackground(applicationEntity.getBackground());
    final ApplicationSettings applicationEntitySettings = applicationEntity.getSettings();
    if (applicationEntitySettings != null) {
        io.gravitee.rest.api.portal.rest.model.ApplicationSettings appSettings = new io.gravitee.rest.api.portal.rest.model.ApplicationSettings();
        final SimpleApplicationSettings simpleAppEntitySettings = applicationEntitySettings.getApp();
        if (simpleAppEntitySettings != null) {
            appSettings.app(new io.gravitee.rest.api.portal.rest.model.SimpleApplicationSettings().clientId(simpleAppEntitySettings.getClientId()).type(simpleAppEntitySettings.getType()));
            application.setHasClientId(simpleAppEntitySettings.getClientId() != null);
        } else {
            final OAuthClientSettings oAuthClientEntitySettings = applicationEntitySettings.getoAuthClient();
            appSettings.oauth(new io.gravitee.rest.api.portal.rest.model.OAuthClientSettings().applicationType(oAuthClientEntitySettings.getApplicationType()).clientId(oAuthClientEntitySettings.getClientId()).clientSecret(oAuthClientEntitySettings.getClientSecret()).clientUri(oAuthClientEntitySettings.getClientUri()).logoUri(oAuthClientEntitySettings.getLogoUri()).grantTypes(oAuthClientEntitySettings.getGrantTypes()).redirectUris(oAuthClientEntitySettings.getRedirectUris()).responseTypes(oAuthClientEntitySettings.getResponseTypes()).renewClientSecretSupported(oAuthClientEntitySettings.isRenewClientSecretSupported()));
            application.setHasClientId(oAuthClientEntitySettings.getClientId() != null);
        }
        application.setSettings(appSettings);
    }
    return application;
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) Group(io.gravitee.rest.api.portal.rest.model.Group) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) GroupService(io.gravitee.rest.api.service.GroupService) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) User(io.gravitee.rest.api.portal.rest.model.User) Collectors(java.util.stream.Collectors) Application(io.gravitee.rest.api.portal.rest.model.Application) List(java.util.List) Component(org.springframework.stereotype.Component) OffsetDateTime(java.time.OffsetDateTime) UserService(io.gravitee.rest.api.service.UserService) ZoneOffset(java.time.ZoneOffset) UriInfo(javax.ws.rs.core.UriInfo) PortalApiLinkHelper.usersURL(io.gravitee.rest.api.portal.rest.utils.PortalApiLinkHelper.usersURL) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) ApplicationLinks(io.gravitee.rest.api.portal.rest.model.ApplicationLinks) Group(io.gravitee.rest.api.portal.rest.model.Group) User(io.gravitee.rest.api.portal.rest.model.User) UserEntity(io.gravitee.rest.api.model.UserEntity) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) Application(io.gravitee.rest.api.portal.rest.model.Application)

Aggregations

ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)12 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)12 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)11 Test (org.junit.Test)7 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)3 ApplicationTypeEntity (io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity)3 Application (io.gravitee.rest.api.portal.rest.model.Application)3 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)2 ClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity)2 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)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