Tag: spring security

spring security:NoSuchBeanDefinitionException:找不到类型的限定bean

我正在尝试为我的其他应用添加spring-security。 我在春季网站上按照教程( https://spring.io/guides/tutorials/spring-security-and-angular-js/ )进行操作,但是它使用了我不想使用的spring-boot组件,也许问题在这里。 我的安全配置在这里: @Configuration @Order(2147483636) public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic().and().authorizeRequests() .antMatchers(“/rest”, “/”).permitAll().anyRequest() .authenticated().and().csrf() .csrfTokenRepository(csrfTokenRepository()).and() .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class); } private Filter csrfHeaderFilter() { return new OncePerRequestFilter() { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class […]

使用REST和Javaconfig在Spring Security中消化Auth

我在使用spring security设置摘要式身份validation时遇到问题: 我的安全配置: @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserService userService; @Override @Bean public UserDetailsService userDetailsServiceBean() { return userService; } @Override protected void configure(AuthenticationManagerBuilder registry) throws Exception { registry.userDetailsService(userDetailsServiceBean()); } @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers(“/resources/**”); } @Override protected void configure(HttpSecurity http) throws Exception { […]

web.xmlfilter如何工作? 你有两个filter映射到所有页面(/ *)并指定顺序吗?

我想使用Spring Security,它说要将filter映射到/ ***。 但我已经有一个映射到/ *的filter,它是Tuckee URLRewritefilter。 是否可以将两个filter映射到同一个东西,还有一种方法可以指定filter被调用的顺序吗?

当Spring Security对用户进行身份validation时,如何在会话中管理自定义用户对象?

当Spring Security对用户进行身份validation时,它会创建一个UserDetail对象,并且可以在web-app中查找当前的UserId。 但是,假设我想保留一个带有首选项和其他详细信息的自定义用户对象以及UserDetails或Replacing UserDetails。 那么,当Spring Security成功validation时,如何向会话添加自定义用户对象? 以及如何在Spring Security注销登录用户时从会话中删除自定义用户对象。 或者有任何适当的方法来做到这一点?

官方Spring安全性oauth2示例不起作用(授权代码机制)

根据教程Spring Boot和OAuth2 我有以下项目结构: 以下源代码: SocialApplication.class: @SpringBootApplication @RestController @EnableOAuth2Client @EnableAuthorizationServer @Order(200) public class SocialApplication extends WebSecurityConfigurerAdapter { @Autowired OAuth2ClientContext oauth2ClientContext; @RequestMapping({ “/user”, “/me” }) public Map user(Principal principal) { Map map = new LinkedHashMap(); map.put(“name”, principal.getName()); return map; } @Override protected void configure(HttpSecurity http) throws Exception { // @formatter:off http.antMatcher(“/**”).authorizeRequests().antMatchers(“/”, “/login**”, “/webjars/**”).permitAll().anyRequest() .authenticated().and().exceptionHandling() .authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint(“/”)).and().logout() .logoutSuccessUrl(“/”).permitAll().and().csrf() […]

如何在所有模板中显示当前登录用户的信息,包括Spring Security应用程序中由WebMvcConfigurerAdapter管理的视图

我有一个使用Spring Security和Thymeleaf模板的Spring Boot应用程序。 当控制器由WebConfigurerAdapter的子类管理时,我试图在模板中显示登录用户的名字和姓氏。 所以,说我的WebConfigurerAdapter子类看起来像这样 @Configuration public class MvcConfig extends WebMvcConfigurerAdapter{ @Override public void addViewControllers(ViewControllerRegistry registry){ registry.addViewController(“/some-logged-in-page”).setViewName(“some-logged-in-page”); registry.addViewController(“/login”).setViewName(“login”); } …. } 我的用户实体类看起来像这样 @Entity @Table(name = “user”) public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = “id”, nullable = false, updatable = false) private Long id; @Column(name=”first_name”, nullable = false) private String firstName; public String […]

为什么Spring Security在Tomcat中工作,但在部署到Weblogic时却没有?

我不是一个真正的Java开发人员,但是客户的项目要求我,所以也许我错过了一些明显的东西。 我正在使用SpringBoot,当应用程序在我的本地计算机和测试服务器上的Tomcat中运行时,一切正常。 但是,只要将应用程序部署到Weblogic,就好像根本没有安全性可访问所有路径。 登录和注销路线也不存在。 话虽如此。 其他一切似乎都运行正常,完全没有任何安全性。 我无法访问Weblogic,因为客户端是部署代码的客户端,但他们告诉我们它正在12c上运行。 我该怎么做才能修复或排除故障? 这是我的Application.java中的相关配置: /** * The type Authentication security. */ @Order(Ordered.HIGHEST_PRECEDENCE) @Configuration protected static class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter { /** * The Users. */ @Autowired private Users users; /** * Init void. * * @param auth the auth * @throws Exception the exception */ @Override public void init(AuthenticationManagerBuilder auth) […]

登录后重定向到所需位置

我知道这个问题可以通过不同的解决方案找到。 但我无法让它在我的项目中运作。 我们正在向用户发送邮件,这些用户可以在应用程序中执行某些操作。 当用户点击url时,如果他没有登录,则应该重定向到登录页面,登录后应导航到目标URL。 我试图修复使用CustomLoginSuccessHandler这里是代码: public class CustomLoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { // public CustomLoginSuccessHandler(String defaultTargetUrl) { // setDefaultTargetUrl(defaultTargetUrl); // } @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { HttpSession session = request.getSession(false); if (session != null) { String redirectUrl = (String) session.getAttribute(“url_prior_login”); if (redirectUrl != null) { // we do […]

java.lang.ClassCastException:org.springframework.security.core.userdetails.User无法强制转换为model.User

我在我的应用程序中使用Spring Security。 我需要在我的应用程序的控制器中登录用户详细信息。 为此,我使用此代码 User loggedInUser = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 但是在运行此代码时,我得到了classcastexception java.lang.ClassCastException: org.springframework.security.core.userdetails.User cannot be cast to model.User 为了解决这个问题,我参考了这篇文章 最初我使用了CustomUserServiceDetails类 @Service(“myUserDetailService”) @Transactional public class CustomUserDetailsService implements UserDetailsService { private static final Logger logger = Logger.getLogger(CustomUserDetailsService.class); @Autowired private UserDAO userDAO; public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException, DataAccessException { // returns the get(0) of the user list obtained from […]

Spring-Security 3 / Spring MVC和可怕的@Secured / RequestMapping

我在向控制器添加安全注释时遇到了很多问题。 事实certificate让我的Controller实现一个InitializingBean是个坏主意。 public class MyController implements InitializingBean { @Secured(value=”ROLE_ADMIN”) @RequestMapping(method = RequestMethod.GET, value = “/{id}/edit”) public String getView(Model model, @PathVariable(“id”) long id) { return “some view”; } } 这失败了: WARN PageNotFound:962 – 找不到带URI的HTTP请求的映射[…] 删除@Secured Annotation会起作用,但显然我不想这样做。 在网上浪费了大量时间之后,我注意到工作和非工作控制器之间的最后一个区别是它实现了InitializingBean接口。 而现在这就像一个魅力: public class MyController{ @Secured(value=”ROLE_ADMIN”) @RequestMapping(method = RequestMethod.GET, value = “/{id}/edit”) public String getView(Model model, @PathVariable(“id”) long id) { […]