Spring Cloud 云身份識別代理(IAP)身份驗(yàn)證

2024-01-11 16:17 更新

Cloud Identity-Aware Proxy(IAP)為部署到Google Cloud的應(yīng)用程序提供了安全層。

IAP入門人員使用Spring Security OAuth 2.0資源服務(wù)器功能從注入代理的x-goog-iap-jwt-assertion HTTP標(biāo)頭中自動(dòng)提取用戶身份。

以下聲明將自動(dòng)驗(yàn)證:

  • 發(fā)行時(shí)間
  • 到期時(shí)間
  • 發(fā)行人
  • 聽眾

當(dāng)應(yīng)用程序在App Engine Standard或App Engine Flexible上運(yùn)行時(shí),將自動(dòng)配置受眾群體("aud")驗(yàn)證。對于其他運(yùn)行時(shí)環(huán)境,必須通過spring.cloud.gcp.security.iap.audience屬性提供自定義受眾。 自定義屬性(如果已指定)將覆蓋自動(dòng)的App Engine受眾群體檢測。

Compute Engine或Kubernetes Engine沒有自動(dòng)的受眾字符串配置。要在GCE / GKE上使用IAP啟動(dòng)器, 在“驗(yàn)證JWT有效負(fù)載”指南中按照說明查找受眾字符串,并在spring.cloud.gcp.security.iap.audience屬性中進(jìn)行指定。 否則,應(yīng)用程序?qū)o法以No qualifying bean of type 'org.springframework.cloud.gcp.security.iap.AudienceProvider' available消息啟動(dòng)。

如果創(chuàng)建自定義WebSecurityConfigurerAdapter ,請通過向HttpSecurity對象 添加.oauth2ResourceServer().jwt()配置來提取用戶身份。如果沒有自定義項(xiàng),WebSecurityConfigurerAdapter則無需執(zhí)行任何操作,因?yàn)镾pring Boot將默認(rèn)添加此自定義項(xiàng)。

起始Maven坐標(biāo),使用Spring Cloud GCP BOM

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-gcp-starter-security-iap</artifactId>
</dependency>

入門級Gradle坐標(biāo):

dependencies {
    compile group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-security-iap'
}
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號