2017-03-14 26 views
1

私はEntryPointクラスを以下のように持っていますが、どのような正確な値をrelaystateに設定するかは任意です。認証前に要求されたURLパラメータ値を取得したい。SAMLEntryPointにRelayStateを設定する方法

import org.opensaml.saml2.metadata.provider.MetadataProviderException; 
import org.springframework.security.core.AuthenticationException; 
import org.springframework.security.saml.SAMLEntryPoint; 
import org.springframework.security.saml.context.SAMLMessageContext; 
import org.springframework.security.saml.websso.WebSSOProfileOptions; 

public class SamlLoginEntryPoint extends SAMLEntryPoint{ 

    protected WebSSOProfileOptions getProfileOptions(SAMLMessageContext context, AuthenticationException exception) throws MetadataProviderException { 

     System.out.println("inside entrypoint"); 
     WebSSOProfileOptions ssoProfileOptions; 
     if (defaultOptions != null) { 
      System.out.println("in if"); 
      ssoProfileOptions = defaultOptions.clone(); 
      ssoProfileOptions.setRelayState(""); 
      System.out.println("relaystate:"+ssoProfileOptions.getRelayState()); 
     } else { 
      System.out.println("in else"); 
      ssoProfileOptions = new WebSSOProfileOptions(); 
      ssoProfileOptions.setRelayState(""); 
     } 

     return ssoProfileOptions; 

    } 

答えて

0

SAMLEntryPointクラスのcommence()メソッドをオーバーライドし、要求オブジェクトから要求パラメータを取得します。

だから私の実装は次のようになります。

public class CustomMFASamlEntryPoint extends SAMLEntryPoint { 
    private String relayState; 

    @Override 
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authenticationException) throws IOException, ServletException { 
     //read your request parameter 
     setRelayState(request.getParameter("request-param-for-relaystate")); 
     super.commence(request, response, authenticationException); 
    } 

    @Override 
    protected WebSSOProfileOptions getProfileOptions(SAMLMessageContext samlMessageContext, AuthenticationException authenticationException) throws MetadataProviderException { 
     //set the relayState to your SAML message context 
     samlMessageContext.setRelayState(getRelayState()); 
     return super.getProfileOptions(samlMessageContext, authenticationException); 
    } 

    private void setRelayState(String relayState) { 
     this.relayState = relayState; 
    } 

    private String getRelayState() { 
     return relayState; 
    } 
} 
関連する問題