Tag: spring security

Spring Oauth2:在SecurityContext中找不到身份validation对象

我有一个项目,我实现了Spring安全性和Spring OAuth2 Security。当我请求访问令牌时,它运行良好但是当我使用访问令牌请求资源时,我得到了“在SecurityContext中找不到身份validation对象”。 我的项目的SecurityContext是: <!– –> <!– –> <!– –> <!– –> <!– –> <!– –> <!– –> 我使用http:// localhost:8060 / oauth / token请求令牌?grant_type =密码&client_id = nokia3320&client_secret = 0987654321&username = subash&password = 123456我得到了以下回复 { “access_token”: “9f5a89ce-a0d9-4d65-8e83-5d3b16d8c025”, “token_type”: “bearer”, “refresh_token”: “c2ac82ec-9f41-46dd-b7c2-4772c018505c”, “expires_in”: 499, “scope”: “read trust write” } 当我尝试使用http:// localhost:8060 / Api / currencyList在authorizatioin错误中使用访问令牌访问资源时,我得到了以下响应 { “error”: […]

密码编码 – BCrypt – 不授权哈希密码,仅授权纯文本

我有一个宠物项目,我一直在慢慢削减,最近我决定为用户加入BCrypt密码编码。 我遇到的问题是它现在从未授权任何用户我已经拥有它,我无法弄清楚原因。 希望你们能帮忙。 以下是我的SecurityConfig.java文件中的配置 @Autowired private PasswordEncoder passwordEncoder; @Override protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception { auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(passwordEncoder); } @Bean public BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } 我的控制器注册新用户并将其记录在: @RequestMapping(value = “/user_create”, method = RequestMethod.POST) public String createUser(@ModelAttribute User user) { user.setPlain(user.getPassword()); user.setPassword(BCrypt.hashpw(user.getPassword(),BCrypt.gensalt())); userInterface.saveUser(user); return “redirect:/”; } 创建新用户可以完美地工作(将其加载到DB中),结果如下所示: ID | USERNAME | PLAIN_PASSWORD | HASHED_PASSWORD 1 […]

Spring安全性 – 方法级安全性不适用于从另一个方法调用

假设我有两种方法 @Secured(“ROLE_ADMIN”) @RequestMapping(value = “/methodA”, method = RequestMethod.GET) public void MethodA(){ // code } 和另一种调用第一种方法的方法 @RequestMapping(value = “/MethodB”, method = RequestMethod.GET) public void MethodB(){ MethodA(); //code } 如果我使用权限ROLE_USER登录到应用程序并尝试访问URL /methodA ROLE_USER ,我将获得访问被拒绝的exception – 完美! 但是,如果我访问URL /methodB即使我使用ROLE_USER权限访问MethodA,我也不会获得访问被拒绝的exception。 是应该像那样工作还是我做错了什么? PS:这不是一个实时应用场景,但我只是在玩代码。

Spring @Scheduler正在执行两次。 我正在使用spring security,如果我删除上下文参数spring安全性不起作用

我在我的应用程序中使用spring Scheduler和spring security。 如果spring-servlet.xml文件在上下文参数中分配,则spring安全工作正常,但Spring Scheduler执行两次。 安全的context.xml <!– –> 为spring-servlet.xml com.joseph.model org.hibernate.cfg.AnnotationConfiguration ${jdbc.dialect} true 调度程序类 package com.joseph.cronJob; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @Service public class SampleCronJobImpl implements SampleCronJob { private static int count=0; @Override @Scheduled(cron = “0 */1 * * * *”) public void testSchedulerfunction() { count++; System.out.println(“scheduler fuction call count: “+count); } } web.xml中 CRUDWebAppMavenizedold log4jConfigLocation […]

SpringBoot,如何在不使用ldif的情况下使用LDAP进行身份validation?

我在这里尝试SpringBoot中的LDAP身份validation示例 它使用的是我认为不适用于我的要求的ldif方法,因为我们的ldap管理员不会告诉我在哪里可以找到我需要的ldif。 在springboot之前,我曾经使用过自己的ldap实现而不是使用ldif。 有没有办法validation不使用ldif只是SECURITY_AUTHENTICATION.simple? 下面是我如何在基本的Java没有弹簧的ldap安全性。 如何在不使用ldif基本用户名密码的情况下在spring这样做。 boolean isLdapRegistred(String username, String password) { boolean result = false; try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, “com.sun.jndi.ldap.LdapCtxFactory”); env.put(Context.PROVIDER_URL, “ldap://10.xxx:389”); env.put(Context.SECURITY_AUTHENTICATION, “simple”); env.put(Context.SECURITY_PRINCIPAL, “OUR-DOMAIN\\” + username); env.put(Context.SECURITY_CREDENTIALS, password); // Create the initial context DirContext ctx = new InitialDirContext(env); result = ctx != null; if (ctx != null) ctx.close(); […]

Spring MVC – 试图互相交互的2个不同的Web应用程序(安全性)

我们有2个不同的Web应用程序在同一个tomcat上运行。 webapp#1,webapp#2。 Webapp#1通过此服务方法连接到webapp#2: this.restTemplate.postForObject(url, request, responseType); webapp#2正在以下控制器中接收此请求: @RequestMapping(value = “/bla”, method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) @ResponseBody public ResponseDTO requestSomething(@RequestBody RequestDTO requestDTO, HttpServletRequest request) { return new ResponseDTO(“Hello”); } 现在,我们有一个安全要求,即我们在webapp#2中显示的这个控制器只接收来自webapp#1的请求。 实现这一目标有哪些替代方案? 我们是否必须从webapp#1在webapp#2中创建一个新会话? 如果是这样,凭证来自哪里? 我们应该就预定义的东西达成一 春季安全有没有办法解决这个问题? 谢谢!

Spring Security sec:使用Java Config授权标记

我目前正在开发一个用例,我需要使用以下Spring Security taglib来显示(或不显示)基于用户权限的链接。 在查看日志时,我发现在谈到日志时没有任何反应 无论我的角色如何,我总是看到按钮。 当我使用hasRole时,它可以工作,所以我肯定错过了的工作。 在阅读Spring Security参考的以下部分时: 要使用此标记,还必须在应用程序上下文中有一个WebInvocationPrivilegeEvaluator实例。 如果您使用命名空间,将自动注册。 …问题是该引用不包括Java Config。 所以我想我只需要在SecurityConfig类中定义一个@Bean ,就像这样: @Bean public WebInvocationPrivilegeEvaluator webInvocationPrivilegeEvaluator() { return new DefaultWebInvocationPrivilegeEvaluator(); } …但是,它需要一个FilterSecurityInterceptor实例,我已经在日志中看到了它。 事实上,它已经是我的filter链的一部分,所以我想知道如何在上面的DefaultWebInvocationPrivilegeEvaluator构造函数中引用它? Spring Security 3.2.4.RELEASE参考: http ://docs.spring.io/spring-security/site/docs/3.2.4.RELEASE/reference/htmlsingle/#the-authorize-tag 谢谢

如何在Struts 2上使用Spring Security 3?

我已经阅读了很多关于在Struts 2上使用Spring Security 3的教程。但是我无法使它工作:/。 关于在Struts 2上实现这个框架,我找不到“Dummy step by step guide”。 这是我有的: web.xml中: struts2 org.apache.struts2.dispatcher.FilterDispatcher struts2 /* org.springframework.web.context.ContextLoaderListener cv 30 example/HelloWorld.jsp security.xml文件 还有我的HelloWorld.jsp Welcome! This session will be visible to an admin only. You are an Administrator. This session will be visible to an Customer only. You are an Customer. ${HelloMessage} <a href="https://stackoverflow.com/questions/12607719/how-use-spring-security-3-on-struts-2/”>Logout 我想测试权限如何使用标记“isAnonymous”显示该文本块,但我无法使其工作 🙁

在Spring中如何从“”打印用户名和姓氏

如何从打印用户名和姓 此principal.username仅打印用户ID。 但我想在这里打印用户名和数据库的名字。 可能吗?

Spring Security应用程序中Sitemesh未修饰的自定义错误页面

在带有Spring Security(3.2.0.RC2)和Sitemesh(2.4.2)的Spring MVC(3.2.4)应用程序中,web.xml文件具有以下条目: 403 /error?code=403 映射到ErrorController: @RequestMapping(“error”) public String displayErrorPage( @RequestParam(value = “code”, defaultValue = “0”) int code, Model model, final HttpServletRequest request, Principal principal) { // … return “errorPage”; } 它通过InternalResourceViewResolver显示errorPage.jsp(应用程序中没有其他视图解析器)。 安全性正常,当未经授权的用户尝试访问受保护的页面时,会显示errorPage.jsp,但该页面未进行装饰。 应用程序中的每个其他页面都没有任何问题进行修饰,并且errorPage.jsp与其他装饰没有任何问题的JSP存在于同一目录中。 此应用程序使用Servlet 3.0规范。