Remove old tag libs module
This commit is contained in:
parent
8e5586ca48
commit
afdb37eb02
|
@ -1,13 +0,0 @@
|
|||
*.class
|
||||
|
||||
#folders#
|
||||
/target
|
||||
/neoDb*
|
||||
/data
|
||||
/src/main/webapp/WEB-INF/classes
|
||||
*/META-INF/*
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
|
@ -1,76 +0,0 @@
|
|||
<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>
|
||||
|
||||
<artifactId>spring-boot-security-taglibs</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>spring-boot-security-taglibs</name>
|
||||
<description>spring 5 security sample project</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- security taglib -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-taglibs</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- JSTL -->
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-jasper</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test -->
|
||||
<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>
|
||||
<finalName>spring-5-security-taglibs</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -1,42 +0,0 @@
|
|||
package org.baeldung.security;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
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.configuration.WebSecurityConfigurerAdapter;
|
||||
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.provisioning.InMemoryUserDetailsManager;
|
||||
|
||||
@SpringBootApplication
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class ApplicationConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
// Using withDefaultPasswordEncoder and InMemoryUserDetailsManager for demonstration and testing purpose
|
||||
@Bean
|
||||
@Override
|
||||
public UserDetailsService userDetailsService() {
|
||||
UserDetails user = User.withDefaultPasswordEncoder()
|
||||
.username("testUser")
|
||||
.password("password")
|
||||
.roles("ADMIN")
|
||||
.build();
|
||||
|
||||
return new InMemoryUserDetailsManager(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
// @formatter:off
|
||||
http.csrf()
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/userManagement").hasRole("ADMIN")
|
||||
.anyRequest().permitAll().and().httpBasic();
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package org.baeldung.security;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class HomeController {
|
||||
|
||||
@RequestMapping
|
||||
public String home() {
|
||||
return "home";
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
#jsp config
|
||||
spring.mvc.view.prefix: /WEB-INF/views/
|
||||
spring.mvc.view.suffix: .jsp
|
|
@ -1,38 +0,0 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<%@ taglib prefix="sec"
|
||||
uri="http://www.springframework.org/security/tags"%>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<sec:csrfMetaTags />
|
||||
<title>Home Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<sec:authorize access="!isAuthenticated()">
|
||||
Login
|
||||
</sec:authorize>
|
||||
|
||||
<sec:authorize access="isAuthenticated()">
|
||||
Logout
|
||||
</sec:authorize>
|
||||
|
||||
<sec:authorize access="isAuthenticated()">
|
||||
<h2>
|
||||
Welcome back, <sec:authentication property="name" />
|
||||
</h2>
|
||||
<sec:authorize access="hasRole('ADMIN')">
|
||||
Manage Users
|
||||
</sec:authorize>
|
||||
<form method="post">
|
||||
<sec:csrfInput />
|
||||
Text Field: <br /> <input type="text" name="textField" />
|
||||
<input type="submit" value="Submit form with CSRF input">
|
||||
</form>
|
||||
<sec:authorize url="/userManagement">
|
||||
<a href="/userManagement">Manage Users</a>
|
||||
</sec:authorize>
|
||||
</sec:authorize>
|
||||
</body>
|
||||
</html>
|
|
@ -1,60 +0,0 @@
|
|||
package org.baeldung.security;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class HomeControllerTest {
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Test
|
||||
public void whenUserIsAuthenticatedThenAuthenticatedSectionsShowOnSite() throws Exception {
|
||||
String body = this.restTemplate.withBasicAuth("testUser", "password")
|
||||
.getForEntity("/", String.class)
|
||||
.getBody();
|
||||
|
||||
// test <sec:authorize access="!isAuthenticated()">
|
||||
assertFalse(body.contains("Login"));
|
||||
|
||||
// test <sec:authorize access="isAuthenticated()">
|
||||
assertTrue(body.contains("Logout"));
|
||||
|
||||
// test <sec:authorize access="hasRole('ADMIN')">
|
||||
assertTrue(body.contains("Manage Users"));
|
||||
|
||||
// test <sec:authentication property="principal.username" />
|
||||
assertTrue(body.contains("testUser"));
|
||||
|
||||
// test <sec:authorize url="/adminOnlyURL">
|
||||
assertTrue(body.contains("<a href=\"/userManagement\">"));
|
||||
|
||||
// test <sec:csrfInput />
|
||||
assertTrue(body.contains("<input type=\"hidden\" name=\"_csrf\" value=\""));
|
||||
|
||||
// test <sec:csrfMetaTags />
|
||||
assertTrue(body.contains("<meta name=\"_csrf_parameter\" content=\"_csrf\" />"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUserIsNotAuthenticatedThenOnlyAnonymousSectionsShowOnSite() throws Exception {
|
||||
String body = this.restTemplate.getForEntity("/", String.class)
|
||||
.getBody();
|
||||
|
||||
// test <sec:authorize access="!isAuthenticated()">
|
||||
assertTrue(body.contains("Login"));
|
||||
|
||||
// test <sec:authorize access="isAuthenticated()">
|
||||
assertFalse(body.contains("Logout"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue