Skip to content
Snippets Groups Projects
Verified Commit 1cb9290a authored by Martin Weise's avatar Martin Weise
Browse files

Fixed initial setup

parent b7462e4c
Branches
Tags
4 merge requests!231CI: Remove build for log-service,!228Better error message handling in the frontend,!223Release of version 1.4.0,!191Fixed the DataCite issue of minting new dois
Showing
with 36 additions and 61 deletions
......@@ -17,7 +17,7 @@ import jakarta.validation.constraints.NotNull;
public class ApiErrorDto {
@NotNull(message = "http status is required")
@Schema(example = "STATUS")
@Schema(example = "NOT_FOUND")
private HttpStatus status;
@NotNull(message = "message is required")
......
......@@ -146,7 +146,6 @@ public class DatabaseEndpoint {
principal);
final User user = userService.findByUsername(principal.getName());
final Database database = databaseService.create(createDto, principal);
messageQueueService.createUser(user.getUsername());
messageQueueService.createExchange(database, principal);
queryStoreService.create(database.getId(), principal);
databaseAccessRepository.save(databaseMapper.defaultCreatorAccess(database, UserUtil.getId(principal)));
......
......@@ -7,6 +7,7 @@ import at.tuwien.entities.user.User;
import at.tuwien.exception.*;
import at.tuwien.mapper.UserMapper;
import at.tuwien.service.DatabaseService;
import at.tuwien.service.MessageQueueService;
import at.tuwien.service.UserService;
import at.tuwien.utils.UserUtil;
import io.micrometer.core.annotation.Timed;
......@@ -40,13 +41,16 @@ public class UserEndpoint {
private final UserMapper userMapper;
private final UserService userService;
private final DatabaseService databaseService;
private final MessageQueueService messageQueueService;
@Autowired
public UserEndpoint(UserMapper userMapper, UserService userService, DatabaseService databaseService) {
public UserEndpoint(UserMapper userMapper, UserService userService, DatabaseService databaseService,
MessageQueueService messageQueueService) {
this.userMapper = userMapper;
this.userService = userService;
this.databaseService = databaseService;
this.messageQueueService = messageQueueService;
}
@GetMapping
......@@ -99,14 +103,14 @@ public class UserEndpoint {
})
public ResponseEntity<UserBriefDto> create(@NotNull @Valid @RequestBody SignupRequestDto data)
throws RealmNotFoundException, UserAlreadyExistsException, UserEmailAlreadyExistsException,
UserNotFoundException, KeycloakRemoteException, AccessDeniedException {
UserNotFoundException, KeycloakRemoteException, AccessDeniedException, BrokerVirtualHostCreationException {
log.debug("endpoint create a user, data={}", data);
/* check */
userService.validateUsernameNotExists(data.getUsername());
userService.validateEmailNotExists(data.getEmail());
/* create */
final User user = userService.create(data);
final UserBriefDto dto = userMapper.userToUserBriefDto(user);
final UserBriefDto dto = userMapper.userToUserBriefDto(userService.create(data));
messageQueueService.createUser(dto.getUsername());
log.trace("create user resulted in dto {}", dto);
return ResponseEntity.status(HttpStatus.CREATED)
.body(dto);
......
......@@ -7,6 +7,7 @@ import at.tuwien.api.auth.SignupRequestDto;
import at.tuwien.api.user.*;
import at.tuwien.entities.user.User;
import at.tuwien.exception.*;
import at.tuwien.service.MessageQueueService;
import at.tuwien.service.UserService;
import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.Test;
......@@ -40,6 +41,9 @@ public class UserEndpointUnitTest extends BaseUnitTest {
@MockBean
private UserService userService;
@MockBean
private MessageQueueService messageQueueService;
@Autowired
private UserEndpoint userEndpoint;
......@@ -63,7 +67,7 @@ public class UserEndpointUnitTest extends BaseUnitTest {
@WithAnonymousUser
public void create_anonymous_succeeds() throws UserNotFoundException, UserEmailAlreadyExistsException,
RealmNotFoundException, UserAlreadyExistsException, KeycloakRemoteException,
at.tuwien.exception.AccessDeniedException {
at.tuwien.exception.AccessDeniedException, BrokerVirtualHostCreationException {
final SignupRequestDto request = SignupRequestDto.builder()
.email(USER_1_EMAIL)
.username(USER_1_USERNAME)
......@@ -300,11 +304,14 @@ public class UserEndpointUnitTest extends BaseUnitTest {
protected void create_generic(SignupRequestDto data, User user) throws UserEmailAlreadyExistsException,
RealmNotFoundException, UserAlreadyExistsException, UserNotFoundException, KeycloakRemoteException,
AccessDeniedException {
AccessDeniedException, BrokerVirtualHostCreationException {
/* mock */
when(userService.create(data))
.thenReturn(user);
doNothing()
.when(messageQueueService)
.createUser(anyString());
/* test */
final ResponseEntity<UserBriefDto> response = userEndpoint.create(data);
......
......@@ -92,7 +92,7 @@ public class UserServiceIntegrationTest extends BaseUnitTest {
@Test
public void create_succeeds() throws UserAlreadyExistsException, UserNotFoundException, KeycloakRemoteException,
AccessDeniedException {
AccessDeniedException, UserEmailAlreadyExistsException {
final SignupRequestDto request = SignupRequestDto.builder()
.username(USER_2_USERNAME)
.password(USER_2_PASSWORD)
......@@ -113,7 +113,7 @@ public class UserServiceIntegrationTest extends BaseUnitTest {
.build();
/* test */
assertThrows(UserAlreadyExistsException.class, () -> {
assertThrows(UserEmailAlreadyExistsException.class, () -> {
userService.create(request);
});
}
......@@ -168,7 +168,7 @@ public class UserServiceIntegrationTest extends BaseUnitTest {
@Test
public void updatePassword_succeeds() throws KeycloakRemoteException, AccessDeniedException, UserNotFoundException,
UserAlreadyExistsException {
UserAlreadyExistsException, UserEmailAlreadyExistsException {
final UserPasswordDto request = UserPasswordDto.builder()
.password(USER_3_PASSWORD)
.build();
......
......@@ -78,7 +78,7 @@ public class UserServiceUnitTest extends BaseUnitTest {
@Test
public void create_succeeds() throws UserNotFoundException, KeycloakRemoteException, AccessDeniedException,
UserAlreadyExistsException {
UserAlreadyExistsException, UserEmailAlreadyExistsException {
/* mock */
when(userRepository.findById(USER_1_ID))
......
......@@ -3,16 +3,13 @@ package at.tuwien.gateway;
import at.tuwien.api.keycloak.UserCreateDto;
import at.tuwien.api.keycloak.UserDto;
import at.tuwien.api.user.UserPasswordDto;
import at.tuwien.exception.AccessDeniedException;
import at.tuwien.exception.KeycloakRemoteException;
import at.tuwien.exception.UserAlreadyExistsException;
import at.tuwien.exception.UserNotFoundException;
import at.tuwien.exception.*;
import java.util.UUID;
public interface KeycloakGateway {
void createUser(UserCreateDto data) throws AccessDeniedException, KeycloakRemoteException, UserAlreadyExistsException;
void createUser(UserCreateDto data) throws AccessDeniedException, KeycloakRemoteException, UserAlreadyExistsException, UserEmailAlreadyExistsException;
void updateUserCredentials(UUID id, UserPasswordDto password) throws AccessDeniedException,
KeycloakRemoteException;
......
......@@ -3,10 +3,7 @@ package at.tuwien.gateway.impl;
import at.tuwien.api.keycloak.*;
import at.tuwien.api.user.UserPasswordDto;
import at.tuwien.config.KeycloakConfig;
import at.tuwien.exception.AccessDeniedException;
import at.tuwien.exception.KeycloakRemoteException;
import at.tuwien.exception.UserAlreadyExistsException;
import at.tuwien.exception.UserNotFoundException;
import at.tuwien.exception.*;
import at.tuwien.gateway.KeycloakGateway;
import at.tuwien.mapper.UserMapper;
import lombok.extern.log4j.Log4j2;
......@@ -57,7 +54,7 @@ public class KeycloakGatewayImpl implements KeycloakGateway {
@Override
public void createUser(UserCreateDto data) throws AccessDeniedException, KeycloakRemoteException,
UserAlreadyExistsException {
UserAlreadyExistsException, UserEmailAlreadyExistsException {
/* obtain admin token */
final HttpHeaders headers = new HttpHeaders();
headers.set("Accept", "application/json");
......@@ -70,9 +67,14 @@ public class KeycloakGatewayImpl implements KeycloakGateway {
log.error("Failed to create user: {}", e.getMessage());
throw new KeycloakRemoteException("Failed to create user: " + e.getMessage());
} catch (HttpClientErrorException.Conflict e) {
if (e.getMessage().contains("same email")) {
log.error("Conflict when creating user: {}", e.getMessage());
throw new UserEmailAlreadyExistsException("Conflict when creating user: " + e.getMessage());
} else {
log.error("Conflict when creating user: {}", e.getMessage());
throw new UserAlreadyExistsException("Conflict when creating user: " + e.getMessage());
}
}
if (!response.getStatusCode().equals(HttpStatus.CREATED)) {
log.error("Failed to create user: status {} was not expected", response.getStatusCode().value());
throw new KeycloakRemoteException("Failed to create user: status " + response.getStatusCode().value() + "was not expected");
......
......@@ -43,7 +43,7 @@ public interface UserService {
* @throws UserAlreadyExistsException The user already exists in the metadata database.
*/
User create(SignupRequestDto data) throws UserAlreadyExistsException, AccessDeniedException,
KeycloakRemoteException, UserNotFoundException;
KeycloakRemoteException, UserNotFoundException, UserEmailAlreadyExistsException;
/**
* Updates the user information for a user with given id in the metadata database.
......
......@@ -64,7 +64,7 @@ public class UserServiceImpl implements UserService {
@Override
public User create(SignupRequestDto data) throws UserAlreadyExistsException, AccessDeniedException,
KeycloakRemoteException, UserNotFoundException {
KeycloakRemoteException, UserNotFoundException, UserEmailAlreadyExistsException {
/* create at authentication service */
final User entity = User.builder()
.username(data.getUsername())
......
......@@ -8,12 +8,6 @@
<v-form ref="form" v-model="valid" @submit.prevent="submit">
<v-card flat tile>
<v-card-text>
<v-alert
v-if="mailVerify"
border="left"
color="info">
Before you can use the repository, you will need to <i>confirm</i> your email address, make sure to check your spam folder.
</v-alert>
<v-row dense>
<v-col sm="6">
<v-text-field
......@@ -108,9 +102,6 @@ export default {
loadingColor () {
return this.error ? 'red lighten-2' : 'primary'
},
mailVerify () {
return this.$config.mailVerify
}
},
mounted () {
this.loadUsers()
......@@ -123,7 +114,7 @@ export default {
this.loading = true
UserService.create(this.createAccount)
.then(() => {
this.$toast.success(`Success! ${this.mailVerify ? 'Check your inbox!' : ''}`)
this.$toast.success('Success!')
this.$router.push('/login')
this.loading = false
})
......
......@@ -240,31 +240,6 @@ services:
logging:
driver: json-file
dbrepo-search-sync-agent:
restart: "no"
container_name: dbrepo-search-sync-agent
hostname: search-startup-agent
build: ./dbrepo-search-sync-agent
image: dbrepo-search-sync-agent
networks:
core:
env_file:
- .env
healthcheck:
test: wget -qO- localhost:9050/actuator/health/readiness | grep -q "UP" || exit 1
interval: 10s
timeout: 5s
retries: 12
depends_on:
dbrepo-metadata-db:
condition: service_healthy
dbrepo-search-db:
condition: service_started
dbrepo-authentication-service:
condition: service_healthy
logging:
driver: json-file
dbrepo-ui:
restart: "no"
container_name: dbrepo-ui
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment