spring-cookie-session

Implementation of SecurityContextRepository which allows to store authentication in cookie

License

License

GroupId

GroupId

com.oakfusion
ArtifactId

ArtifactId

spring-cookie-session
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

spring-cookie-session
Implementation of SecurityContextRepository which allows to store authentication in cookie

Download spring-cookie-session

How to add to project

<!-- https://jarcasting.com/artifacts/com.oakfusion/spring-cookie-session/ -->
<dependency>
    <groupId>com.oakfusion</groupId>
    <artifactId>spring-cookie-session</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.oakfusion/spring-cookie-session/
implementation 'com.oakfusion:spring-cookie-session:1.0'
// https://jarcasting.com/artifacts/com.oakfusion/spring-cookie-session/
implementation ("com.oakfusion:spring-cookie-session:1.0")
'com.oakfusion:spring-cookie-session:jar:1.0'
<dependency org="com.oakfusion" name="spring-cookie-session" rev="1.0">
  <artifact name="spring-cookie-session" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.oakfusion', module='spring-cookie-session', version='1.0')
)
libraryDependencies += "com.oakfusion" % "spring-cookie-session" % "1.0"
[com.oakfusion/spring-cookie-session "1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.springframework.security : spring-security-web jar 3.2.0.RELEASE
commons-codec : commons-codec jar 1.9

provided (1)

Group / Artifact Type Version
javax.servlet : javax.servlet-api jar 3.0.1

Project Modules

There are no modules declared in this project.

spring-cookie-session

##Maven At this stage 1.0-SNAPSHOT version is available, so you need to add Sonatype Nexus snapshot repository to your pom.xml:

<repositories>
	<repository>
		<id>sonatype-nexus-snapshots</id>
		<url>https://oss.sonatype.org/content/repositories/snapshots</url>
	</repository>
</repositories>

and then dependency:

<dependency>
	<groupId>com.oakfusion</groupId>
	<artifactId>spring-cookie-session</artifactId>
	<version>1.0-SNAPSHOT</version>
</dependency>

##Example Java configuration

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.*;
import org.springframework.security.config.annotation.authentication.builders.*;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.*;
import org.springframework.security.web.context.SecurityContextRepository;
import org.springframework.security.web.savedrequest.NullRequestCache;
import com.oakfusion.security.CookieSecurityContextRepository;
import com.oakfusion.security.SecurityCookieService;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

	@Autowired
	public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
		auth
			.inMemoryAuthentication()
			.withUser("user").password("password").roles("USER");
	}

	@Bean
	public static SecurityContextRepository securityContextRepository() {
		return new CookieSecurityContextRepository(securityCookieService());
	}

	private static SecurityCookieService securityCookieService() {
		return new SecurityCookieService("spring-cookie-session", "jmccu2j73983kjiw88");
	}

	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http
			.csrf().disable().
			requestCache().disable()
			.securityContext()
				.securityContextRepository(securityContextRepository())
			.and()
				.requestCache().requestCache(new NullRequestCache())
			.and()
				.formLogin()
			.and()
				.authorizeRequests()
				.anyRequest().authenticated();
	}
}

Versions

Version
1.0