第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

由于授權(quán)而無法訪問API

由于授權(quán)而無法訪問API

繁星點點滴滴 2021-03-30 16:13:23
我創(chuàng)建了自己的api,以便在請求時向UI提供數(shù)據(jù)。但是我正在使用JHipster,它實現(xiàn)了Spring Security來驗證api請求。當(dāng)我登錄到應(yīng)用程序并使用url(localhost:9090 / api / lesson)直接訪問api時,它為我的用戶角色和管理員角色提供了401。{  "type" : "https://www.jhipster.tech/problem/problem-with-message",  "title" : "Unauthorized",  "status" : 401,  "detail" : "Full authentication is required to access this resource",  "path" : "/api/lesson",  "message" : "error.http.401"}我檢查了安全性配置,并且/ api / **路徑已設(shè)置為Authenticated,這使我感到困惑,為什么登錄后無法訪問該資源。protected void configure(HttpSecurity http) throws Exception {    http        .addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class)        .exceptionHandling()        .authenticationEntryPoint(problemSupport)        .accessDeniedHandler(problemSupport)    .and()        .csrf()        .disable()        .headers()        .frameOptions()        .disable()    .and()        .sessionManagement()        .sessionCreationPolicy(SessionCreationPolicy.STATELESS)    .and()        .authorizeRequests()        .antMatchers("api/lesson").permitAll()        .antMatchers("/api/register").permitAll()        .antMatchers("/api/activate").permitAll()        .antMatchers("/api/authenticate").permitAll()        .antMatchers("/api/account/reset-password/init").permitAll()        .antMatchers("/api/account/reset-password/finish").permitAll()        .antMatchers("/api/profile-info").permitAll()        .antMatchers("/api/**").authenticated()        .antMatchers("/management/health").permitAll()        .antMatchers("/management/**").hasAuthority(AuthoritiesConstants.ADMIN)        .antMatchers("/v2/api-docs/**").permitAll()        .antMatchers("/swagger-resources/configuration/ui").permitAll()        .antMatchers("/swagger-ui/index.html").hasAuthority(AuthoritiesConstants.ADMIN)    .and()        .apply(securityConfigurerAdapter());}盡管我的API并非像JHipsters那樣創(chuàng)建,就像使用CrudRepository代替JPA一樣,但我認(rèn)為這不會成為問題。但是,我可能是錯的。
查看完整描述

1 回答

?
阿波羅的戰(zhàn)車

TA貢獻(xiàn)1862條經(jīng)驗 獲得超6個贊

為什么不使用如下所示:


http

                .cors()

                .and()

                .csrf()

                .disable()

                .exceptionHandling()

                .authenticationEntryPoint(unauthorizedHandler)

                .and()

                .sessionManagement()

                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)

                .and()

                .authorizeRequests()

                .antMatchers("/")

                .permitAll()

                .antMatchers("/api/auth/**","/api/user/exist")

                .permitAll()

                .antMatchers("/api/user/checkUsernameAvailability", "/api/user/checkEmailAvailability")

                .permitAll()

                .antMatchers(HttpMethod.GET, "/api/polls/**", "/api/users/**", "/api/gift/**")

                .permitAll()

                .anyRequest()

                .authenticated();


查看完整回答
反對 回復(fù) 2021-04-14
  • 1 回答
  • 0 關(guān)注
  • 165 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號