Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ protected void configure(HttpSecurity http) throws Exception {
.csrf().disable(); // disable cross site request forgery, as we don't use cookies - otherwise ALL PUT, POST, DELETE will get HTTP 403!
}

//@Override
//protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// auth.inMemoryAuthentication()
// .withUser("foo").password("{noop}bar").roles("USER");
//}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin").password("{noop}admin").roles("USER");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void secured_api_should_react_with_unauthorized_per_default() {
public void secured_api_should_give_http_200_when_authorized() {

given()
.auth().basic("sina", "miller")
.auth().basic("admin", "admin")
.when()
.get("/api/secured")
.then()
Expand All @@ -104,4 +104,26 @@ public void secured_api_should_give_http_200_when_authorized() {
.body(is(equalTo(BackendController.SECURED_TEXT)));
}

@Test
public void secured_api_should_react_with_unauthorized_when_using_wrong_password() {

given()
.auth().basic("admin", "wrongpassword")
.when()
.get("/api/secured")
.then()
.statusCode(HttpStatus.SC_UNAUTHORIZED);
}

@Test
public void secured_api_should_react_with_unauthorized_when_using_non_existing_user() {

given()
.auth().basic("nonuser", "anypassword")
.when()
.get("/api/secured")
.then()
.statusCode(HttpStatus.SC_UNAUTHORIZED);
}

}
55 changes: 49 additions & 6 deletions frontend/src/components/HelloSpringWorld.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<template>
<div class="hello">
<h1>{{ hellomsg }}</h1>
<h1>{{ internalMsg }}</h1>
<div class="refresh-section">
<button class="btn btn-primary" @click="refreshData" :disabled="loading">
{{ loading ? '加载中...' : '刷新数据' }}
</button>
</div>
<h2>See the sources here: </h2>
<ul>
<li><a href="https://github.com/jonashackt/spring-boot-vuejs" target="_blank">github.com/jonashackt/spring-boot-vuejs</a></li>
Expand All @@ -21,15 +26,49 @@
</div>
</template>

<script>
export default {
<script lang="ts">
import { defineComponent } from 'vue';
import api from '@/api/backend-api';

export default defineComponent({
name: 'HelloSpringWorld',
props: {
hellomsg: {
type: String,
required: true }
default: 'Welcome to your Vue.js (+ TypeScript) powered Spring Boot App'
}
},
data() {
return {
internalMsg: this.hellomsg,
loading: false
};
},
watch: {
hellomsg(newVal) {
this.internalMsg = newVal;
}
},
mounted() {
this.refreshData();
},
methods: {
async refreshData() {
if (this.loading) return;

this.loading = true;
try {
const response = await api.hello();
this.internalMsg = response.data;
} catch (error) {
console.error('Failed to refresh data:', error);
this.internalMsg = '获取数据失败,请稍后重试';
} finally {
this.loading = false;
}
}
}
}
});
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
Expand All @@ -51,4 +90,8 @@ li {
a {
color: #42b983;
}
</style>

.refresh-section {
margin-bottom: 20px;
}
</style>
4 changes: 2 additions & 2 deletions frontend/src/views/Home.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<div class="home">
<img alt="Vue with Spring logo" src="../assets/spring-boot-vuejs-logo.png">
<HelloSpringWorld hellomsg="Welcome to your Vue.js (+ TypeScript) powered Spring Boot App"/>
<HelloSpringWorld/>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import HelloSpringWorld from '@/components/HelloSpringWorld.vue'; // @ is an alias to /src
import HelloSpringWorld from '@/components/HelloSpringWorld.vue';

export default defineComponent({
name: 'Home',
Expand Down