Spring security filter chain

Key filters in the chain are (in the order) SecurityContextPersistenceFilter (restores Authentication from JSESSIONID) UsernamePasswordAuthenticationFilter (performs authentication) ExceptionTranslationFilter (catch security exceptions from FilterSecurityInterceptor) FilterSecurityInterceptor (may throw authentication and authorization exceptions) Filter Ordering: The order that filters are defined in the chain is very important. Irrespective of which filters you are…

Continue reading

Retrieve the user details in Spring Security

Get the User in a Bean Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!(authentication instanceof AnonymousAuthenticationToken)) { String currentUserName = authentication.getName(); return currentUserName; } Get the User in a Controller In a @Controller annotated bean, there are additional options – the principal can be defined directly as a method argument and it will be correctly resolved…

Continue reading

Enable Spring Security

Spring Security is based entirely on Servlet Filters we can declare it in web.xml of the application: <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> Spring Security Java Configuration @Config @EnableWebSecurity public class SecurityJavaConfig extends WebSecurityConfigurerAdapter { // … } Now, let’s create users with different roles in SecurityJavaConfig that we will be using…

Continue reading

Spring Security Interview Questions

Q: How is Security mechanism implemented using Spring? A: Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications. Spring Security is a framework that focuses on providing both authentication and authorization to Java applications. Like all Spring projects, the…

Continue reading

Intoduction to Spring Boot

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Spring had few drawback mainly of the configuration that was required.Most Spring Boot…

Continue reading

Fetching strategies in Hibernate

Hibernate uses a fetching strategy to retrieve associated objects if the application needs to navigate the association. Fetch strategies can be declared in the O/R mapping metadata, or over-ridden by a particular HQL or Criteria query. Hibernate3 defines the following fetching strategies: Join fetching: Hibernate retrieves the associated instance or…

Continue reading

Joins In Hibernate

Hibernate supports 4 types of joins.. Left Join Right  Join Full Join Inner Join the DEFAULT join in hibernate is Inner join Similar posts: Hibernate Architecture Hibernate Using Mapping File Inheritance Mapping In Hibernate Inheritance-Table Per Class Hierarchy Hibernate-generator-element

Continue reading

Microservices

What Are Microservices? Microservices are a form of service-oriented architecture style (one of the most important skills for Java developers) wherein applications are built as a collection of different smaller services rather than one whole app. Instead of a monolithic app, you have several independent applications that can run on…

Continue reading

Default Method

Need for default method- Without effecting implementation classes if we want to add new method to the interface then we can do this with default interface. Syntax:

Output: Default Method Suppose if we want to provide new implementation then we can do this as well. This can be done as…

Continue reading

Lamda_SquareExample

Lamda Expression example for square of int :

Output: Square of 2 is :4 now suppose we put parenthesis in the body as below and try to compile the code using command prompt,

you will get compilation error as below: \basic>javac Lamda_SquareExample.java Lamda_SquareExample.java:13: error: not a statement Interfun…

Continue reading