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

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

主體為空:Spring

主體為空:Spring

UYOU 2021-12-01 14:33:16
我有以下@RestContoller登錄:  @RequestMapping("/account/login")@ResponseBody@CrossOrigin(origins = "*", maxAge = 3600)public Principal login(Principal principal) {    logger.info("user logged " + principal.getName());    return principal;}我有客戶端發(fā)出的以下請求,它是一個 Angularjs 應(yīng)用程序。Accept: application/jsonAccept-Encoding: gzip, deflate, brAccept-Language: en-US,en;q=0.9,fa;q=0.8,it;q=0.7Authorization: Basic bWVocmRhZGFsbGFoa2FyYW1pQGdtYWlsLmNvbTptZWhyZGFkConnection: keep-aliveDNT: 1Host: localhost:8080Origin: http://localhost:4200Referer: http://localhost:4200/loginUser-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36但是我得到200了響應(yīng),服務(wù)器打印null并且客戶端收到錯誤響應(yīng):HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "OK", url: "http://localhost:8080/account/login", ok: false, …}error: {timestamp: 1540136257516, status: 400, error: "Bad Request", exception: "org.springframework.web.bind.ServletRequestBindingException", message: "Missing request header 'header' for method parameter of type Header", …}headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ?}message: "Http failure response for http://localhost:8080/account/login: 400 OK"name: "HttpErrorResponse"ok: falsestatus: 400statusText: "OK"url: "http://localhost:8080/account/login"__proto__: HttpResponseBase誰能幫我知道我哪里錯了?它以前工作過,但我在 Angular 中使用了攔截器,但它不再工作了。我的登錄控制器是這樣的:@Injectable()export class AuthService {  constructor(public http: HttpClient, public auth: InterceptorAuthService) {  }  public logIn(user: User) {    this.auth.setUser(user);    return this.http.get(AppComponent.API_URL + "/account/login")      .pipe(        map(response => {            // login successful if there's a jwt token in the response            let user = response;// the returned user object is a principal object          })        ));  }}
查看完整描述

2 回答

?
明月笑刀無情

TA貢獻1828條經(jīng)驗 獲得超4個贊

嘗試添加sec:authorize="isAuthenticated()到要顯示用戶名的“/account/login”模板

例如:

<h3 sec:authorize="isAuthenticated()" th:text="${user.username}"></h3>

如果它發(fā)生了,它將獲得身份驗證狀態(tài),否則,它不會顯示<h3>代碼塊。


查看完整回答
反對 回復(fù) 2021-12-01
?
臨摹微笑

TA貢獻1982條經(jīng)驗 獲得超2個贊

@Component

public class MyBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {

@Override

public void afterPropertiesSet() throws Exception {

    setRealmName("Baeldung");

    super.afterPropertiesSet();

}

@Override

public void commence(

  HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx) 

  throws IOException, ServletException {

    response.addHeader("WWW-Authenticate", "Basic realm="" + getRealmName() + """);

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

    PrintWriter writer = response.getWriter();

    writer.println("HTTP Status 401 - " + authEx.getMessage());

}

}


// inside filter we can get the 

SecurityContextHolder.getContext().getAuthentication().getPrincipal()


查看完整回答
反對 回復(fù) 2021-12-01
  • 2 回答
  • 0 關(guān)注
  • 161 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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