2015-10-21 35 views
0

我想編寫一個自定義聯合身份驗證器。原因是我想從多個數據源檢索聲明,並將它們作爲SAML響應中的屬性包含在我的應用程序中。 我看着一個自定義的要求處理:WSO2 Identity Server - 自定義SAMLSSOAuthenticator

http://pushpalankajaya.blogspot.ie/2014/07/adding-custom-claims-to-saml-response.html

遺憾的是,登錄直接到外部IDP時,定製的要求處理,不得被調用。

要創建自定義SAMLSSOAuthenticator,我創建了一個自定義類:

public class CustomSAMLSSOAuthenticator extends SAMLSSOAuthenticator implements FederatedApplicationAuthenticator { 
    @Override 
    protected void processAuthenticationResponse(final HttpServletRequest request, final HttpServletResponse response, 
               final AuthenticationContext context) throws AuthenticationFailedException { 
    } 

    @Override 
    public String getName() { 
     return "CustomSAMLSSOAuthenticator"; 
    } 

    @Override 
    public String getFriendlyName() { 
     return "custom-samlsso"; 
    }             
} 

然後我註冊的OSGi類作爲一個AbstractApplicationAuthenticator。我可以在工作日誌看到這個註冊:

DEBUG {org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceComponent} - Added application authenticator : CustomSAMLSSOAuthenticator 

然後我讓IS_HOME /庫/ conf目錄/安全/應用authentication.xml變爲$:

<AuthenticatorNameMapping name="CustomSAMLSSOAuthenticator" alias="firecrest-samlsso" /> 
... 
<AuthenticatorConfig name="CustomSAMLSSOAuthenticator" enabled="true"> 

和我刪除參考SAMLSSOAuthenticator從文件。

從Mgmt控制檯,當爲我的服務提供者添加高級認證配置並選擇聯合認證器時,我期待看到選項custom-samlsso,但我只獲得samlsso,並且在登錄到外部IDP時,使用SAMLSSOAuthenticator而不是CustomSAMLSSOAuthenticator處理。

我也注意到在IdPManagementUIUtil類,有SAMLSSOAuthenticator的一些硬編碼這可能表明什麼,我試圖做的是不支持的:

private static void buildSAMLAuthenticationConfiguration(IdentityProvider fedIdp, 
     Map<String, String> paramMap) throws IdentityApplicationManagementException { 

    FederatedAuthenticatorConfig saml2SSOAuthnConfig = new FederatedAuthenticatorConfig(); 
    saml2SSOAuthnConfig.setName("SAMLSSOAuthenticator"); 
    saml2SSOAuthnConfig.setDisplayName("samlsso"); 
    ... 
} 

任何想法我做錯了嗎?

回答

0

替換現有的SAMLSSOAuthenticator的方法存在問題,因爲如問題中所述,存在與其相關的某些硬編碼。

的解決方案只是增加一個新的自定義驗證器,使它看起來儘可能接近到SAMLSSOAuthenticator:

https://docs.wso2.com/display/IS500/Writing+a+Custom+Twitter+Authenticator

我唯一的問題越來越管理控制檯上的配置形式看相同:

@Override 
public List<Property> getConfigurationProperties() { 
    final List<Property> properties = Lists.newArrayList(); 
    properties.add(createProperty(IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID, null, 
     "Identity Provider Entity Id", "Enter identity provider's entity identifier value", true, null, null)); 

    ...  
    return properties; 
}  

private Property createProperty(final String name, final String value, final String label, 
           final String description, final boolean required, final String type, 
           final String defaultValue) { 
    final Property property = new Property(); 
    property.setName(name); 
    property.setValue(value); 
    property.setDisplayName(label); 
    property.setDescription(description); 
    property.setRequired(required); 
    if (type != null) { 
     property.setType(type); 
    } 
    property.setDefaultValue(defaultValue); 
    return property; 
} 

我不確定什麼是有效的值#屬性# 無法確定是否有方法使用屬性類型創建複選框和單選按鈕?

2

首先,它支持添加自定義驗證器作爲首選,硬編碼值僅適用於默認打包驗證器。即使配置不可見,它似乎是有效的,你可以通過嘗試通過驗證來驗證。只有在自定義實現中定義了配置屬性時,纔會顯示自定義身份驗證器的配置。所以請嘗試通過Abstract類中的方法添加一些屬性。

public List<Property> getConfigurationProperties() 

另一方面,您的第一種方法應該已經工作。如果你可以發送代碼將能夠檢查出了什麼問題。

相關問題