What is the replacement for the deprecated AuthorizationServer in Spring Security?

The first thing to note is that Spring Security OAuth 2.4.0 officially deprecates all its classes. The second thing is that according to the Spring Security – OAuth 2.0 Features Matrix – FAQ: We are no longer planning on adding Authorization Server support to Spring Security. One solution is to use an OAuth2 authorization server … Read more

Setting session timeout period with Spring Security 3.0

You can either set the session timeout (say 60 minutes) for all sessions in web.xml: <session-config> <session-timeout>60</session-timeout> </session-config> or on a per-session basis using session.setMaxInactiveInterval(60*60); the latter you might want to do in a authorizationSuccessHandler. <form-login authentication-success-handler-ref=”authenticationSuccessHandler”/>

An Authentication object was not found in the SecurityContext – Spring 3.2.2

The security’s authorization check part gets the authenticated object from SecurityContext, which will be set when a request gets through the spring security filter. My assumption here is that soon after the login this is not being set. You probably can use a hack as given below to set the value. try { SecurityContext ctx … Read more

How to apply Spring Security filter only on secured endpoints?

I have an application with the same requirement and to solve it I basically restricted Spring Security to a given ant match patter (using antMatcher) as follows: http .antMatcher(“/api/**”) .authorizeRequests() // .anyRequest().authenticated() // .and() .addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class); You can read it as follows: for http only invoke these configurations on requests matching the ant pattern /api/** … Read more

Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]

You need a spring-security-config.jar on your classpath. The exception means that the security: xml namescape cannot be handled by spring “parsers”. They are implementations of the NamespaceHandler interface, so you need a handler that knows how to process <security: tags. That’s the SecurityNamespaceHandler located in spring-security-config

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath

Same solution for maven: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>1.5.1.RELEASE</version> <exclusions> <exclusion> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </exclusion> </exclusions> </dependency>

Adding additional details to principal object stored in spring security context

Here is what you need: Extend spring User (org.springframework.security.core.userdetails.User) class and what ever properties you need. Extend spring UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService) and fill the above object. Override loadUserByUsername and return your extended user class Set your custom UserDetailsService in AuthenticationManagerBuilder For example public class CurrentUser extends User{ //This constructor is a must public CurrentUser(String username, String … Read more