2015-10-21 61 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() 

另一方面,您的第一种方法应该已经工作。如果你可以发送代码将能够检查出了什么问题。

相关问题