我正在尝试使用Jetty嵌入式服务器来公开我的Rest API,现在我想实现Kerberos身份验证.这就是我创建SecurityHandler的方式
String domainRealm = "MY.COM";
Constraint constraint = new Constraint();
constraint.setName(Constraint.__SPNEGO_AUTH);
constraint.setRoles(new String[]{domainRealm});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
SpnegoLoginService loginService = new SpnegoLoginService();
loginService.setConfig("/path/to/spnego.properties");
loginService.setName(domainRealm);
ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
sh.setAuthenticator(new SpnegoAuthenticator());
sh.setLoginService(loginService);
sh.setConstraintMappings(new ConstraintMapping[]{cm});
sh.setRealmName(domainRealm);
Run Code Online (Sandbox Code Playgroud)
这是我的spnego.properties:
targetName = HTTP/target.name.com
Run Code Online (Sandbox Code Playgroud)
我的krb5.ini:
[libdefaults]
default_realm = HW.COM
default_keytab_name = FILE:/path/to/target.name.com.keytab
permitted_enctypes = aes128-cts aes256-cts arcfour-hmac-md5
default_tgs_enctypes = aes128-cts aes256-cts arcfour-hmac-md5
default_tkt_enctypes = aes128-cts aes256-cts arcfour-hmac-md5
[realms]
MY.COM= {
kdc = 12.13.14.222 #IP adress
admin_server = 12.13.14.222 # IP …Run Code Online (Sandbox Code Playgroud) 微软利用我目前所知的两个WWW-Authenticate新增功能
如果从服务器发送Negotiate,则基于一组条件将使用Kerberos
然后将在服务器和客户端之间尝试Kerberos,如果不满足上述条件,则将尝试NTLM.
我的问题是,是否有一些方法让服务器指示不应该发送NTLM?我目前通过跟踪会话中的请求来处理这个问题,如果收到NTLM消息,它会在其余的会话生命周期中禁用Kerberos和WWW-Authenticate.
有没有人知道在Windows上运行的Java 6客户端是否能够在访问实现SPNEGO身份验证协议的Microsoft服务器时通过NTLM进行身份验证?
我的理解是,在Windows上运行的Java 6内置了对SPNEGO的支持,但似乎Java实现不会在无法进行kerberos身份验证的情况下尝试NTLM身份验证.Sun文档中提供的Authenticator示例在响应服务器发送WWW-Authenticate:Negotiate时发生401 Unauthorized错误失败.
以下是测试环境的说明:
目标服务器:
客户端机器:
最终目标是使用Apache CXF 2.4.0在WCF服务器上调用SOAP服务.在添加CXF和SOAP的复杂性之前,我一直在尝试使用简单的Java测试应用程序从服务器检索WSDL来解决身份验证问题.
FWIW - 我可以使用Windows服务器的本地管理员登录从IE访问WCF服务器.我还能够创建一个没有任何特殊授权配置的Delphi XE SOAP客户端.Delphi SOAP客户端使用WinInet.
我知道这是一个很长的镜头但是,是否会碰巧有一个用于响应kerberos而不是http(又名spnego)请求的clojure库?
我目前正在考虑使用弹簧安全框架,但我想我会问一个更好的clojure友好的方法以防万一.
我最终将我的JBoss AS 7服务器配置为SPNEGO在针对Windows 2008 R2的AD域上使用.我正在使用Java 7.
当用户从域计算机以外的某个地方(例如,从移动电话或更广泛的Internet)访问服务器URL时,系统会提示他们输入用户名和密码,然后我收到错误消息:
Login failure: javax.security.auth.login.LoginException: Unsupported negotiation mechanism 'NTLM'
Run Code Online (Sandbox Code Playgroud)
当用户在登录域时访问URL时,一切正常.
在SPNEGOsecurity-domain(standalone.xml)上我配置了2个登录模块:
第一: org.jboss.security.negotiation.spnego.SPNEGOLoginModule
第二:
<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required">
<module-option name="password-stacking" value="useFirstPass"/>
<module-option name="usersProperties" value="file:${jboss.server.config.dir}/spnego-users.properties"/>
<module-option name="rolesProperties" value="file:${jboss.server.config.dir}/spnego-roles.properties"/>
<module-option name="defaultUsersProperties" value="file:${jboss.server.config.dir}/spnego-users.properties"/>
<module-option name="defaultRolesProperties" value="file:${jboss.server.config.dir}/spnego-roles.properties"/>
</login-module>
Run Code Online (Sandbox Code Playgroud)
问题是:我如何回退BASIC或FORM什么时候SPNEGO超出范围?
谢谢
完全例外如下:
00:40:23,751 ERROR [org.jboss.security.authentication.JBossCachedAuthenticationManager] (http--0.0.0.0-9090-8) Login failure: javax.security.auth.login.LoginException: Unsupported negotiation mechanism 'NTLM'.
at org.jboss.security.negotiation.spnego.SPNEGOLoginModule.spnegoLogin(SPNEGOLoginModule.java:230) [jboss-negotiation-spnego-2.2.0.SP1.jar:2.2.0.SP1]
at org.jboss.security.negotiation.spnego.SPNEGOLoginModule.innerLogin(SPNEGOLoginModule.java:194) [jboss-negotiation-spnego-2.2.0.SP1.jar:2.2.0.SP1]
at org.jboss.security.negotiation.spnego.SPNEGOLoginModule.login(SPNEGOLoginModule.java:137) [jboss-negotiation-spnego-2.2.0.SP1.jar:2.2.0.SP1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_05]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_05] …Run Code Online (Sandbox Code Playgroud) 尝试通过SPNEGO和Kerberos对Windows客户端(IE/Firefox)进行身份验证.服务器端是Java/Tomcat,带有用于SPNEGO身份验证的JCIFS.在Win 2008 R2服务器上托管服务器端时,SSO(Kerberos)auth工作正常.但是,当在2012服务器上时,它失败了GSSException: Defective token detected.
通过网络跟踪深入挖掘我发现,在工作的情况下,IE客户端发送带有4个mechTypes的协商令牌:
MS KRB5,KRB5,NEGOEX,和NTLMSSP在这种情况下,我的服务器端将完成SPNEGO选择MS KRB5.但是,在问题的情况下,IE客户端只发送带有2个mechtypes的令牌 - NEGOEX和NTLMSSP.这是首选的发起人.Java不支持NEGOEX,因此失败.
一些搜索显示此问题与JDK*中的错误或DNS问题有关.但是,我在最新的JDK和DNS似乎没问题.所以我的问题是,Windows中的浏览器什么时候切换到SPNEGO中的NEGOEX?为什么?我找到的最接近的答案是在msdn博客中说的Kerberos is not available since it's not in a domain environment.但是,客户端确实在域环境中并klist显示有效的Kerberos票证.如果它确实是一个域问题,究竟可能是根本原因,我该如何避免这个问题呢?
让spring-security-kerberos-web与Spring Boot应用程序一起工作,我似乎已经达到了一个死胡同.
我的项目中有一个@Configuration类,如下所示
package com.co.dept.bsc.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider;
import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider;
import org.springframework.security.kerberos.authentication.sun.GlobalSunJaasKerberosConfig;
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter;
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import com.co.dept.bsc.service.DummyUserDetailsService;
@Configuration
@EnableWebSecurity
public class AuthProviderConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.exceptionHandling().authenticationEntryPoint(spnegoEntryPoint()).and().authorizeRequests().antMatchers("/", "/home")
.permitAll().anyRequest().authenticated().and().formLogin().loginPage("/login").permitAll().and().logout().permitAll()
.and()
.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class);
}
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(kerberosAuthenticationProvider())
.authenticationProvider(kerberosServiceAuthenticationProvider());
}
@Bean
public KerberosAuthenticationProvider kerberosAuthenticationProvider() { …Run Code Online (Sandbox Code Playgroud) 在我的 Python 脚本中,我在应用请求包时需要 gssapi 作为身份验证机制。
我注意到包 requests_gssapi 似乎对我的目的很有希望。
在“pip install requests_gssapi”并导入之后,我得到了这个:
>>> from requests_gssapi import HTTPSPNEGOAuth
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\opt\Python36\lib\site-packages\requests_gssapi\__init__.py", line 17, in <module>
from .gssapi_ import HTTPSPNEGOAuth, REQUIRED, OPTIONAL, DISABLED # noqa
File "C:\opt\Python36\lib\site-packages\requests_gssapi\gssapi_.py", line 6, in <module>
import gssapi
File "C:\opt\Python36\lib\site-packages\gssapi\__init__.py", line 29, in <module>
from gssapi.raw.types import NameType, RequirementFlag, AddressType # noqa
File "C:\opt\Python36\lib\site-packages\gssapi\raw\__init__.py", line 50, in <module>
from gssapi.raw.creds import * # noqa
ImportError: DLL load failed: …Run Code Online (Sandbox Code Playgroud) 我正在尝试配置嵌入式Jetty Web服务器以编程方式使用SPNEGO(不使用xml).
我试图将此转换为:http://www.eclipse.org/jetty/documentation/current/spnego-support.html到非基于xml的配置.这是我的尝试:
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
// ...
String domainRealm = "MY.DOMAIN.COM";
Constraint constraint = new Constraint();
constraint.setName(Constraint.__SPNEGO_AUTH);
constraint.setRoles(new String[] { domainRealm });
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
SpnegoLoginService loginService = new SpnegoLoginService();
loginService.setConfig(System.getProperty("spnego.properties"));
loginService.setName(domainRealm);
ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
sh.setLoginService(loginService);
sh.setConstraintMappings(new ConstraintMapping[]{cm});
sh.setRealmName(domainRealm);
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setErrorHandler(new ErrorHandler() { }); // TODO
contextHandler.setContextPath(contextPath);
contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), "/*");
contextHandler.addEventListener(new ContextLoaderListener(context));
contextHandler.setSecurityHandler(sh);
Server server = new Server(port);
server.setHandler(contextHandler);
Run Code Online (Sandbox Code Playgroud)
但是,当我点击服务器时,它正在尝试使用基本身份验证(base 64). …
我正在尝试将 SPNEGO/Kerberos5 身份验证与 Active Directory 2008 和 Java 一起使用。我遵循了本指南:http : //spnego.sourceforge.net/ - “预检”进展顺利,但后来我得到了著名的例外:
Exception in thread "main" GSSException: Failure unspecified at GSS-API level (Mechanism level: Checksum failed)
at sun.security.jgss.krb5.Krb5Context.acceptSecContext(Krb5Context.java:856)
at sun.security.jgss.GSSContextImpl.acceptSecContext(GSSContextImpl.java:342)
at sun.security.jgss.GSSContextImpl.acceptSecContext(GSSContextImpl.java:285)
at sun.security.jgss.spnego.SpNegoContext.GSS_acceptSecContext(SpNegoContext.java:906)
at sun.security.jgss.spnego.SpNegoContext.acceptSecContext(SpNegoContext.java:556)
at sun.security.jgss.GSSContextImpl.acceptSecContext(GSSContextImpl.java:342)
at sun.security.jgss.GSSContextImpl.acceptSecContext(GSSContextImpl.java:285)
at de.meona.auth.spnego.TestSpnegoAes.main(TestSpnegoAes.java:45)
Caused by: KrbException: Checksum failed
at sun.security.krb5.internal.crypto.Aes256CtsHmacSha1EType.decrypt(Aes256CtsHmacSha1EType.java:102)
Run Code Online (Sandbox Code Playgroud)
我仔细查看了这篇文章,因为问题似乎很相似: 校验和失败:Kerberos / Spring / Active Directory (2008)
为了使问题可重现,我编写了一个小的 Java 类。我能够单步到发生异常的那一行。我认为这是因为用于解密的秘密服务密钥与 Active Directory 用于加密服务票证的秘密服务密钥不同。怎么会这样?
public class TestSpnegoAes {
private static Oid spnegoOid = null;
private static String negotiate = …Run Code Online (Sandbox Code Playgroud)