2011-11-08 6 views

答えて

6

現在ログインしているユーザーを取得するには、コントローラに依存関係注入を使用してspringSecurityServiceにアクセスし、そこから現在ログインしているユーザーのユーザー名にアクセスできます。

def springSecurityService // will be injected by DI 

... in controller method, 

    def currentUsername = new MyDomainClassWithUsername(springSecurityService.currentUser.username)   
    currentUsername.save() 
+0

これは私が取得エラーです:いいえ、そのようなプロパティ:クラスのユーザー名:org.springframework.security.authenticationエラー500:コントローラー[com.test.IncidentController]原因となった例外の実行アクションを[作成]。 RememberMeAuthenticationToken – drago

+0

私はSpring Security Userクラスのユーザー名を取得しようとしています。 – drago

+1

try:springSecurityService.getCurrentUser()。username – socha23