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

Do not display

parent 296373f2
No related branches found
No related tags found
2 merge requests!379Fixed the sync,!377Fixed the sync
No preview for this file type
......@@ -2,6 +2,7 @@ package at.tuwien.handlers;
import at.tuwien.api.error.ApiErrorDto;
import at.tuwien.exception.*;
import com.auth0.jwt.exceptions.TokenExpiredException;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.HttpHeaders;
......@@ -16,6 +17,13 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep
@ControllerAdvice
public class ApiExceptionHandler extends ResponseEntityExceptionHandler {
@Hidden
@ResponseStatus(code = HttpStatus.UNAUTHORIZED)
@ExceptionHandler(TokenExpiredException.class)
public ResponseEntity<ApiErrorDto> handle(TokenExpiredException e) {
return generic_handle(e.getClass(), e.getLocalizedMessage(), "error.token.expired");
}
@Hidden
@ResponseStatus(code = HttpStatus.NOT_FOUND)
@ExceptionHandler(AccessNotFoundException.class)
......@@ -465,13 +473,17 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler {
}
private ResponseEntity<ApiErrorDto> generic_handle(Class<?> exceptionClass, String message) {
return generic_handle(exceptionClass, message, exceptionClass.getAnnotation(ResponseStatus.class).reason());
}
private ResponseEntity<ApiErrorDto> generic_handle(Class<?> exceptionClass, String message, String code) {
final HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/problem+json");
final ResponseStatus annotation = exceptionClass.getAnnotation(ResponseStatus.class);
final ApiErrorDto response = ApiErrorDto.builder()
.status(annotation.code())
.message(message)
.code(annotation.reason())
.code(code)
.build();
return new ResponseEntity<>(response, headers, response.getStatus());
}
......
......@@ -3,6 +3,7 @@ package at.tuwien.handlers;
import at.tuwien.api.error.ApiErrorDto;
import at.tuwien.exception.*;
import at.tuwien.test.AbstractUnitTest;
import com.auth0.jwt.exceptions.TokenExpiredException;
import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
......@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import java.io.IOException;
import java.lang.reflect.Method;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
......@@ -55,6 +57,19 @@ public class ApiExceptionHandlerTest extends AbstractUnitTest {
}
}
@Test
public void handle_tokenExpiredException_succeeds() {
/* test */
final ResponseEntity<ApiErrorDto> response = apiExceptionHandler.handle(new TokenExpiredException("msg", Instant.now()));
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
final ApiErrorDto body = response.getBody();
assertNotNull(body);
assertNotNull(body.getMessage());
assertEquals(HttpStatus.UNAUTHORIZED, body.getStatus());
assertEquals("error.token.expired", body.getCode());
}
@Test
public void handle_accessNotFoundException_succeeds() {
......@@ -68,7 +83,6 @@ public class ApiExceptionHandlerTest extends AbstractUnitTest {
assertEquals("error.access.missing", body.getCode());
}
@Test
public void handle_accountNotSetupException_succeeds() {
......@@ -82,7 +96,6 @@ public class ApiExceptionHandlerTest extends AbstractUnitTest {
assertEquals("error.user.setup", body.getCode());
}
@Test
public void handle_analyseServiceException_succeeds() {
......@@ -96,7 +109,6 @@ public class ApiExceptionHandlerTest extends AbstractUnitTest {
assertEquals("error.analyse.invalid", body.getCode());
}
@Test
public void handle_authServiceConnectionException_succeeds() {
......@@ -110,7 +122,6 @@ public class ApiExceptionHandlerTest extends AbstractUnitTest {
assertEquals("error.auth.connection", body.getCode());
}
@Test
public void handle_authServiceException_succeeds() {
......
......@@ -141,23 +141,6 @@
</v-form>
<v-main>
<v-container>
<div
v-cloak>
<v-alert
v-if="isNotFinishedAccountSetup"
border="start"
color="info"
class="mb-4">
{{ $t('pages.settings.subpages.authentication.setup.text') }}
<v-btn
variant="flat"
size="small"
to="/user/authentication">
{{ $t('pages.settings.subpages.authentication.setup.action') }}
</v-btn>
.
</v-alert>
</div>
<JumboBox
v-if="error"
:title="$t(errorCodeKey(error).title, { resource })"
......@@ -269,15 +252,6 @@ export default {
commitShort () {
return this.$config.public.commit.substr(0, 8)
},
isNotFinishedAccountSetup () {
if (!this.cacheUser) {
return false
}
if (!('setup_finished' in this.cacheUser)) {
return true
}
return this.cacheUser.setup_finished === false
},
error () {
if (this.identifier) {
return null
......
......@@ -61,7 +61,7 @@
</template>
<script setup>
const { loggedIn, user } = useOidcAuth()
const { loggedIn } = useOidcAuth()
</script>
<script>
import UserToolbar from '@/components/user/UserToolbar.vue'
......@@ -113,10 +113,6 @@ export default {
const userService = useUserService()
userService.updatePassword(this.cacheUser.uid, {'password': this.password})
.then(() => {
const user = Object.assign({}, this.cacheUser)
user.setup_finished = true
this.cacheStore.setUser(user)
// fixme [mweise]: currently nuxt-oidc-auth cannot refresh the session correctly
const toast = useToastInstance()
toast.success(this.$t('success.user.password'))
this.loadingUpdate = false
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment