説明:セキュリティに基づいてビルドにグループチャット、ポイントに基づいて改善されました
<依存性> <依存性> <のgroupId> org.springframework.boot </のgroupId> <たartifactId>ばねブートスタータウェブ</たartifactId> </依存> <依存性> <のgroupId> org.springframework.boot </のgroupId > <たartifactId>ばねブートスタータのWebSocket </たartifactId> </依存> <依存性> <のgroupId> org.springframework.boot </のgroupId> <たartifactId>ばねブートスタータセキュリティ</たartifactId> <バージョン> RELEASE </バージョン> </依存関係> <依存関係> <たartifactId>春・ブート・スターターテスト</たartifactId> 依存関係> <groupIdを> org.springframework.boot </ groupIdを> <スコープ>テスト</スコープ> <除外> <除外> <のgroupId> org.junit.vintage </のgroupId> <たartifactId> JUnitのヴィンテージエンジン</たartifactId> </除外> </除外> </依存> </依存関係>
WebSocketのプロフィール
セキュリティの設定ファイル
@Configuration パブリック クラス WebSecurity社は延びWebSecurityConfigurerAdapter { @Bean PasswordEncoder passwordEncoder(){ リターンNoOpPasswordEncoder.getInstanceを(); } @Overrideは、 保護された 空隙(AuthenticationManagerBuilder AUTH)設定をスロー例外{ auth.inMemoryAuthentication() .withUser( "duanbochao" ) みましょう。パスワード( "123" ) .roles( "管理" ) .AND() .withUser( "lizi"を) みましょう。パスワード( "123" ) .roles( "ドゥアン" )。 } @Override 公共 ボイド設定(org.springframework.security.config.annotation.web.builders.WebSecurityウェブ)がスロー例外{ スーパー.configure(ウェブ)。 } @Overrideは、 保護された ボイドを構成する(HttpSecurity HTTP)スロー{例外 http.authorizeRequests() )(.anyRequest(認証)。 .AND() .formLogin()permitAll()。 } }
Beanを作成します。
コントローラで
index.htmlをファイル
テストをログインした後、現在のユーザーlizi
その他は通常の状態に取り替えを送信することはできません!
これまでのところ、[OK]をクリックします。
ソースアドレスします。https://github.com/duanbochao/websocket.git