出于遗留原因,我必须使用Vaadin 8.6.3
。
我有一个简单的索引页,它的菜单栏包含三个项目(home
,user
,admin
)和欢迎消息。
我将该索引页映射到/
,并希望未经身份验证的用户可以访问它。 home
菜单选项链接到此页面。
user
和admin
链接到尚不存在但应由Spring boot保护的页面。
这是我(仅目前)的WebSecurity配置:
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.builders.WebSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
@Configuration
@EnableWebSecurity
class AnyRequestConfiguration : WebSecurityConfigurerAdapter(){
override fun configure(http: HttpSecurity) {
http
.csrf().disable() //vaadin has its own csrf protection, therefore this must be disabled
.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
}
override fun configure(web: WebSecurity){
web
.ignoring().antMatchers(
"/VAADIN/**",
"/frontend/**",
"/webjars/**",
"/images/**",
"/frontend-es5/**", "/frontend-es6/**"
)
}
}
页面被渲染,显示菜单和欢迎消息,但连接立即丢失,我得到一个
服务器连接丢失,尝试重新连接
页面右上角的消息,带有一个旋转的加载圆圈。
为什么?如何使它工作?
索引页:
import com.vaadin.annotations.Theme
import com.vaadin.server.VaadinRequest
import com.vaadin.spring.annotation.SpringUI
import com.vaadin.ui.Label
import com.vaadin.ui.MenuBar
import com.vaadin.ui.UI
import com.vaadin.ui.VerticalLayout
@SpringUI(path = "/")
@Theme("mytheme")
class Index : UI() {
companion object {
const val HOME_MENU = "Home"
const val USER_MENU = "User"
const val ADMIN_MENU = "Admin"
lateinit var navigation: MenuBar
private set
}
private lateinit var layout: VerticalLayout
override fun init(request: VaadinRequest?) {
layout = VerticalLayout()
//navigation bar
navigation = MenuBar()
navigation.id = "menubar"
navigation.addItem(HOME_MENU)
navigation.addItem(USER_MENU)
navigation.addItem(ADMIN_MENU)
//TODO: add onClick-listeners
//welcome message
val welcomeMessage = Label()
welcomeMessage.id = "label.welcome"
welcomeMessage.value = "Welcome to Spring Security Demo with Vaadin"
layout.addComponents(
navigation,
welcomeMessage
)
this.content = layout
}
}
更新
Devconsole显示错误
com.vaadin.DefaultWidgetSet-0.js:6129 POST http://localhost:8080/vaadinServlet/UIDL/?v-uiId=0 403
之后是警告
com.vaadin.DefaultWidgetSet-0.js:6421 5月08日星期三12:19:17 GMT + 200 2019 com.vaadin.client.communication.DefaultConnectionStateHandler 警告:服务器为xhr返回403
然后再次尝试
2019年5月8日星期三12:20:33 GMT + 200 com.vaadin.client.communication.DefaultConnectionStateHandler
INFO:为XHR重新尝试尝试49
com.vaadin.DefaultWidgetSet-0.js:6421 5月08日星期三12:20:38 GMT + 200 2019 com.vaadin.client.communication.DefaultConnectionStateHandler
信息:将最后一条消息重新发送到服务器...
com.vaadin.DefaultWidgetSet-0.js:6421 5月08日星期三12:20:38 GMT + 200 2019 com.vaadin.client.communication.XhrConnection
INFO:向服务器发送xhr消息:{“ csrfToken”:“ 24cb59a1-cd65-4774-b208-c7272314e8a7”,“ rpc”:[[“ 0”,“ com.vaadin.shared.ui.ui.UIServerRpc “,” resize“,[1478,698,1478,698]]]],” syncId“:0,” clientId“:0,” wsver“:” 8.6.3“}
哪个也会失败,所以圆圈会重复。