[JAVA] [Spring Security] Spring Security on GAE (SE)

Introduction

Note that I ran Spring Security on GAE (SE)

environment

eclipse maven

full pom.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>
	<packaging>war</packaging>
	<version>0.1.0-SNAPSHOT</version>

	<groupId>trial-nino</groupId>
	<artifactId>spring-mvc01-springsecurity-gae-se</artifactId>

	<prerequisites>
		<maven>3.5</maven>
	</prerequisites>

	<properties>
		<appengine.maven.plugin.version>1.3.2</appengine.maven.plugin.version>
		<appengine.api.sdk.version>1.9.71</appengine.api.sdk.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
	</properties>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.1.RELEASE</version>
		<relativePath />
	</parent>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>com.google.cloud</groupId>
				<artifactId>google-cloud-bom</artifactId>
				<version>0.78.0-alpha</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<dependencies>

		<!-- Compile/runtime dependencies -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<!-- version>3.1.0</version -->
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>javax.servlet.jsp-api</artifactId>
			<version>2.3.1</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
		<dependency>
			<groupId>com.google.appengine</groupId>
			<artifactId>appengine-api-1.0-sdk</artifactId>
			<!-- version>1.9.71</version -->
		</dependency>

		<!-- spring boot -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-tomcat</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<dependency>
			<groupId>nz.net.ultraq.thymeleaf</groupId>
			<artifactId>thymeleaf-layout-dialect</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>

		<!-- java library -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<!-- version>1.18.4</version -->
			<scope>provided</scope>
		</dependency>

		<!-- logger -->
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
			<!-- version>1.2.3</version -->
		</dependency>

		<!-- Test Dependencies -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<!-- version>4.12</version -->
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<!-- for hot reload of the web application -->
		<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
		<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
		<resources>
			<resource>
				<directory>${project.basedir}/src/main/resources</directory>
			</resource>
		</resources>
		<testResources>
			<testResource>
				<directory>src/test/resources</directory>
				<includes>
					<include>**/*.properties</include>
				</includes>
			</testResource>
		</testResources>


		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>versions-maven-plugin</artifactId>
				<!-- version>2.3</version -->
				<executions>
					<execution>
						<phase>compile</phase>
						<goals>
							<goal>display-dependency-updates</goal>
							<goal>display-plugin-updates</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
					<webResources>
						<!-- in order to interpolate version from pom into appengine-web.xml -->
						<resource>
							<directory>${basedir}/src/main/webapp/WEB-INF</directory>
							<filtering>true</filtering>
							<targetPath>WEB-INF</targetPath>
						</resource>
					</webResources>
				</configuration>
			</plugin>

			<plugin>
				<groupId>com.google.cloud.tools</groupId>
				<artifactId>appengine-maven-plugin</artifactId>
				<version>${appengine.maven.plugin.version}</version>
				<configuration>
					<deploy.promote>true</deploy.promote>
					<deploy.stopPreviousVersion>true</deploy.stopPreviousVersion>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>

		</plugins>
	</build>
</project>

procedure

Other

If you do not use Spring Security Static files (css, javascript, etc.) could not be read unless a directory was prepared directly under webapp, If you use SpringSecurity and specify it in SecurityConfig, you can read static files under WEB-INF.

that's all

Recommended Posts

[Spring Security] Spring Security on GAE (SE)
gae + spring boot
About Spring Security authentication
Spring Security causes 403 forbidden
Spring Boot on Microsoft Azure
Spring Security usage memo CSRF
On passing Java Gold SE 8
Spring Security usage memo Run-As
Spring Security Usage memo Method security
Spring Security usage memo Remember-Me
Login function with Spring Security
Try using Spring Boot Security
Try Spring Boot on Mac
Spring Security usage memo CORS
Spring Security usage memo test
Spring Security usage memo Authentication / authorization
gRPC on Spring Boot with grpc-spring-boot-starter
Implemented authentication function with Spring Security ③
Spring Boot Tutorial Using Spring Security Authentication
Spring Security usage memo response header
Implemented authentication function with Spring Security ①
Learn Spring Security authentication processing architecture
Spring Security usage memo session management
Try running Spring Boot on Kubernetes
Spring Security usage memo Basic / mechanism
Authentication / authorization with Spring Security & Thymeleaf