Skip to content

Commit dc78aac

Browse files
SeunMattzhendrikse
authored andcommitted
BAEL-884 Spring Security in JEE App (eugenp#2362)
* added updated example codes * updated example code StringToCharStream * deleted StringToCharStream.java locally * removed redundant file * added code for apache commons collection SetUtils * refactored example code * added example code for bytebuddy * added example code for PCollections * update pom * refactored tests for PCollections * spring security xml config * spring security xml config
1 parent 71f1a2b commit dc78aac

6 files changed

Lines changed: 100 additions & 0 deletions

File tree

‎jee7/.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
/classes/
3+
/.idea/
4+
/target/
5+
/jee7.iml

‎jee7/pom.xml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
<groupId>com.baeldung</groupId>
77
<artifactId>jee7</artifactId>
88
<version>1.0-SNAPSHOT</version>
9+
<packaging>war</packaging>
910
<description>JavaEE 7 Arquillian Archetype Sample</description>
1011

12+
1113
<parent>
1214
<groupId>com.baeldung</groupId>
1315
<artifactId>parent-modules</artifactId>
@@ -174,6 +176,7 @@
174176
<artifactId>maven-war-plugin</artifactId>
175177
<version>${maven-war-plugin.version}</version>
176178
<configuration>
179+
<warSourceDirectory>webapp</warSourceDirectory>
177180
<failOnMissingWebXml>false</failOnMissingWebXml>
178181
</configuration>
179182
</plugin>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<b:beans xmlns="http://www.springframework.org/schema/security"
3+
xmlns:b="http://www.springframework.org/schema/beans"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
6+
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
7+
8+
<authentication-manager>
9+
<authentication-provider>
10+
<user-service>
11+
<user name="user" password="user123" authorities="ROLE_USER" />
12+
</user-service>
13+
</authentication-provider>
14+
</authentication-manager>
15+
16+
<http auto-config='true' use-expressions="true">
17+
<form-login default-target-url="/secure.jsp" />
18+
<intercept-url pattern="/" access="isAnonymous()" />
19+
<intercept-url pattern="/index.jsp" access="isAnonymous()" />
20+
<intercept-url pattern="/secure.jsp" access="hasRole('ROLE_USER')" />
21+
</http>
22+
23+
</b:beans>

‎jee7/src/main/webapp/WEB-INF/web.xml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,33 @@
3232
<!-- If you go to http://host/project/ (with no file name), it will
3333
try index.jsf first, welcome.jsf next, and so forth.
3434
-->
35+
36+
37+
<!-- UNCOMMENT THE FOLLOWING SECTION FOR SPRING SECURITY XML CONFIGURATION-->
38+
39+
<!--<context-param>-->
40+
<!--<param-name>contextConfigLocation</param-name>-->
41+
<!--<param-value>-->
42+
<!--/WEB-INF/spring/*.xml-->
43+
<!--</param-value>-->
44+
<!--</context-param>-->
45+
46+
<!--<filter>-->
47+
<!--<filter-name>springSecurityFilterChain</filter-name>-->
48+
<!--<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>-->
49+
<!--</filter>-->
50+
51+
<!--<filter-mapping>-->
52+
<!--<filter-name>springSecurityFilterChain</filter-name>-->
53+
<!--<url-pattern>/*</url-pattern>-->
54+
<!--</filter-mapping>-->
55+
56+
<!--<listener>-->
57+
<!--<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>-->
58+
<!--</listener>-->
59+
60+
<!-- END SPRING SECURITY XML CONFIGURATION-->
61+
3562
<welcome-file-list>
3663
<welcome-file>index.jsf</welcome-file>
3764
<welcome-file>welcome.jsf</welcome-file>

‎jee7/src/main/webapp/index.jsp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<%--
2+
Created by IntelliJ IDEA.
3+
User: smatt
4+
Date: 02/08/2017
5+
Time: 07:03 AM
6+
To change this template use File | Settings | File Templates.
7+
--%>
8+
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
9+
<html>
10+
<head>
11+
<title>Index Page</title>
12+
</head>
13+
<body>
14+
Non-secured Index Page
15+
<br>
16+
<a href="/login">Login</a>
17+
</body>
18+
</html>

‎jee7/src/main/webapp/secure.jsp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
3+
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
4+
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %>
5+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
6+
<html>
7+
<head>
8+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9+
<title>Home Page</title>
10+
</head>
11+
<body>
12+
<h3>Home Page</h3>
13+
14+
<p>
15+
Hello <b><c:out value="${pageContext.request.remoteUser}"/></b><br>
16+
Roles: <b><sec:authentication property="principal.authorities" /></b>
17+
</p>
18+
19+
<form action="logout" method="post">
20+
<input type="submit" value="Logout" />
21+
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
22+
</form>
23+
</body>
24+
</html>

0 commit comments

Comments
 (0)