Spring Security Core を使用して、事前認証済みのシナリオで Grails アプリを構成しようとしています。
そこで、カスタム認証フィルターを作成しました。
class MyAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter {
protected getPreAuthenticatedPrincipal(request) { "my_username" }
protected getPreAuthenticatedCredentials(request) { "N/A" }
}
それを春に追加しました:
beans = {
myAuthenticationFilter(MyAuthenticationFilter) {
authenticationManager = ref('authenticationManager')
checkForPrincipalChanges = true
}
}
位置 PRE_AUTH_FILTER で BootStrap に登録しました。
class BootStrap {
def init = { servletContext ->
SpringSecurityUtils.clientRegisterFilter('myAuthenticationFilter',
SecurityFilterPosition.PRE_AUTH_FILTER.order)
}
}
Config.groovy には、標準の User、Role、および UserRole クラス名といくつかの staticRules しかありません。
フィルター内で、そのgetPreAuthenticatedPrincipal()
メソッドからあらゆる種類のものを返そうとしました: ユーザー ID、文字列としてのユーザー ID、そのユーザー名、ユーザー オブジェクト自体… リクエストごとにフィルターが呼び出されていることがわかります (これは私は、checkForPrincipalChanges = true
) を設定した後、何を返しても、現在のユーザーは匿名のままですspringSecurityService.principal
。__grails.anonymous.user__
ユーザーを既存のグループとロールで認証できるようにするには、セットアップで何を変更する必要がありますか? 追加の認証プロバイダーを書きたくありません。Grails の標準で問題ありませんdaoAuthenticationProvider
。フィルターから特定のものを返す必要がありますか? 他のSpringクラスをセットアップする必要がありますか?