Skip to content

Commit 21cbc2b

Browse files
author
Eugen
committed
Merge pull request eugenp#33 from egmp777/master
Login and Registration Error Handling pom changes
2 parents a9c3c08 + b27187d commit 21cbc2b

File tree

16 files changed

+352
-0
lines changed

16 files changed

+352
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beansProjectDescription>
3+
<version>1</version>
4+
<pluginVersion><![CDATA[3.5.1.201404300732-RELEASE]]></pluginVersion>
5+
<configSuffixes>
6+
<configSuffix><![CDATA[xml]]></configSuffix>
7+
</configSuffixes>
8+
<enableImports><![CDATA[true]]></enableImports>
9+
<configs>
10+
</configs>
11+
<autoconfigs>
12+
</autoconfigs>
13+
<configSets>
14+
</configSets>
15+
</beansProjectDescription>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<configuration>
2+
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<logger name="org.springframework" level="WARN" />
11+
<logger name="org.springframework.transaction" level="WARN" />
12+
13+
<!-- in order to debug some marshalling issues, this needs to be TRACE -->
14+
<logger name="org.springframework.web.servlet.mvc" level="WARN" />
15+
16+
<root level="INFO">
17+
<appender-ref ref="STDOUT" />
18+
</root>
19+
20+
</configuration>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
message.username=Username required
2+
message.password=Password required
3+
message.unauth=Unauthorized Access !!
4+
message.badCredentials=Invalid Username or Password
5+
message.sessionExpired=Session Timed Out
6+
message.logoutError=Sorry, error logging out
7+
message.logoutSucc=You logged out successfully
8+
message.regSucc=You registrated correctly, please log in
9+
message.regError=There was a registration error please go back to registration
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
message.username=Por favor ingrese el nombre de usuario
2+
message.password=Por favor ingrese una clave
3+
message.unauth=Acceso denegado !!
4+
message.badCredentials=Usuario o clave invalida
5+
message.sessionExpired=La sesion expiro
6+
message.logoutError=Lo sentimos, hubo problemas en logout
7+
message.logoutSucc=Logout con exito
8+
message.regSucc=Se registro correctamente, por favor ingrese
9+
message.regError=Hubo un error, por favor vuelva a registrarse
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans:beans xmlns="http://www.springframework.org/schema/security"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
4+
xmlns:mvc="http://www.springframework.org/schema/mvc"
5+
xsi:schemaLocation="
6+
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
7+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
8+
9+
10+
<http use-expressions="true">
11+
<intercept-url pattern="/login*" access="permitAll" />
12+
<intercept-url pattern="/logout*" access="permitAll" />
13+
<intercept-url pattern="/registration*" access="permitAll" />
14+
<intercept-url pattern="/resources/**" access="permitAll" />
15+
<intercept-url pattern="/invalidSession*" access="isAnonymous()" />
16+
<intercept-url pattern="/**" access="isAuthenticated()" />
17+
<form-login login-page='/login.html'
18+
authentication-failure-url="/login.html?error=true"
19+
authentication-success-handler-ref="myAuthenticationSuccessHandler"
20+
default-target-url="/homepage.html" />
21+
<session-management invalid-session-url="/invalidSession.html"
22+
session-fixation-protection="none" />
23+
<logout invalidate-session="false" logout-success-url="/logout.html?logSucc=1"
24+
logout-url="/j_spring_security_logout" delete-cookies="JSESSIONID" />
25+
</http>
26+
<beans:bean id="myAuthenticationSuccessHandler"
27+
class="org.baeldung.security.MySimpleUrlAuthenticationSuccessHandler" />
28+
<authentication-manager>
29+
<authentication-provider>
30+
<user-service>
31+
<user name="user1" password="user1Pass" authorities="ROLE_USER" />
32+
<user name="admin1" password="admin1Pass" authorities="ROLE_ADMIN" />
33+
</user-service>
34+
</authentication-provider>
35+
</authentication-manager>
36+
</beans:beans>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:p="http://www.springframework.org/schema/p"
4+
xmlns:mvc="http://www.springframework.org/schema/mvc"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
6+
7+
8+
9+
10+
</beans>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2+
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
3+
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
4+
<html>
5+
<sec:authorize ifAnyGranted="ROLE_USER">
6+
<spring:message code="message.unauth" ></spring:message>
7+
</sec:authorize>
8+
<head></head>
9+
10+
11+
<body>
12+
13+
<head></head>
14+
<sec:authorize ifAnyGranted="ROLE_ADMIN">
15+
<H1> Hello Admin</H1>
16+
</sec:authorize>
17+
18+
<a href="<c:url value="/j_spring_security_logout" />">Logout</a>
19+
<a href="<c:url value="/home.html" />">Home</a>
20+
</body>
21+
22+
23+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2+
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
3+
<html>
4+
<head></head>
5+
6+
<body>
7+
<h1>This is the landing page for the admin</h1>
8+
9+
<security:authorize access="hasRole('ROLE_USER')">
10+
This text is only visible to a user
11+
<br/>
12+
</security:authorize>
13+
14+
<security:authorize access="hasRole('ROLE_ADMIN')">
15+
This text is only visible to an admin
16+
<br/>
17+
</security:authorize>
18+
19+
<a href="<c:url value="/j_spring_security_logout" />">Logout</a>
20+
<a href="<c:url value="/admin.html" />">Administrator Page</a>
21+
22+
</body>
23+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
2+
<%@ page session="true" %>
3+
<html>
4+
<head>
5+
<title>Home</title>
6+
</head>
7+
<body>
8+
<h1>
9+
Welcome back home!
10+
</h1>
11+
12+
</body>
13+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2+
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
3+
<%@ page session="true" %>
4+
<html>
5+
<head></head>
6+
7+
<body>
8+
<body>
9+
<h1>This is the homepage for the user</h1>
10+
11+
<sec:authorize access="hasRole('ROLE_USER')">
12+
This text is only visible to a user
13+
<br />
14+
</sec:authorize>
15+
16+
<sec:authorize access="hasRole('ROLE_ADMIN')">
17+
This text is only visible to an admin
18+
<br />
19+
</sec:authorize>
20+
21+
<a href="<c:url value="/j_spring_security_logout" />">Logout</a>
22+
<a href="<c:url value="/home.html" />">Home</a>
23+
<a href="<c:url value="/admin.html" />">Administrator Page</a>
24+
25+
</body>
26+
27+
</body>
28+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
2+
<html>
3+
<head>
4+
<title>Home</title>
5+
</head>
6+
<body>
7+
<h1>
8+
<spring:message code="message.sessionExpired" ></spring:message>
9+
</h1>
10+
11+
</body>
12+
</html>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2+
<%@ taglib prefix="sec"
3+
uri="http://www.springframework.org/security/tags"%>
4+
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
5+
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
6+
<fmt:setBundle basename="messages" />
7+
<%@ page session="false"%>
8+
<c:if test="${param.error != null}">
9+
<div id="error">
10+
<spring:message code="message.badCredentials"></spring:message>
11+
</div>
12+
</c:if>
13+
<c:if test="${param.regSucc == 1}">
14+
<div id="error">
15+
<spring:message code="message.regSucc"></spring:message>
16+
</div>
17+
</c:if>
18+
<c:if test="${param.regError == 1}">
19+
20+
<div id="error">
21+
<spring:message code="message.regError"></spring:message>
22+
</div>
23+
<a href="registration.html">Register</a>
24+
</c:if>
25+
<fmt:message key="message.password" var="noPass" />
26+
<fmt:message key="message.username" var="noUser" />
27+
<html>
28+
<head>
29+
30+
<script type="text/javascript">
31+
function validate() {
32+
if (document.f.j_username.value == ""
33+
&& document.f.j_password.value == "") {
34+
alert("${noUser} & ${noPass}");
35+
document.f.j_username.focus();
36+
return false;
37+
}
38+
if (document.f.j_username.value == "") {
39+
alert("${noUser}");
40+
document.f.j_username.focus();
41+
return false;
42+
}
43+
44+
if (document.f.j_password.value == "") {
45+
alert("${noPass}");
46+
document.f.j_password.focus();
47+
return false;
48+
}
49+
}
50+
</script>
51+
</head>
52+
53+
<body>
54+
<h1>Login</h1>
55+
<a href="?lang=en">English</a> |
56+
<a href="?lang=es_ES">Spanish</a>
57+
<form name='f' action="j_spring_security_check" method='POST'
58+
onsubmit="return validate();">
59+
60+
<table>
61+
<tr>
62+
<td>User:</td>
63+
<td><input type='text' name='j_username' value=''></td>
64+
</tr>
65+
<tr>
66+
<td>Password:</td>
67+
<td><input type='password' name='j_password' /></td>
68+
</tr>
69+
<tr>
70+
<td><input name="submit" type="submit" value="submit" /></td>
71+
</tr>
72+
</table>
73+
74+
</form>
75+
<br> Current Locale : ${pageContext.response.locale}
76+
</body>
77+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
2+
<%@ taglib prefix="sec"
3+
uri="http://www.springframework.org/security/tags"%>
4+
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
5+
<c:if test="${not empty SPRING_SECURITY_LAST_EXCEPTION}">
6+
<div id="error">
7+
<spring:message code="message.logoutError"></spring:message>
8+
</div>
9+
</c:if>
10+
<c:if test="${param.logSucc == 1}">
11+
<div id="success">
12+
<spring:message code="message.logoutSucc"></spring:message>
13+
</div>
14+
</c:if>
15+
<html>
16+
<head>
17+
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
18+
<title>Logged Out</title>
19+
</head>
20+
<body>
21+
22+
<a href="login.html">Login</a>
23+
</body>
24+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<%@ page language="java" contentType="text/html; charset=US-ASCII"
2+
pageEncoding="US-ASCII"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
7+
<title>Registration</title>
8+
</head>
9+
<body>
10+
<H1> This is the registration page</H1>
11+
</body>
12+
</html>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
3+
<context-param>
4+
<param-name>contextClass</param-name>
5+
<param-value>
6+
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
7+
</param-value>
8+
</context-param>
9+
<context-param>
10+
<param-name>contextConfigLocation</param-name>
11+
<param-value>org.baeldung.spring</param-value>
12+
</context-param>
13+
<listener>
14+
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
15+
</listener>
16+
<servlet>
17+
<servlet-name>mvc</servlet-name>
18+
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
19+
<load-on-startup>1</load-on-startup>
20+
</servlet>
21+
<servlet-mapping>
22+
<servlet-name>mvc</servlet-name>
23+
<url-pattern>/</url-pattern>
24+
</servlet-mapping>
25+
<filter>
26+
<filter-name>springSecurityFilterChain</filter-name>
27+
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
28+
</filter>
29+
<filter-mapping>
30+
<filter-name>springSecurityFilterChain</filter-name>
31+
<url-pattern>/*</url-pattern>
32+
</filter-mapping>
33+
<filter>
34+
<filter-name>localizationFilter</filter-name>
35+
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
36+
</filter>
37+
<filter-mapping>
38+
<filter-name>localizationFilter</filter-name>
39+
<url-pattern>/*</url-pattern>
40+
</filter-mapping>
41+
</web-app>

0 commit comments

Comments
 (0)