Shibboleth 4 IDP:使用密码流查询两个不同的登录源
Shibboleth 4 IDP: Query two different login sources with the Password flow
我有两个登录源(一个 Active Directory 和一个本地 MySQL 数据库),每个都包含不同的用户。我想以这种方式配置密码流程:
- 先查询AD
- 如果成功,用户将登录
- 如果失败,查询本地数据库,如果成功则用户登录
- 否则,身份验证失败
我怎样才能做到这一点?
这是我找到的解决方案:
在文件 conf/authn/password-authn-config.xml
中放入以下行或替换它们(如果它们已经存在):
<import resource="jaas-authn-config.xml"/>
<!-- Ordered list of CredentialValidators to apply to a request. -->
<util:list id="shibboleth.authn.Password.Validators">
<ref bean="shibboleth.JAASValidator"/>
</util:list>
注释掉您不需要的任何其他资源,例如 ldap-authn-config.xml
或 krb5-authn-config.xml
。
在我的例子中,如果我的任一登录源 return 'okay',我希望登录成功。因此你需要这一行:
<!-- Controls whether all validators in the above bean have to succeed, or just one. -->
<util:constant id="shibboleth.authn.Password.RequireAll" static-field="java.lang.Boolean.FALSE"/>
如果您希望所有登录源都成功,只需将 'FALSE' 替换为 'TRUE'。
接下来,将以下内容放入conf/authn/jaas-authn-config.xml
:
<!-- Specify your JAAS config. -->
<bean id="JAASConfig" class="org.springframework.core.io.FileSystemResource" c:path="%{idp.home}/conf/authn/jaas.config" />
<util:property-path id="shibboleth.authn.JAAS.JAASConfigURI" path="JAASConfig.URI" />
<!-- Specify the application name(s) in the JAAS config. -->
<util:list id="shibboleth.authn.JAAS.LoginConfigNames">
<value>ShibUserPassAuthLDAP</value>
<value>ShibUserPassAuthJAAS</value>
</util:list>
现在打开conf/authn/jaas.config
并写下:
ShibUserPassAuthJAAS {
relationalLogin.DBLogin required debug=true
dbDriver="com.mysql.jdbc.Driver"
userTable="login"
userColumn="email"
passColumn="password"
dbURL="jdbc:mysql://localhost:3306/login"
dbUser="your_db_user"
dbPassword="your_db_password"
hashAlgorithm="SHA2" // or what u need
saltColumn="salt" // leave empty if you don't need this
errorMessage="Invalid password"
where="status < 9999"; // remove if you don't need this
};
ShibUserPassAuthLDAP {
org.ldaptive.jaas.LdapLoginModule required
ldapUrl="ldap://localhost:10389" // your active directory url
useStartTLS="true"
baseDn="OU=example,OU=example,DC=example,DC=org" // change this to whatever you need
bindDn="CN=shibboleth,OU=example,DC=example,DC=local" // change this to whatever you need
bindCredential="your_ad_password"
userFilter="(sAMAccountName={user})"
credentialConfig="{trustCertificates=file:/opt/shibboleth-idp/credentials/ldap.pem}";
};
relationalLogin.DBLogin
是 java class 我用来实际检查凭据的。您可以从这里下载:download the jar
只需将它放在您的 idp 上的这个目录中即可:{shibboleth_root}/edit-webapp/WEB-INF/lib/
现在请确保您在 conf/authn/general_authn.xml
中正确配置了密码流程:
<bean id="authn/Password" parent="shibboleth.AuthenticationFlow"
p:passiveAuthenticationSupported="true"
p:forcedAuthenticationSupported="true"/>
要启用密码流程,请更改 idp.properties
中的这一行:
idp.authn.flows=
对此:
idp.authn.flows=Password
完成这些步骤后,不要忘记重启码头以使更改生效。
说明
ShibUserPassAuthLDAP
和 ShibUserPassAuthJAAS
中的两个条目 jaas-authn-config.xml
是魔法发生的地方:密码流将尝试使用您提供的这两个配置来验证凭据。如果成功,它将尝试第一个并完成身份验证,或者如果第一个失败,则尝试第二个配置。
我有两个登录源(一个 Active Directory 和一个本地 MySQL 数据库),每个都包含不同的用户。我想以这种方式配置密码流程:
- 先查询AD
- 如果成功,用户将登录
- 如果失败,查询本地数据库,如果成功则用户登录
- 否则,身份验证失败
我怎样才能做到这一点?
这是我找到的解决方案:
在文件 conf/authn/password-authn-config.xml
中放入以下行或替换它们(如果它们已经存在):
<import resource="jaas-authn-config.xml"/>
<!-- Ordered list of CredentialValidators to apply to a request. -->
<util:list id="shibboleth.authn.Password.Validators">
<ref bean="shibboleth.JAASValidator"/>
</util:list>
注释掉您不需要的任何其他资源,例如 ldap-authn-config.xml
或 krb5-authn-config.xml
。
在我的例子中,如果我的任一登录源 return 'okay',我希望登录成功。因此你需要这一行:
<!-- Controls whether all validators in the above bean have to succeed, or just one. -->
<util:constant id="shibboleth.authn.Password.RequireAll" static-field="java.lang.Boolean.FALSE"/>
如果您希望所有登录源都成功,只需将 'FALSE' 替换为 'TRUE'。
接下来,将以下内容放入conf/authn/jaas-authn-config.xml
:
<!-- Specify your JAAS config. -->
<bean id="JAASConfig" class="org.springframework.core.io.FileSystemResource" c:path="%{idp.home}/conf/authn/jaas.config" />
<util:property-path id="shibboleth.authn.JAAS.JAASConfigURI" path="JAASConfig.URI" />
<!-- Specify the application name(s) in the JAAS config. -->
<util:list id="shibboleth.authn.JAAS.LoginConfigNames">
<value>ShibUserPassAuthLDAP</value>
<value>ShibUserPassAuthJAAS</value>
</util:list>
现在打开conf/authn/jaas.config
并写下:
ShibUserPassAuthJAAS {
relationalLogin.DBLogin required debug=true
dbDriver="com.mysql.jdbc.Driver"
userTable="login"
userColumn="email"
passColumn="password"
dbURL="jdbc:mysql://localhost:3306/login"
dbUser="your_db_user"
dbPassword="your_db_password"
hashAlgorithm="SHA2" // or what u need
saltColumn="salt" // leave empty if you don't need this
errorMessage="Invalid password"
where="status < 9999"; // remove if you don't need this
};
ShibUserPassAuthLDAP {
org.ldaptive.jaas.LdapLoginModule required
ldapUrl="ldap://localhost:10389" // your active directory url
useStartTLS="true"
baseDn="OU=example,OU=example,DC=example,DC=org" // change this to whatever you need
bindDn="CN=shibboleth,OU=example,DC=example,DC=local" // change this to whatever you need
bindCredential="your_ad_password"
userFilter="(sAMAccountName={user})"
credentialConfig="{trustCertificates=file:/opt/shibboleth-idp/credentials/ldap.pem}";
};
relationalLogin.DBLogin
是 java class 我用来实际检查凭据的。您可以从这里下载:download the jar
只需将它放在您的 idp 上的这个目录中即可:{shibboleth_root}/edit-webapp/WEB-INF/lib/
现在请确保您在 conf/authn/general_authn.xml
中正确配置了密码流程:
<bean id="authn/Password" parent="shibboleth.AuthenticationFlow"
p:passiveAuthenticationSupported="true"
p:forcedAuthenticationSupported="true"/>
要启用密码流程,请更改 idp.properties
中的这一行:
idp.authn.flows=
对此:
idp.authn.flows=Password
完成这些步骤后,不要忘记重启码头以使更改生效。
说明
ShibUserPassAuthLDAP
和 ShibUserPassAuthJAAS
中的两个条目 jaas-authn-config.xml
是魔法发生的地方:密码流将尝试使用您提供的这两个配置来验证凭据。如果成功,它将尝试第一个并完成身份验证,或者如果第一个失败,则尝试第二个配置。