Interface TenantAwareUserDetails


public interface TenantAwareUserDetails

具備租戶感知能力的 UserDetails 介面

當使用非 JWT 認證方式(如 Basic Auth、Form Login)時, 應用程式的 UserDetails 實作可實作此介面,讓 UserDetailsTenantIdResolver 能夠從中取得租戶 ID。

使用範例:

public class AccountUserDetails extends User implements TenantAwareUserDetails {
    private final String tenantId;

    public AccountUserDetails(String username, String password,
                              Collection<? extends GrantedAuthority> authorities,
                              String tenantId) {
        super(username, password, authorities);
        this.tenantId = tenantId;
    }

    @Override
    public String getTenantId() {
        return tenantId;
    }
}
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    取得此使用者所屬的租戶 ID
  • Method Details

    • getTenantId

      String getTenantId()
      取得此使用者所屬的租戶 ID
      Returns:
      租戶 ID,若使用者不屬於任何租戶則可返回 null