クラス SecurityEvaluationContextExtension

java.lang.ObjectSE
org.springframework.security.data.repository.query.SecurityEvaluationContextExtension
実装済みのインターフェース一覧:
org.springframework.data.spel.spi.EvaluationContextExtension, org.springframework.data.spel.spi.ExtensionIdAware

public class SecurityEvaluationContextExtension extends ObjectSE implements org.springframework.data.spel.spi.EvaluationContextExtension

このオブジェクトを Bean として定義することにより、Spring SecuritySpring Data クエリを作成するための SpEL 式として公開されます。

Java ベースの構成では、以下を使用して Bean を定義できます。

例: 次の User オブジェクトを継承する UserDetails を返す場合:

@Entity
public class User {
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Id
    private Long id;

    ...
}

そして、次のようなメッセージオブジェクトがあります。

@Entity
public class Message {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToOne
    private User to;

    ...
}
次の Query アノテーションを使用して、現在のユーザー宛てのメッセージのみを検索できます。
@Repository
public interface SecurityMessageRepository extends MessageRepository {

        @Query("select m from Message m where m.to.id = ?#{ principal?.id }")
        List<Message> findAll();
}
これは、このインスタンスのプリンシパルが id フィールドを持つユーザーであるために機能します。
導入:
4.0