Spring Security – Remember Me

Spring Security – Remember Me ”; Previous Next Remember Me is an important function of Spring Security, so that a user can remain logged in the application even when session is expired. We”ll demonstrate the use of Remember Me functionality provided by Spring security in following sections. A Remember Me functionality performs following important functions. Firstly, it will add a “Remember Me” checkbox to default login form that we generated using formLogin(). In case of custom login form, we need to add a checkbox named “remember-me” to the form. In case of different name to be used, we need to configure the new name during Spring Security configuration as shown below: .rememberMe().rememberMeParameter(“remember”) And, secondly, ticking the checkbox generates the remember-me cookie. The cookie stores the identity of the user and the browser stores it. Spring Security detects the cookie in future sessions to automate the login. As a result, the user can access the application again without logging in again. A remember-me can be explicitly configured as given below − protected void configure(HttpSecurity http) throws Exception { http // … // key should be unique .rememberMe(config -> config.key(“123456″) .tokenValiditySeconds(3600)) .build(); } Important Methods Following are important methods that we can configure in logout() method. rememberMe () − This will be used to implement remember me functionality. The key passed to remember-me function should be unique and secret. This key is application specific and is used to generate remember me token content. tokenValiditySeconds () − This will be used to set the expiry of the remember me cookie. By default it has validity of 2 weeks. We can customize it any time as in above code snippet, we”ve set it as 1 hour using 3600 seconds. rememberMeParameter () − This is used to mark an input check box to be remember-me checkbox. By default, its value is remember-me. Let us start actual programming with Spring Security. Before you start writing your example using Spring framework, you have to make sure that you have set up your Spring environment properly as explained in Spring Security – Environment Setup Chapter. We also assume that you have a bit of working knowledge on Spring Tool Suite IDE. Now let us proceed to write a Spring MVC based Application managed by Maven, which will ask user to login, authenticate user and then provide option to logout using Spring Security Form Login Feature. Create Project using Spring Initializr Spring Initializr is great way to start with Spring Boot project. It provides a easy to use User Interface to create a project, add dependencies, select java runtime etc. It generates a skeleton project structure which once downloaded can be imported in spring tool suite and we can proceed with our readymade project structure. We”re choosing a maven project, naming the project as formlogin, with java version as 21. Following dependencies are added: Spring Web Spring Security Thymeleaf Spring Boot DevTools Thymeleaf is a templating engine for Java. It allows us to quickly develop static or dynamic web pages for rendering in the browser. It is extremely extensible and allows us to define and customize the processing of our templates in fine detail. In addition to this, we can learn more about Thymeleaf by clicking this link. Let”s move on to generate our project and download it. We then extract it to a folder of our choice and use any IDE to open it. I shall be using Spring Tools Suite 4. It is available for free downloading from the https://spring.io/tools website and is optimized for spring applications. pom.xml with all relevant dependencies Let”s take a look at our pom.xml file. It should look something similar to this − pom.xml <?xml version=”1.0″ encoding=”UTF-8″?> <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.3.1</version> <relativePath/> <!– lookup parent from repository –> </parent> <groupId>com.tutorialspoint.security</groupId> <artifactId>formlogin</artifactId> <version>0.0.1-SNAPSHOT</version> <name>formlogin</name> <description>Demo project for Spring Boot</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>21</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity6</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> Spring Security Configuration Class Inside of our config package, we have created the WebSecurityConfig class. We shall be using this class for our security configurations, so let”s annotate it with an @Configuration annotation and @EnableWebSecurity. As a result, Spring Security knows to treat this class a configuration class. As we can see, configuring applications have been made very easy by Spring. WebSecurityConfig package com.tutorialspoint.security.formlogin.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.web.SecurityFilterChain; @Configuration @EnableWebSecurity public class WebSecurityConfig { @Bean protected UserDetailsService userDetailsService() { UserDetails user = User.builder() .username(“user”) .password(passwordEncoder().encode(“user123”)) .roles(“USER”) .build(); UserDetails admin = User.builder() .username(“admin”) .password(passwordEncoder().encode(“admin123”)) .roles(“USER”, “ADMIN”) .build(); return new InMemoryUserDetailsManager(user, admin); } @Bean protected PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Bean protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http .csrf(AbstractHttpConfigurer::disable) .authorizeHttpRequests( request -> request.requestMatchers(“/login”).permitAll() .requestMatchers(“/**”).authenticated() ) .formLogin(form -> form.loginPage(“/login”) .defaultSuccessUrl(“/”) .failureUrl(“/login?error=true”) .permitAll()) .rememberMe(config -> config.key(“123456”) .tokenValiditySeconds(3600)) .logout(config -> config .logoutUrl(“/logout”) .logoutSuccessUrl(“/login”) .invalidateHttpSession(true) .deleteCookies(“JSESSIONID”)) .build(); } } Here we”ve mentioned the rememberMe() with a secure key for spring security. Controller Class In this class, we”ve created a mapping for “/” endpoint and for “/login” for the index page and login page of this application. AuthController.java package com.tutorialspoint.security.formlogin.controllers; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class AuthController { @GetMapping(“/”) public String home() { return “index”; } @GetMapping(“/login”) public String login() { return “login”; } } Views Let”s create index.html in /src/main/resources/templates folder with following content to act as a home page and to display logged in user name. index.html <!DOCTYPE html> <html xmlns=”http://www.w3.org/1999/xhtml” xmlns:th=”https://www.thymeleaf.org” xmlns:sec=”https://www.thymeleaf.org/thymeleaf-extras-springsecurity3″> <head> <title> Hello World! </title> </head> <body> <h1 th:inline=”text”>Hello <span sec:authentication=”name”></span>!</h1> <form th:action=”@{/logout}” method=”post”> <input type=”submit” value=”Sign Out”/> </form> </body> <html> login.html Let”s create the login.html in /src/main/resources/templates folder with following content

Spring Security – Redirection

Spring Security – Redirection ”; Previous Next In web application, we”re often required to land to different pages based on user profile. For example, a normal user may land on user home page whereas an admin may land on Admin console. We can achieve this requirement very easily using spring security which provides supports to handle login success and based on user role, we can decide which page to be shown to the user or simply redirect the user to the required page. In order to achieve redirection, we need to handle successHandler of formLogin in Spring Security Configuration as shown below: protected void configure(HttpSecurity http) throws Exception { http // … // key should be unique .formLogin(form -> form.loginPage(“/login”) .defaultSuccessUrl(“/”) .failureUrl(“/login?error=true”) .successHandler(authenticationSuccessHandler()) .permitAll()) // .build(); } Here authenticationSuccessHandler() method is another bean to handle login success and redirect user to the required page. @Bean public AuthenticationSuccessHandler authenticationSuccessHandler() { return new AuthenticationHandler(); } AuthenticationSuccessHandler In order to achieve redirection, we first need to create a class by implementing AuthenticationSuccessHandler as shown below. In this class, we”ve to implement onAuthenticationSuccess() method. onAuthenticationSuccess() method is called once user is logged in successfully. Now using Authentication object, we can check the role of the logged in user and then determine the redirection url. Using HttpServletResponse.sendRedirect() method, we can then redirect user to the required page. public class AuthenticationHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { String redirect = request.getContextPath(); if (authentication.getAuthorities().stream().anyMatch(a -> a.getAuthority().equals(“ROLE_ADMIN”))) { redirect = “/admin”; } else if (authentication.getAuthorities().stream().anyMatch(a -> a.getAuthority().equals(“ROLE_USER”))) { redirect = “/user”; } response.sendRedirect(redirect); } } Let us start actual programming with Spring Security. Before you start writing your first example using Spring framework, you have to make sure that you have set up your Spring environment properly as explained in Spring Security – Environment Setup Chapter. We also assume that you have a bit of working knowledge on Spring Tool Suite IDE. Now let us proceed to write a Spring MVC based Application managed by Maven, which will ask user to login, authenticate user and then provide option to logout using Spring Security Form Login Feature. Create Project using Spring Initializr Spring Initializr is great way to start with Spring Boot project. It provides a easy to use User Interface to create a project, add dependencies, select java runtime etc. It generates a skeleton project structure which once downloaded can be imported in spring tool suite and we can proceed with our readymade project structure. We”re choosing a maven project, naming the project as formlogin, with java version as 21. Following dependencies are added: Spring Web Spring Security Thymeleaf Spring Boot DevTools Thymeleaf is a templating engine for Java. It allows us to quickly develop static or dynamic web pages for rendering in the browser. It is extremely extensible and allows us to define and customize the processing of our templates in fine detail. In addition to this, we can learn more about Thymeleaf by clicking this link. Let”s move on to generate our project and download it. We then extract it to a folder of our choice and use any IDE to open it. I shall be using Spring Tools Suite 4. It is available for free downloading from the https://spring.io/tools website and is optimized for spring applications. pom.xml with all relevant dependencies Let”s take a look at our pom.xml file. It should look something similar to this − pom.xml <?xml version=”1.0″ encoding=”UTF-8″?> <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.3.1</version> <relativePath/> <!– lookup parent from repository –> </parent> <groupId>com.tutorialspoint.security</groupId> <artifactId>formlogin</artifactId> <version>0.0.1-SNAPSHOT</version> <name>formlogin</name> <description>Demo project for Spring Boot</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>21</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity6</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> Spring Security Configuration Class Inside of our config package, we have created the WebSecurityConfig class. We shall be using this class for our security configurations, so let”s annotate it with an @Configuration annotation and @EnableWebSecurity. As a result, Spring Security knows to treat this class a configuration class. As we can see, configuring applications have been made very easy by Spring. WebSecurityConfig package com.tutorialspoint.security.formlogin.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; @Configuration @EnableWebSecurity public class WebSecurityConfig { @Bean protected UserDetailsService userDetailsService() { UserDetails user = User.builder() .username(“user”) .password(passwordEncoder().encode(“user123”)) .roles(“USER”) .build(); UserDetails admin = User.builder() .username(“admin”) .password(passwordEncoder().encode(“admin123”)) .roles(“USER”, “ADMIN”) .build(); return new InMemoryUserDetailsManager(user, admin); } @Bean protected PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Bean protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http .csrf(AbstractHttpConfigurer::disable) .authorizeHttpRequests( request -> request.requestMatchers(“/login”).permitAll() .requestMatchers(“/**”).authenticated() ) .formLogin(form -> form.loginPage(“/login”) .defaultSuccessUrl(“/”) .failureUrl(“/login?error=true”) .successHandler(authenticationSuccessHandler()) .permitAll()) .rememberMe(config -> config.key(“123456”) .tokenValiditySeconds(3600)) .logout(config -> config .logoutUrl(“/logout”) .logoutSuccessUrl(“/login”) .invalidateHttpSession(true) .deleteCookies(“JSESSIONID”)) .build(); } @Bean public AuthenticationSuccessHandler authenticationSuccessHandler() { return new AuthenticationHandler(); } } Here we”ve used the authenticationSuccessHandler() in successHandler() method to do the required redirection. The AuthenticationHandler class should be in same package. AuthenticationHandler class Following class implements AuthenticationSuccessHandler as shown below. In this class, we”ve implemented onAuthenticationSuccess() method. onAuthenticationSuccess() method is called once user is logged in successfully. AuthenticationHandler package com.tutorialspoint.security.formlogin.config; import java.io.IOException; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; public class AuthenticationHandler implements AuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { String redirect = request.getContextPath(); if (authentication.getAuthorities().stream().anyMatch(a -> a.getAuthority().equals(“ROLE_ADMIN”))) { redirect = “/admin”; } else if (authentication.getAuthorities().stream().anyMatch(a -> a.getAuthority().equals(“ROLE_USER”))) { redirect = “/user”; } response.sendRedirect(redirect); } } Controller Class In this class, we”ve created a mapping for “/” endpoint and for “/login” for the index page and login page of this application. For user.html and admin.html we”ve two methods user() and admin() added. AuthController.java package com.tutorialspoint.security.formlogin.controllers; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class AuthController {

Spring Security – Introduction

Spring Security – Introduction ”; Previous Next What is Spring Security? Spring Security is one of Spring Project or Module to secure a Spring based application. Spring security provides us many in-built features to implement authentication and authorization in our application. We can use these features with our changes to secure an application very quickly. In addition to this, Spring Security also allows plenty of customizations to the features mentioned before to implement our own complex authentications and authorizations. In addition to providing various inbuilt authentication and authorization options, Spring Security allows us to customize our authentication process as much as we want. Starting from a custom login page to our very own customized authentication providers and authentication filters, we can pretty much customize every aspect of the authentication process. We can define our own authentication process which can range from basic authentication using a username and a password to a complex one such as two-factor authentication using tokens and OTP’s. Also, we can use various databases – both relational and non-relational, use various password encoders, lock malicious users out of their accounts, and so on. Authentication and Authorization Authentication and Authorization are two main components of Spring Security. Authentication − Authentication is to ensure that the user or the client is who they claim to be. There are many ways in which Spring Security enables us to perform authentication. Spring Security supports Basic Authentication, LDAP authentication, JDBC authentication, etc. Authorization − Authorization ensures whether the user has permission for the action or not. If our application is a complex one, with different kinds of users such as admins, regular users, other less privileged users, we need to maintain access control in our application. For example, a guest user should not be able to access admin content. So, to control access to various resources within our application, we need to check if a user has permission to access that resource. Spring Security supports roles, claims etc. to provide user level authorization. Spring Security supports a large set of authentication models. Most of these authentication models are developed by third parties or by Internet Engineering Task Force, IETF as a standard body. Being able to integrate with wide set of third parties autentication models, spring security becomes very popular among developers to integrate in their projects. Spring provides its own authentication features as well. Following list shows the various authentication methods supported by Spring security. HTTP BASIC authentication headers HTTP Digest authentication headers HTTP X.509 client certificate exchange LDAP Form-based authentication OpenID authentication Authentication based on pre-established request headers JA-SIG Central Authentication Service, a open source single sign on system Transparent authentication context propagation for Remote Method Invocation (RMI) and HttpInvoker Remember Me Anonymous authentication Run-as authentication Java Authentication and Authorization Service (JAAS) JEE container autentication Kerberos Java Open Source Single Sign On (JOSSO) OpenNMS Network Management Platform AppFuse AndroMDA Mule ESB Direct Web Request (DWR) Grails Tapestry JTrac Jasypt Roller Elastic Path Atlassian Crowd We can integrate own custom authentication mechanism as well with Spring Security. History of Spring Security Spring Security started in late 2003 as The Acegi Security System for Spring as a simple Spring based security implementation. Later as spring community members enquired for an existing framework, it was assigned to one of the community member to work and by Jan 2004, a team of 20+ people started working in this project which was later established as a SourceForge project in Mar 2004. Initially spring security had not its authentication module and it was relying completely on Container managed security and Acegi security system was focusing only on authorization modules. In following year, 2005, Acegi Security specific Authentication services were introduced and Acegi Security System became an official Spring sub-project. In May 2006, after being used in numerous production softwares, community improvements and bug fixes, 1.0.0 was released. By the end of 2007, Acegi Security System was rebranded as Spring Security and it became an Official Spring Portfolio Project. Print Page Previous Next Advertisements ”;

Sprint Security – Home

Spring Security Tutorial PDF Version Quick Guide Resources Job Search Discussion In this tutorial, we will learn about Spring Security Frameworks. We will start with the basics and go through the configuration of various frameworks to work with Spring Security. We will also do some handson coding to perform CRUD operation using Spring Security Frameworks. Audience This tutorial will be useful for graduates, post graduates, and research students who either have an interest in this subject or have this subject as a part of their curriculum. The reader can be a beginner or an advanced learner. Prerequisites Though there is NO mandatory requirement to have for this tutorial. However, if you have any or all (supercool) prior knowledge on any below mentioned technologies that will be an added advantage − About 30 minutes Basic Spring Security knowledge A Basic understanding of the Apache Solr Database. A java based IDE (Eclipse, STS or IntelliJ IDEA) JDK 1.8 or later Gradle 4+ or Maven 3.2+ Apache Solr installed Print Page Previous Next Advertisements ”;

Spring Security – Taglibs

Spring Security – Taglibs ”; Previous Next In Spring MVC applications using JSP, we can use the Spring Security tags for applying security constraints as well as for accessing security information. Spring Security Tag library provides basic support for such operations. Using such tags, we can control the information displayed to the user based on his roles or permissions. Also, we can include CSRF protection features in our forms. To use Spring security tags, we must have the security taglib declared in our JSP file. <%@ taglib prefix=”sec” uri=”http://www.springframework.org/security/tags” %> Now, we can use Spring Security tags with the sec prefix. Let”s now see the usage of the tags. The authorize Tag The first tag we will be discussing is the authorize tag. Let’s check out some usage examples. <sec:authorize access=”!isAuthenticated()”> Login </sec:authorize> <sec:authorize access=”isAuthenticated()”> Logout </sec:authorize> <sec:authorize access=”hasRole(”ADMIN”)”> Hello Admin. </sec:authorize> As we can see, we can use this tag to hide or show sections of information based on access or roles. hasRole(ADMIN) − evaluates to true if the current user has the admin role. hasAnyRole(‘ADMIN’,’USER’) − evaluates to true if the current user has any of the listed roles isAnonymous() − evaluates to true if the current user is an anonymous user isRememberMe() − evaluates to true if the current user is a remember-me user isFullyAuthenticated() − evaluates to true if the user is authenticated and is neither anonymous nor a remember-me user As we can see, the access attribute is where the web-security expression is specified. Then, Spring Security evaluates the expression. The evaluation is generally delegated to SecurityExpressionHandler<FilterInvocation>, which is defined in the application context. If it returns true, then the user can get access to the information given in that section. If we use the authorize tag with Spring Security ‘s Permission Evaluator, we can also check user permissions as given below − <p sec:authorize=”hasPermission(#domain,”read”) or hasPermission(#domain,”write”)”> This content is visible to users who have read or write permission. </p> We can also allow or restrict the user from clicking on certain links within our content. <a sec:authorize href=”/admin”> This content will only be visible to users who are authorized to send requests to the “/admin” URL. </agt; The authentication tag When we want access to the current Authentication object stored in the Spring Security Context, we can use the authentication tag. Then we can use it to render properties of the object directly in our JSP page. For example, if we want to render the principal property of the Authentication object in our page, we can do it as follows − <p sec:authentication=”name” /> The csrfInput Tag We can use the csrfInput tag to insert a hidden form field with the correct values for the CSRF protection token when CSRF protection is enabled. If CSRF protection is not enabled, this tag outputs nothing. We can place the tag within the HTML <form></form> block along with other input fields. However, we must not place the tag within the <form:form></form:form> block as Spring Security automatically inserts a CSRF form field within those tags and also takes care of Spring forms automatically. <form method=”post” action=”/do/something”> <sec:csrfInput /> Username:<br /> <input type=”text” username=”username” /> … </form> The csrfMetaTags Tag We can use this tag to insert meta tags which contain the CSRF protection token form field and header names and CSRF protection token value. These meta tags can be useful for employing CSRF protection within Javascript in our application. However, this tag only works when we have enabled CSRF protection in our application, otherwise, this tag outputs nothing. <html> <head> <title>CSRF Protection in Javascript</title> <sec:csrfMetaTags /> <script type=”text/javascript” language=”javascript”> var csrfParam = $(“meta[name=”_csrf_param”]”).attr(“content”); var csrfToken = $(“meta[name=”_csrf”]”).attr(“content”); </script> </head> <body> … </body> </html> Let us start actual programming with Spring Security. Before you start writing your example using Spring framework, you have to make sure that you have set up your Spring environment properly as explained in Spring Security – Environment Setup Chapter. We also assume that you have a bit of working knowledge on Spring Tool Suite IDE. Now let us proceed to write a Spring MVC based Application managed by Maven, which will ask user to login, authenticate user and then provide option to logout using Spring Security Form Login Feature. Create Project using Spring Initializr Spring Initializr is great way to start with Spring Boot project. It provides a easy to use User Interface to create a project, add dependencies, select java runtime etc. It generates a skeleton project structure which once downloaded can be imported in spring tool suite and we can proceed with our readymade project structure. We”re choosing a maven project, naming the project as formlogin, with java version as 21. Following dependencies are added: Spring Web Spring Security Thymeleaf Spring Boot DevTools Thymeleaf is a templating engine for Java. It allows us to quickly develop static or dynamic web pages for rendering in the browser. It is extremely extensible and allows us to define and customize the processing of our templates in fine detail. In addition to this, we can learn more about Thymeleaf by clicking this link. Let”s move on to generate our project and download it. We then extract it to a folder of our choice and use any IDE to open it. I shall be using Spring Tools Suite 4. It is available for free downloading from the https://spring.io/tools website and is optimized for spring applications. pom.xml with all relevant dependencies Let”s take a look at our pom.xml file. It should look something similar to this − pom.xml <?xml version=”1.0″ encoding=”UTF-8″?> <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.3.1</version> <relativePath/> <!– lookup parent from repository –> </parent> <groupId>com.tutorialspoint.security</groupId> <artifactId>formlogin</artifactId> <version>0.0.1-SNAPSHOT</version> <name>formlogin</name> <description>Demo project for Spring Boot</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>21</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity6</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId>

Spring Boot – Bootstrapping

Spring Boot – Bootstrapping ”; Previous Next This chapter will explain you how to perform bootstrapping on a Spring Boot application. Spring Initializer One of the ways to Bootstrapping a Spring Boot application is by using Spring Initializer. To do this, you will have to visit the Spring Initializer web page www.start.spring.io and choose your Build, Spring Boot Version and platform. Also, you need to provide a Group, Artifact and required dependencies to run the application. Observe the following screenshot that shows an example where we added the spring-boot-starter-web dependency to write REST Endpoints. Once you provided the Group, Artifact, Dependencies, Build Project, Platform and Version, click Generate Project button. The zip file will download and the files will be extracted. This section explains you the examples by using both Maven and Gradle. Maven After you download the project, unzip the file. Now, your pom.xml file looks as shown below − <?xml version = “1.0” encoding = “UTF-8”?> <project xmlns = “http://maven.apache.org/POM/4.0.0” xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation = “http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <modelVersion>4.0.0</modelVersion> <groupId>com.tutorialspoint</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>demo</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version> <relativePath/> <!– lookup parent from repository –> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> Gradle Once you download the project, unzip the file. Now your build.gradle file looks as shown below − buildscript { ext { springBootVersion = ”1.5.8.RELEASE” } repositories { mavenCentral() } dependencies { classpath(“org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}”) } } apply plugin: ”java” apply plugin: ”eclipse” apply plugin: ”org.springframework.boot” group = ”com.tutorialspoint” version = ”0.0.1-SNAPSHOT” sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile(”org.springframework.boot:spring-boot-starter-web”) testCompile(”org.springframework.boot:spring-boot-starter-test”) } Class Path Dependencies Spring Boot provides a number of Starters to add the jars in our class path. For example, for writing a Rest Endpoint, we need to add the spring-boot-starter-web dependency in our class path. Observe the codes shown below for a better understanding − Maven dependency <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> Gradle dependency dependencies { compile(”org.springframework.boot:spring-boot-starter-web”) } Main Method The main method should be writing the Spring Boot Application class. This class should be annotated with @SpringBootApplication. This is the entry point of the spring boot application to start. You can find the main class file under src/java/main directories with the default package. In this example, the main class file is located at the src/java/main directories with the default package com.tutorialspoint.demo. Observe the code shown here for a better understanding − package com.tutorialspoint.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } Write a Rest Endpoint To write a simple Hello World Rest Endpoint in the Spring Boot Application main class file itself, follow the steps shown below − Firstly, add the @RestController annotation at the top of the class. Now, write a Request URI method with @RequestMapping annotation. Then, the Request URI method should return the Hello World string. Now, your main Spring Boot Application class file will look like as shown in the code given below − package com.tutorialspoint.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @RestController public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @RequestMapping(value = “/”) public String hello() { return “Hello World”; } } Create an Executable JAR Let us create an executable JAR file to run the Spring Boot application by using Maven and Gradle commands in the command prompt as shown below − Use the Maven command mvn clean install as shown below − After executing the command, you can see the BUILD SUCCESS message at the command prompt as shown below − Use the Gradle command gradle clean build as shown below − After executing the command, you can see the BUILD SUCCESSFUL message in the command prompt as shown below − Run Hello World with Java Once you have created an executable JAR file, you can find it under the following directories. For Maven, you can find the JAR file under the target directory as shown below − For Gradle, you can find the JAR file under the build/libs directory as shown below − Now, run the JAR file by using the command java –jar <JARFILE>. Observe that in the above example, the JAR file is named demo-0.0.1-SNAPSHOT.jar Once you run the jar file, you can see the output in the console window as shown below − Now, look at the console, Tomcat started on port 8080 (http). Now, go to the web browser and hit the URL http://localhost:8080/ and you can see the output as shown below − Print Page Previous Next Advertisements ”;

Spring Boot – Application Properties

Spring Boot – Application Properties ”; Previous Next Application Properties support us to work in different environments. In this chapter, you are going to learn how to configure and specify the properties to a Spring Boot application. Command Line Properties Spring Boot application converts the command line properties into Spring Boot Environment properties. Command line properties take precedence over the other property sources. By default, Spring Boot uses the 8080 port number to start the Tomcat. Let us learn how change the port number by using command line properties. Step 1 − After creating an executable JAR file, run it by using the command java –jar <JARFILE>. Step 2 − Use the command given in the screenshot given below to change the port number for Spring Boot application by using command line properties. Note − You can provide more than one application properties by using the delimiter −. Properties File Properties files are used to keep ‘N’ number of properties in a single file to run the application in a different environment. In Spring Boot, properties are kept in the application.properties file under the classpath. The application.properties file is located in the src/main/resources directory. The code for sample application.properties file is given below − server.port = 9090 spring.application.name = demoservice Note that in the code shown above the Spring Boot application demoservice starts on the port 9090. YAML File Spring Boot supports YAML based properties configurations to run the application. Instead of application.properties, we can use application.yml file. This YAML file also should be kept inside the classpath. The sample application.yml file is given below − spring: application: name: demoservice server: port: 9090 Externalized Properties Instead of keeping the properties file under classpath, we can keep the properties in different location or path. While running the JAR file, we can specify the properties file path. You can use the following command to specify the location of properties file while running the JAR − -Dspring.config.location = C:application.properties Use of @Value Annotation The @Value annotation is used to read the environment or application property value in Java code. The syntax to read the property value is shown below − @Value(“${property_key_name}”) Look at the following example that shows the syntax to read the spring.application.name property value in Java variable by using @Value annotation. @Value(“${spring.application.name}”) Observe the code given below for a better understanding − import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @RestController public class DemoApplication { @Value(“${spring.application.name}”) private String name; public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @RequestMapping(value = “/”) public String name() { return name; } } Note − If the property is not found while running the application, Spring Boot throws the Illegal Argument exception as Could not resolve placeholder ”spring.application.name” in value “${spring.application.name}”. To resolve the placeholder issue, we can set the default value for the property using thr syntax given below − @Value(“${property_key_name:default_value}”) @Value(“${spring.application.name:demoservice}”) Spring Boot Active Profile Spring Boot supports different properties based on the Spring active profile. For example, we can keep two separate files for development and production to run the Spring Boot application. Spring active profile in application.properties Let us understand how to have Spring active profile in application.properties. By default, application. properties will be used to run the Spring Boot application. If you want to use profile based properties, we can keep separate properties file for each profile as shown below − application.properties server.port = 8080 spring.application.name = demoservice application-dev.properties server.port = 9090 spring.application.name = demoservice application-prod.properties server.port = 4431 spring.application.name = demoservice While running the JAR file, we need to specify the spring active profile based on each properties file. By default, Spring Boot application uses the application.properties file. The command to set the spring active profile is shown below − You can see active profile name on the console log as shown below − 2017-11-26 08:13:16.322 INFO 14028 — [ main] com.tutorialspoint.demo.DemoApplication : The following profiles are active: dev Now, Tomcat has started on the port 9090 (http) as shown below − 2017-11-26 08:13:20.185 INFO 14028 — [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9090 (http) You can set the Production active profile as shown below − You can see active profile name on the console log as shown below − 2017-11-26 08:13:16.322 INFO 14028 — [ main] com.tutorialspoint.demo.DemoApplication : The following profiles are active: prod Now, Tomcat started on the port 4431 (http) as shown below − 2017-11-26 08:13:20.185 INFO 14028 — [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 4431 (http) Spring active profile for application.yml Let us understand how to keep Spring active profile for application.yml. We can keep the Spring active profile properties in the single application.yml file. No need to use the separate file like application.properties. The following is an example code to keep the Spring active profiles in application.yml file. Note that the delimiter (—) is used to separate each profile in application.yml file. spring: application: name: demoservice server: port: 8080 — spring: profiles: dev application: name: demoservice server: port: 9090 — spring: profiles: prod application: name: demoservice server: port: 4431 To command to set development active profile is given below − You can see active profile name on the console log as shown below − 2017-11-26 08:41:37.202 INFO 14104 — [ main] com.tutorialspoint.demo.DemoApplication : The following profiles are active: dev Now, Tomcat started on the port 9090 (http) as shown below − 2017-11-26 08:41:46.650 INFO 14104 — [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9090 (http) The command to set Production active profile is given below − You can see active profile name on the console log as shown below − 2017-11-26 08:43:10.743 INFO 13400 — [ main] com.tutorialspoint.demo.DemoApplication : The following profiles are active: prod This will start Tomcat on the port 4431 (http) as shown below: 2017-11-26 08:43:14.473 INFO 13400 — [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 4431 (http) Print Page Previous Next

Spring MVC – Form Handling

Spring MVC – Form Handling Example ”; Previous Next The following example shows how to write a simple web based Hello World application using the Spring MVC Framework. To start with, let us have a working Eclipse IDE in place and follow the subsequent steps to develop a Dynamic Web Application using the Spring Web Framework. Step Description 1 Create a project with a name HelloWeb under a package com.tutorialspoint as explained in the Spring MVC – Hello World chapter. 2 Create Java classes Student, StudentController under the com.tutorialspoint package. 3 Create view files student.jsp, result.jsp under the jsp sub-folder. 4 The final step is to create the content of the source and configuration files and export the application as explained below. Student.java package com.tutorialspoint; public class Student { private Integer age; private String name; private Integer id; public void setAge(Integer age) { this.age = age; } public Integer getAge() { return age; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setId(Integer id) { this.id = id; } public Integer getId() { return id; } } StudentController.java package com.tutorialspoint; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.ui.ModelMap; @Controller public class StudentController { @RequestMapping(value = “/student”, method = RequestMethod.GET) public ModelAndView student() { return new ModelAndView(“student”, “command”, new Student()); } @RequestMapping(value = “/addStudent”, method = RequestMethod.POST) public String addStudent(@ModelAttribute(“SpringWeb”)Student student, ModelMap model) { model.addAttribute(“name”, student.getName()); model.addAttribute(“age”, student.getAge()); model.addAttribute(“id”, student.getId()); return “result”; } } Here, the first service method student(), we have passed a blank Studentobject in the ModelAndView object with name “command”. This is done because the spring framework expects an object with name “command”, if we use <form:form> tags in the JSP file. So, when the student() method is called, it returns student.jsp view. The second service method addStudent() will be called against a POST method on the HelloWeb/addStudent URL. You will prepare your model object based on the submitted information. Finally, a “result” view will be returned from the service method, which will result in rendering result.jsp. student.jsp <%@taglib uri=”http://www.springframework.org/tags/form” prefix = “form”%> <html> <head> <title>Spring MVC Form Handling</title> </head> <body> <h2>Student Information</h2> <form:form method = “POST” action = “/HelloWeb/addStudent”> <table> <tr> <td><form:label path = “name”>Name</form:label></td> <td><form:input path = “name” /></td> </tr> <tr> <td><form:label path = “age”>Age</form:label></td> <td><form:input path = “age” /></td> </tr> <tr> <td><form:label path = “id”>id</form:label></td> <td><form:input path = “id” /></td> </tr> <tr> <td colspan = “2”> <input type = “submit” value = “Submit”/> </td> </tr> </table> </form:form> </body> </html> result.jsp <%@taglib uri = “http://www.springframework.org/tags/form” prefix = “form”%> <html> <head> <title>Spring MVC Form Handling</title> </head> <body> <h2>Submitted Student Information</h2> <table> <tr> <td>Name</td> <td>${name}</td> </tr> <tr> <td>Age</td> <td>${age}</td> </tr> <tr> <td>ID</td> <td>${id}</td> </tr> </table> </body> </html> Once we are done with creating source and configuration files, export your application. Right click on your application, use Export → WAR File option and save the SpringWeb.war file in Tomcat”s webapps folder. Now, start the Tomcat server and make sure you are able to access other webpages from the webapps folder using a standard browser. Now, try a URL– http://localhost:8080/SpringWeb/student and you should see the following screen if everything is fine with the Spring Web Application. After submitting the required information, click on the submit button to submit the form. You should see the following screen, if everything is fine with your Spring Web Application. Print Page Previous Next Advertisements ”;

Spring Boot CLI – Using Shell

Spring Boot CLI – Using Shell ”; Previous Next Spring Boot CLI provides a Shell interface to run the commands in which we can directly run the commands as shown below. Go to E:Test folder and type the following command. E:/Test> spring shell You will see the following output. ←[1mSpring Boot←[m←[2m (v2.6.3)←[m Hit TAB to complete. Type ”help” and hit RETURN for help, and ”exit” to quit. $ Running commands in Shell. Type the following and see the output. version Spring CLI v2.6.3 You can press tab to auto complete the commands and type exit to finish the shell console. Testing the application in shell Type the following and see the output. $ exit E:TestFirstApplication> Print Page Previous Next Advertisements ”;

Spring Boot CLI – Starter Thymeleaf Project

Spring Boot CLI – Starter Thymeleaf Project ”; Previous Next Let”s create a sample Thymeleaf based project to demonstrate the capabilities of Spring CLI. Follow the below mentioned step to create a sample project. Step Description 1 Create a Folder with a name TestApplication with subfolders templates and static. 2 Create message.groovy in TestApplication folder, message.html in templates folder, index.html in static folder as explained below. 3 Compile and run the application to verify the result of the implemented logic. TestApplication/message.groovy @Controller @Grab(”spring-boot-starter-thymeleaf”) class MessageController { @RequestMapping(“/message”) String getMessage(Model model) { String message = “Welcome to TutorialsPoint.Com!”; model.addAttribute(“message”, message); return “message”; } } TestApplication/templates/message.html <!DOCTYPE HTML> <html xmlns:th=”http://www.thymeleaf.org”> <head> <title>Spring Boot CLI Example</title> <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ /> </head> <body> <p th:text=””Message: ” + ${message}” /> </body> </html> TestApplication/static/index.html <!DOCTYPE HTML> <html> <head> <title>Spring Boot CLI Example</title> <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ /> </head> <body> <p>Go to <a href=”/message”>Message</a></p> </body> </html> Run the application Type the following command E:/Test/TestApplication/> spring run *.groovy Now Spring Boot CLI will come into action, download required dependencies, run the embedded tomcat, deploy the application and start it. You can see the following output on console. . ____ _ __ _ _ /\ / ___”_ __ _ _(_)_ __ __ _ ( ( )___ | ”_ | ”_| | ”_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ” |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.6.3) 2022-02-03 11:36:33.362 INFO 10764 — [ runner-0] o.s.boot.SpringApplication : Starting application using Java 11.0.11 on DESKTOP-86KD9FC with PID 10764 (started by intel in E:TestTestApplication) 2022-02-03 11:36:33.372 INFO 10764 — [ runner-0] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default 2022-02-03 11:36:35.743 INFO 10764 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-02-03 11:36:35.768 INFO 10764 — [ runner-0] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-02-03 11:36:35.769 INFO 10764 — [ runner-0] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2022-02-03 11:36:35.829 INFO 10764 — [ runner-0] org.apache.catalina.loader.WebappLoader : Unknown class loader [org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@553a3d88] of class [class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader] 2022-02-03 11:36:35.896 INFO 10764 — [ runner-0] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-02-03 11:36:35.897 INFO 10764 — [ runner-0] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2085 ms 2022-02-03 11:36:36.436 INFO 10764 — [ runner-0] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html] 2022-02-03 11:36:37.132 INFO 10764 — [ runner-0] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ”” 2022-02-03 11:36:37.153 INFO 10764 — [ runner-0] o.s.boot.SpringApplication : Started application in 4.805 seconds (JVM running for 8.633) 2022-02-03 11:37:03.049 INFO 10764 — [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ”dispatcherServlet” 2022-02-03 11:37:03.049 INFO 10764 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ”dispatcherServlet” 2022-02-03 11:37:03.054 INFO 10764 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 3 ms Browse the application in Browser Our spring based rest application is now ready. Open url as “http://localhost:8080/” and you will see the following output. Go to Message Click on Message link and you will see the following output. Message: Welcome to TutorialsPoint.Com! Points to consider Following actions are taken by Spring CLI. @Grab(”spring-boot-starter-thymeleaf”) annotation directs CLI to download spring-boot-starter-thymeleaf 2.6.3 version. Spring CLI automatically detects the version using its metadata as we”ve not specified any group id or version id here. Finally it compiles the code, deploy the war on a embedded tomcat, start embedded tomcat server on the default port 8080. Print Page Previous Next Advertisements ”;