2016-07-25 4 views
0

現在、ログインページなしでWebを作成しています。春のセキュリティでヘッダーの情報を使ってユーザーを検証する方法

私は情報とヘッダを送信する別のウェブサイトを持っている:

user:John 
userCode:1234567 

だから私の現在のウェブサイトは、ヘッダの内容をチェックして、このような認証マネージャでユーザーを検証します:

まずI AuthenticationEntryPointを作成します。AuthenticationEntryPoint私はトークンを作成してメインページにリダイレクトするので、メインページに行く前に、springはユーザーを認証し、有効なユーザーのトークンを与えますページ。

@Component 
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint { 
     if(authException.getClass().getSimpleName().equals("InsufficientAuthenticationException")) { 
      if (request.getHeader("user") != null) { 
       UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(request.getHeader("user"), request.getHeader("userCode")); 
       SecurityContextHolder.getContext().setAuthentication(auth); 
       response.sendRedirect(request.getContextPath()); 
      } 
     } 
} 

AuthenticationManagerでプロセスは通常通り行って、ユーザーが有効であればトークンを与えます:コードは次のようです。私が変える必要があるものか、春に使用できる別のアプローチがありますか?

ありがとうございます!

+0

私はカスタムAuthenticationEntryPointを意味し、事前認証をこのように扱うべきか分かりません。 ref doc:[Http403ForbiddenEntryPoint](http://docs.spring.io/spring-security/site/docs/4.0.x/reference/html/preauth.html#http403forbiddenentrypoint) –

答えて

1

私の場合は、Siteminder implementation exampleの参考資料を参考にしてください。 Siteminderでは、HTTPリクエストと共にヘッダ(SM_USER)が渡されます。

これは、Spring Securityの事前認証の例です。

この設定を試しましたか? まず、「カスタムフィルタ」を定義して、RequestHeaderAuthenticationFilterのインスタンスを定義します。ドキュメントの

エキス:

<security:http> 
<!-- Additional http configuration omitted --> 
<security:custom-filter position="PRE_AUTH_FILTER" ref="siteminderFilter" /> 
</security:http> 

<bean id="siteminderFilter" class="org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter"> 
<property name="principalRequestHeader" value="SM_USER"/> 
<property name="authenticationManager" ref="authenticationManager" /> 
</bean> 

<bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider"> 
<property name="preAuthenticatedUserDetailsService"> 
    <bean id="userDetailsServiceWrapper" 
     class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper"> 
    <property name="userDetailsService" ref="userDetailsService"/> 
    </bean> 
</property> 
</bean> 

<security:authentication-manager alias="authenticationManager"> 
<security:authentication-provider ref="preauthAuthProvider" /> 
</security:authentication-manager> 
+0

ありがとうございます、私はすでにあなたの答えを操作します私の状況で – FreezY

関連する問題