【java – 从元素’global-method-security’开始发现无效内容】教程文章相关的互联网学习教程文章

java – 如何使用Spring security 2和Apache Tomcat 7设置将JSESSIONID cookie设置为安全【代码】

如何使用Spring security 2和Apache Tomcat 7设置将JSESSIONID cookie设置为安全. 已经在web.xml中放入了下面的代码,它似乎并没有起作用.<cookie-config><secure>true</secure> </cookie-config>谢谢解决方法:使用以下内容:<session-config><cookie-config><secure>true</secure><http-only>true</http-only></cookie-config> </session-config>

java.security.cert.CertificateParsingException:无效的DER编码证书数据【代码】

当我尝试将证书导入java密钥库时,我收到以下异常. “java.security.cert.CertificateParsingException:无效的DER编码证书数据”FileInputStream fis = new FileInputStream(filename); BufferedInputStream bis = new BufferedInputStream(fis);java.security.cert.CertificateFactory cf = java.security.cert.CertificateFactory.getInstance("X.509"); while (bis.available() > 0) {Certificate cert = cf.generateCertificat...

将Spring Security添加到现有的Spring Web App(使用JavaConfig)【代码】

我有一个Spring MVC Rest Web App,我正在添加一层Spring Security. 当我经历Spring documentation时,我无法理解第3.1.3节的含义.我正在复制/粘贴以下部分的内容.If we were using Spring elsewhere in our application we probably already had a WebApplicationInitializer that is loading our Spring Configuration. If we use the previous configuration we would get an error. Instead, we should register Spring Security...

java – 使用spring security进行手动身份验证并记住我的提供程序【代码】

我需要实现手动登录过程.身份验证工作正常:UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getEmail(), user.getPassword()); token.setDetails(new WebAuthenticationDetails(request)); Authentication authenticatedUser = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authenticatedUser);但是在这种情况下如何使用记住我...

如何清除java.security.Key的内容?【代码】

当您在Java应用程序中使用敏感数据时,通常会建议您使用原始类型 – 例如使用char []而不是String … 但是使用加密密钥,我们通常需要使用java.security.Key对象,因为这是JCE提供者使用的.密钥往往是非常敏感的信息,我们希望能够最小化可能的攻击窗口 – 即尽可能晚地创建密钥对象,进行加密/解密/签名,然后尽快清除对象.但Key没有提供任何能够促成这种清算的方法. 目前我们正在这样做,我们将密钥保存在字节数组中并在使用之前初始化K...

java.security.InvalidKeyException:生成RSA公钥时的无效密钥格式【代码】

背景: 我创建了一个applet来提取从智能卡中提取的证书的公钥.然后将该公钥存储在数据库中.证书的私钥用于对数据进行签名,然后使用公钥来验证签名.从证书中提取公钥的代码:private byte[] getPublicKey(KeyStore paramKeyStore)throws GeneralSecurityException {Enumeration localEnumeration = paramKeyStore.aliases();if (localEnumeration.hasMoreElements()) {String element = (String) localEnumeration.nextElement();Ce...

关于在谷歌应用引擎上使用spring security的java.lang.NoClassDefFoundError【代码】

我在我的谷歌应用程序中使用Spring Core框架版本4.1.6.RELEASE和Spring Security版本4.0.0.RELEASE.但是当我尝试在本地appservere中运行它时,我会看到以下日志org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: java.lang.reflect.Parameter is a rest...

java.security.InvalidKeyException:解密期间密钥大小错误【代码】

在解密期间,我得到的是“错误的密钥大小”或“给定的最终块未正确填充”,这取决于我正在运行的操作系统. 在Win7上,使用IBMJCE或SUNJCE(两者都是Java8),解密在25%的时间内失败:javax.crypto.BadPaddingException: Given final block not properly paddedat com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:811)at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)at com.sun.crypto.provider.DESed...

java – Spring Security BadCredentialsException如何映射到HTTP 401代码【代码】

当我抛出一个org.springframework.security.authentication.BadCredentialsException异常时,在客户端它将显示如下401,{"timestamp": "2016-03-29T09:07:50.866+0000","status": 401,"error": "Unauthorized","message": "Some message","path": "/test/service1/getAll" }我想知道BadCredentialsException在哪里以及如何映射到HTTP 401状态代码?解决方法:它是ExceptionTranslationFilter,它处理安全拦截器抛出的异常,并提供合适的...

java – 将用户对象存储在与Spring Security的会话中【代码】

根据我的理解,有许多不同的方法可以在Spring Security中检索经过身份验证的用户名. 我目前通过包含Principal作为控制器方法参数来获取用户名:@RequestMapping(value = "/dashboard", method = RequestMethod.GET) public ModelAndView displayHomePage(ModelAndView modelAndView, Principal principal) {modelAndView.addObject("email", principal.getName());// Render template located at src/main/resources/templates/dash...

java – 带有Salt的Spring Security 3 SHA-1【代码】

我有一个我们正在重写的遗留应用程序,我正在转换现有的用户表.密码使用带有盐的sha-1加密.特别是盐密码.例如,如果salt是ABC123且密码是XYZ789,那么要加密的字符串是ABC123XYZ789. Spring Security默认加密字符串XYZ789 {ABC123}.如何实现我自己的密码加密/验证以绕过Spring Security的默认加密. 我可以发布我的安全xml,但是如果我用加密的密码{salt}更新散列密码,一切正常. 谢谢你的帮助!解决方法:子类ShaPasswordEncoder并覆盖me...

java – 使用Spring Security自定义注销URL【代码】

我们在创建URI时遵循一定的约定.所有与身份验证相关的URI(例如/ login,/ logout,/ changepassword等)都属于子上下文/身份验证. 因此,我们的身份验证相关URI如下所示:/auth/login /auth/logout /auth/changepassword这就是我们在Spring安全上下文XML中所拥有的.<http pattern="/auth/**" security="none" /> <http pattern="/resources/**" security="none" /><http auto-config="true" access-decision-manager-ref="accessDecisi...

java – Spring Security中用于身份验证的Mock对象【代码】

现在对于单元测试我需要验证方法才能假装它正常工作,在我的情况下什么也不做,所以我可以测试方法本身是否做了预期的工作(根据单元测试原则在其他地方测试身份验证,但验证需要在那个方法里面调用) 这是我的TestNG类,我需要为身份验证制作模拟对象:package in.hexgen.api.facade;import javax.annotation.Resource;import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.Authenticat...

java – 如何防止spring security在成功登录后重定向到上一页?【代码】

我们使用Spring Security 2.0.7:=(在我们的应用程序中. Spring Security实现了以下功能:当未经身份验证的用户访问页面X时,会发生以下情况: >用户被重定向到登录页面>成功登录后,用户将被重定向到第X页而不是登录表单的目标. 在我的应用程序中,由于我无法控制的原因,这不是理想的行为.无论用户尝试访问的页面是什么,我们都希望登陆登录表单的目标页面. 问:是否可以禁用Spring Security的此功能以及如何实现? 我想标准过滤器链的...

java – 从元素’global-method-security’开始发现无效内容【代码】

在下面的代码我得到一个像这样的错误“cvc-complex-type.2.4.a:从元素’global-method-security’开始发现了无效的内容. ‘{“http://www.springframework.org/schema/beans”:import,“http://www.springframework.org/schema/ beans“:别名,”http://www.springframework.org/schema/beans“:bean,WC [## other:”http:// www.springframework.org/schema/beans“],”http://www.springframework.org/schema/beans“:bean...

元素 - 相关标签