use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_CreateTest method shouldNotCreateForUserBecauseTechnicalException.
@Test(expected = TechnicalManagementException.class)
public void shouldNotCreateForUserBecauseTechnicalException() throws TechnicalException {
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings clientSettings = new SimpleApplicationSettings();
clientSettings.setClientId(CLIENT_ID);
settings.setApp(clientSettings);
when(newApplication.getSettings()).thenReturn(settings);
when(applicationRepository.findAllByEnvironment("DEFAULT", ApplicationStatus.ACTIVE)).thenThrow(TechnicalException.class);
applicationService.create(newApplication, USER_NAME);
}
use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_CreateTest method shouldCreateForUser.
@Test
public void shouldCreateForUser() throws TechnicalException {
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings clientSettings = new SimpleApplicationSettings();
clientSettings.setClientId(CLIENT_ID);
settings.setApp(clientSettings);
when(newApplication.getSettings()).thenReturn(settings);
when(application.getName()).thenReturn(APPLICATION_NAME);
when(application.getType()).thenReturn(ApplicationType.SIMPLE);
when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
when(applicationRepository.create(any())).thenReturn(application);
when(newApplication.getName()).thenReturn(APPLICATION_NAME);
when(newApplication.getDescription()).thenReturn("My description");
when(groupService.findByEvent(any())).thenReturn(Collections.emptySet());
when(userService.findById(any())).thenReturn(mock(UserEntity.class));
final ApplicationEntity applicationEntity = applicationService.create(newApplication, USER_NAME);
assertNotNull(applicationEntity);
assertEquals(APPLICATION_NAME, applicationEntity.getName());
}
use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_CreateTest method shouldNotCreateBecauseAppTypeIsNotAllowed.
@Test(expected = IllegalStateException.class)
public void shouldNotCreateBecauseAppTypeIsNotAllowed() {
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);
applicationService.create(newApplication, USER_NAME);
}
use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class UserServiceImpl method connect.
@Override
public UserEntity connect(String userId) {
try {
LOGGER.debug("Connection of {}", userId);
Optional<User> checkUser = userRepository.findById(userId);
if (!checkUser.isPresent()) {
throw new UserNotFoundException(userId);
}
User user = checkUser.get();
User previousUser = new User(user);
// First connection: create default application for user & notify
if (user.getLastConnectionAt() == null && user.getFirstConnectionAt() == null) {
notifierService.trigger(PortalHook.USER_FIRST_LOGIN, new NotificationParamsBuilder().user(convert(user, false)).build());
user.setFirstConnectionAt(new Date());
if (defaultApplicationForFirstConnection) {
LOGGER.debug("Create a default application for {}", userId);
NewApplicationEntity defaultApp = new NewApplicationEntity();
defaultApp.setName("Default application");
defaultApp.setDescription("My default application");
// To preserve backward compatibility, ensure that we have at least default settings for simple application type
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings simpleAppSettings = new SimpleApplicationSettings();
settings.setApp(simpleAppSettings);
defaultApp.setSettings(settings);
try {
environmentService.findByUser(userId).forEach(env -> applicationService.create(defaultApp, userId, env.getId()));
} catch (IllegalStateException ex) {
// do not fail to create a user even if we are not able to create its default app
LOGGER.warn("Not able to create default app for user {}", userId);
}
}
}
// Set date fields
user.setLastConnectionAt(new Date());
if (user.getFirstConnectionAt() == null) {
user.setFirstConnectionAt(user.getLastConnectionAt());
}
user.setUpdatedAt(user.getLastConnectionAt());
user.setLoginCount(user.getLoginCount() + 1);
User updatedUser = userRepository.update(user);
auditService.createOrganizationAuditLog(Collections.singletonMap(USER, userId), User.AuditEvent.USER_CONNECTED, user.getUpdatedAt(), previousUser, user);
final UserEntity userEntity = convert(updatedUser, true);
searchEngineService.index(userEntity, false);
return userEntity;
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to connect {}", userId, ex);
throw new TechnicalManagementException("An error occurs while trying to connect " + userId, ex);
}
}
use of io.gravitee.rest.api.model.application.ApplicationSettings in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_UpdateTest method shouldNotUpdateBecauseTechnicalException.
@Test(expected = TechnicalManagementException.class)
public void shouldNotUpdateBecauseTechnicalException() throws TechnicalException {
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings clientSettings = new SimpleApplicationSettings();
clientSettings.setClientId(CLIENT_ID);
settings.setApp(clientSettings);
when(existingApplication.getSettings()).thenReturn(settings);
when(application.getType()).thenReturn(ApplicationType.SIMPLE);
when(applicationRepository.findById(APPLICATION_ID)).thenReturn(Optional.of(application));
when(applicationRepository.update(any())).thenThrow(TechnicalException.class);
when(existingApplication.getName()).thenReturn(APPLICATION_NAME);
when(existingApplication.getDescription()).thenReturn("My description");
applicationService.update(APPLICATION_ID, existingApplication);
}
Aggregations