use of io.gravitee.management.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class AuthenticationSuccessListenerTest method shouldConnectFoundUser.
@Test
public void shouldConnectFoundUser() {
when(eventMock.getAuthentication()).thenReturn(authenticationMock);
when(authenticationMock.getPrincipal()).thenReturn(userDetailsMock);
when(userDetailsMock.getUsername()).thenReturn(USERNAME);
when(userServiceMock.create(any())).thenReturn(userEntity);
when(userServiceMock.findByUsername(userDetailsMock.getUsername(), false)).thenReturn(new UserEntity());
listener.onApplicationEvent(eventMock);
verify(userServiceMock, times(1)).findByUsername(userDetailsMock.getUsername(), false);
verify(userServiceMock, never()).create(any(NewExternalUserEntity.class), anyBoolean());
verify(userServiceMock, times(1)).connect(userDetailsMock.getUsername());
}
use of io.gravitee.management.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class GoogleAuthenticationResource method processUser.
private Response processUser(final Map<String, Object> userInfo) {
String username = (String) userInfo.get("email");
// set user to Authentication Context
UserDetails userDetails = new UserDetails(username, "", Collections.emptyList());
userDetails.setEmail(username);
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()));
try {
UserEntity registeredUser = userService.findByUsername(username, false);
userDetails.setUsername(registeredUser.getId());
} catch (UserNotFoundException unfe) {
final NewExternalUserEntity newUser = new NewExternalUserEntity();
newUser.setUsername(username);
newUser.setSource(AuthenticationSource.GOOGLE.getName());
newUser.setSourceId(userInfo.get("sub").toString());
newUser.setFirstname(userInfo.get("given_name").toString());
newUser.setLastname(userInfo.get("family_name").toString());
newUser.setEmail(username);
UserEntity createdUser = userService.create(newUser, true);
userDetails.setUsername(createdUser.getId());
}
// User refresh
UpdateUserEntity user = new UpdateUserEntity();
user.setUsername(username);
user.setPicture(userInfo.get("picture").toString());
userService.update(user);
return connectUser(userDetails.getUsername());
}
use of io.gravitee.management.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class EventServiceImpl method convert.
private EventEntity convert(Event event) {
EventEntity eventEntity = new EventEntity();
eventEntity.setId(event.getId());
eventEntity.setType(io.gravitee.management.model.EventType.valueOf(event.getType().toString()));
eventEntity.setPayload(event.getPayload());
eventEntity.setParentId(event.getParentId());
eventEntity.setProperties(event.getProperties());
eventEntity.setCreatedAt(event.getCreatedAt());
eventEntity.setUpdatedAt(event.getUpdatedAt());
if (event.getProperties() != null) {
final String userId = event.getProperties().get(Event.EventProperties.USER.getValue());
if (userId != null && !userId.isEmpty()) {
try {
eventEntity.setUser(userService.findById(userId));
} catch (UserNotFoundException unfe) {
UserEntity user = new UserEntity();
user.setSource("system");
user.setId(userId);
user.setUsername("system");
eventEntity.setUser(user);
}
}
}
return eventEntity;
}
use of io.gravitee.management.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_CreateTest method shouldNotCreateForUserBecauseTechnicalException.
@Test(expected = TechnicalManagementException.class)
public void shouldNotCreateForUserBecauseTechnicalException() throws TechnicalException {
when(apiRepository.findById(anyString())).thenThrow(TechnicalException.class);
when(newApi.getName()).thenReturn(API_NAME);
when(newApi.getVersion()).thenReturn("v1");
when(newApi.getDescription()).thenReturn("Ma description");
when(userService.findByUsername(USER_NAME, false)).thenReturn(new UserEntity());
apiService.create(newApi, USER_NAME);
}
use of io.gravitee.management.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_CreateTest method shouldCreateWithDefaultPath.
@Test
public void shouldCreateWithDefaultPath() throws TechnicalException {
when(api.getId()).thenReturn(API_ID);
when(api.getName()).thenReturn(API_NAME);
when(api.getVisibility()).thenReturn(Visibility.PRIVATE);
when(apiRepository.findById(anyString())).thenReturn(Optional.empty());
when(apiRepository.create(any())).thenReturn(api);
when(newApi.getName()).thenReturn(API_NAME);
when(newApi.getVersion()).thenReturn("v1");
when(newApi.getDescription()).thenReturn("Ma description");
when(newApi.getContextPath()).thenReturn("/context");
UserEntity admin = new UserEntity();
admin.setUsername(USER_NAME);
when(userService.findById(admin.getUsername())).thenReturn(admin);
final ApiEntity apiEntity = apiService.create(newApi, USER_NAME);
assertNotNull(apiEntity);
assertEquals(API_NAME, apiEntity.getName());
assertNotNull(apiEntity.getPaths());
/*assertTrue("paths not empty", !apiEntity.getPaths().isEmpty());
assertEquals("paths.size == 1", apiEntity.getPaths().size(), 1);
assertEquals("path == /* ", apiEntity.getPaths().get(0).getPath(), "/*");*/
}
Aggregations