Merge pull request #181 from Doha2012/master

add password validator and change password
This commit is contained in:
Eugen 2015-04-01 22:38:37 +03:00
commit deac7873f0
30 changed files with 493 additions and 256 deletions

View File

@ -67,6 +67,14 @@
<scope>test</scope>
</dependency>
<!-- Password Validation -->
<dependency>
<groupId>org.passay</groupId>
<artifactId>passay</artifactId>
<version>1.0</version>
</dependency>
<!-- Spring Data JPA dependencies -->
<dependency>
<groupId>org.springframework.data</groupId>

View File

@ -32,4 +32,6 @@ public interface IUserService {
User getUserByID(long id);
void changeUserPassword(User user, String password);
boolean checkIfValidOldPassword(User user, String password);
}

View File

@ -1,32 +1,32 @@
package org.baeldung.persistence.service;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.baeldung.validation.PasswordMatches;
import org.baeldung.validation.ValidEmail;
import org.hibernate.validator.constraints.NotEmpty;
import org.baeldung.validation.ValidPassword;
@PasswordMatches
public class UserDto {
@NotNull
@NotEmpty
@Size(min = 1)
private String firstName;
@NotNull
@NotEmpty
@Size(min = 1)
private String lastName;
@NotNull
@NotEmpty
@ValidPassword
private String password;
@NotNull
@NotEmpty
@Size(min = 1)
private String matchingPassword;
@ValidEmail
@NotNull
@NotEmpty
@Size(min = 1)
private String email;
public String getEmail() {

View File

@ -120,6 +120,11 @@ public class UserService implements IUserService {
repository.save(user);
}
@Override
public boolean checkIfValidOldPassword(final User user, final String oldPassword) {
return passwordEncoder.matches(oldPassword, user.getPassword());
}
private boolean emailExist(final String email) {
final User user = repository.findByEmail(email);
if (user != null) {

View File

@ -14,6 +14,8 @@ public class AuthenticationFailureListener implements ApplicationListener<Authen
public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent e) {
WebAuthenticationDetails auth = (WebAuthenticationDetails) e.getAuthentication().getDetails();
loginAttemptService.loginFailed(auth.getRemoteAddress());
if (auth != null) {
loginAttemptService.loginFailed(auth.getRemoteAddress());
}
}
}

View File

@ -14,6 +14,8 @@ public class AuthenticationSuccessEventListener implements ApplicationListener<A
public void onApplicationEvent(AuthenticationSuccessEvent e) {
WebAuthenticationDetails auth = (WebAuthenticationDetails) e.getAuthentication().getDetails();
loginAttemptService.loginSucceeded(auth.getRemoteAddress());
if (auth != null) {
loginAttemptService.loginSucceeded(auth.getRemoteAddress());
}
}
}

View File

@ -49,6 +49,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
registry.addViewController("/successRegister.html");
registry.addViewController("/forgetPassword.html");
registry.addViewController("/updatePassword.html");
registry.addViewController("/changePassword.html");
}
@Override

View File

@ -0,0 +1,38 @@
package org.baeldung.validation;
import java.util.Arrays;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import org.passay.DigitCharacterRule;
import org.passay.LengthRule;
import org.passay.PasswordData;
import org.passay.PasswordValidator;
import org.passay.RuleResult;
import org.passay.SpecialCharacterRule;
import org.passay.UppercaseCharacterRule;
import org.passay.WhitespaceRule;
import com.google.common.base.Joiner;
public class PasswordConstraintValidator implements ConstraintValidator<ValidPassword, String> {
@Override
public void initialize(final ValidPassword arg0) {
}
@Override
public boolean isValid(final String password, final ConstraintValidatorContext context) {
final PasswordValidator validator = new PasswordValidator(Arrays.asList(new LengthRule(8, 30), new UppercaseCharacterRule(1), new DigitCharacterRule(1), new SpecialCharacterRule(1), new WhitespaceRule()));
final RuleResult result = validator.validate(new PasswordData(password));
if (result.isValid()) {
return true;
}
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(Joiner.on("\n").join(validator.getMessages(result))).addConstraintViolation();
return false;
}
}

View File

@ -0,0 +1,27 @@
package org.baeldung.validation;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
@Documented
@Constraint(validatedBy = PasswordConstraintValidator.class)
@Target({ TYPE, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
public @interface ValidPassword {
String message() default "Invalid Password";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}

View File

@ -14,6 +14,7 @@ import org.baeldung.persistence.service.IUserService;
import org.baeldung.persistence.service.UserDto;
import org.baeldung.registration.OnRegistrationCompleteEvent;
import org.baeldung.validation.EmailExistsException;
import org.baeldung.web.error.InvalidOldPasswordException;
import org.baeldung.web.error.UserAlreadyExistException;
import org.baeldung.web.error.UserNotFoundException;
import org.baeldung.web.util.GenericResponse;
@ -133,7 +134,6 @@ public class RegistrationController {
final String appUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
final SimpleMailMessage email = constructResetTokenEmail(appUrl, request.getLocale(), token, user);
mailSender.send(email);
return new GenericResponse(messages.getMessage("message.resetPasswordEmail", null, request.getLocale()));
}
@ -168,6 +168,19 @@ public class RegistrationController {
return new GenericResponse(messages.getMessage("message.resetPasswordSuc", null, locale));
}
// change user password
@RequestMapping(value = "/user/updatePassword", method = RequestMethod.POST)
@ResponseBody
public GenericResponse changeUserPassword(final Locale locale, @RequestParam("password") final String password, @RequestParam("oldpassword") final String oldPassword) {
final User user = userService.findUserByEmail(SecurityContextHolder.getContext().getAuthentication().getName());
if (!userService.checkIfValidOldPassword(user, oldPassword)) {
throw new InvalidOldPasswordException();
}
userService.changeUserPassword(user, password);
return new GenericResponse(messages.getMessage("message.updatePasswordSuc", null, locale));
}
// NON-API
private final SimpleMailMessage constructResendVerificationTokenEmail(final String contextPath, final Locale locale, final VerificationToken newToken, final User user) {

View File

@ -0,0 +1,23 @@
package org.baeldung.web.error;
public final class InvalidOldPasswordException extends RuntimeException {
private static final long serialVersionUID = 5861310537366287163L;
public InvalidOldPasswordException() {
super();
}
public InvalidOldPasswordException(final String message, final Throwable cause) {
super(message, cause);
}
public InvalidOldPasswordException(final String message) {
super(message);
}
public InvalidOldPasswordException(final Throwable cause) {
super(cause);
}
}

View File

@ -29,7 +29,7 @@ public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionH
// 400
@Override
protected ResponseEntity<Object> handleBindException(BindException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
protected ResponseEntity<Object> handleBindException(final BindException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.error("400 Status Code", ex);
final BindingResult result = ex.getBindingResult();
final GenericResponse bodyOfResponse = new GenericResponse(result.getFieldErrors(), result.getGlobalErrors());
@ -44,6 +44,13 @@ public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionH
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
}
@ExceptionHandler({ InvalidOldPasswordException.class })
public ResponseEntity<Object> handleInvalidOldPassword(final RuntimeException ex, final WebRequest request) {
logger.error("400 Status Code", ex);
final GenericResponse bodyOfResponse = new GenericResponse(messages.getMessage("message.invalidOldPassword", null, request.getLocale()), "InvalidOldEmail");
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
}
// 404
@ExceptionHandler({ UserNotFoundException.class })
public ResponseEntity<Object> handleUserNotFound(final RuntimeException ex, final WebRequest request) {

View File

@ -64,4 +64,9 @@ message.accountVerified=Your account verified successfully
message.resetPasswordSuc=Password reset successfully
message.resetYourPassword=Reset your password
message.resetPasswordEmail=You should receive an Password Reset Email shortly
message.error=Error Occurred
message.error=Error Occurred
message.updatePasswordSuc=Password updated successfully
message.changePassword=Change Password
message.invalidOldPassword=Invalid Old Password
label.user.newPassword=New Password
label.user.oldPassword=Old Password

View File

@ -64,4 +64,9 @@ message.accountVerified=Su cuenta verificada con
message.resetPasswordSuc=Contraseña reajusta correctamente
message.resetYourPassword=Restablecer su contraseña
message.resetPasswordEmail=Te enviaremos un correo electrónico para restablecer su contraseña
message.error=Se produjo un error
message.error=Se produjo un error
message.updatePasswordSuc=Contraseña actualizado correctamente
message.changePassword=Cambiar La Contraseña
message.invalidOldPassword=Inválida contraseña antigua
label.user.newPassword=Nueva Contraseña
label.user.oldPassword=Contraseña Anterior

View File

@ -1,29 +1,34 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
uri="http://www.springframework.org/security/tags"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title><spring:message code="label.pages.home.title"></spring:message></title>
</head>
<body>
<div class="container">
<div class="span12">
<sec:authorize ifNotGranted="WRITE_PRIVILEGE">
<spring:message code="message.unauth"></spring:message>
</sec:authorize>
<sec:authorize ifAnyGranted="WRITE_PRIVILEGE">
<H1>
<spring:message code="label.pages.admin.message"></spring:message>
</H1>
</sec:authorize>
<a href="<c:url value="/j_spring_security_logout" />"><spring:message
code="label.pages.logout"></spring:message></a> <a
href="<c:url value="/home.html" />"><spring:message
code="label.pages.home.title"></spring:message></a>
</div>
</div>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand"href="<c:url value="/home.html" />"><spring:message code="label.pages.home.title"></spring:message></a>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="<c:url value="/j_spring_security_logout" />"><spring:message code="label.pages.logout"></spring:message></a> </li>
</ul>
</div>
</nav>
<div class="container">
<sec:authorize ifNotGranted="WRITE_PRIVILEGE">
<spring:message code="message.unauth"></spring:message>
</sec:authorize>
<sec:authorize ifAnyGranted="WRITE_PRIVILEGE">
<h1>
<spring:message code="label.pages.admin.message"></spring:message>
</h1>
</sec:authorize>
</div>
</body>
</html>
</html>

View File

@ -1,38 +1,37 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
uri="http://www.springframework.org/security/tags"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<fmt:setBundle basename="messages" />
<%@ page session="true"%>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<title><spring:message
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title><spring:message
code="label.badUser.title"></spring:message></title>
</head>
<body>
<h1>
<div class="alert alert-error">
${param.message}
<div class="container">
<h1 class="alert alert-danger">
${param.message}
</h1>
<br>
<a href="<c:url value="/registration.html" />"><spring:message
<a class="btn btn-default" href="<c:url value="/registration.html" />"><spring:message
code="label.form.loginSignUp"></spring:message></a>
<c:if test="${param.expired}">
<br>
<h1>${label.form.resendRegistrationToken}</h1>
<button onclick="resendToken()">
<spring:message code="label.form.resendRegistrationToken"></spring:message>
<spring:message code="label.form.resendRegistrationToken"></spring:message>
</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function resendToken(){
$.get("<c:url value="/user/resendRegistrationToken"><c:param name="token" value="${param.token}"/></c:url>", function(data){
window.location.href = "<c:url value="/login.html"></c:url>" + "?message=" + data.message;
$.get("<c:url value="/user/resendRegistrationToken"><c:param name="token" value="${param.token}"/></c:url>", function(data){
window.location.href = "<c:url value="/login.html"></c:url>" + "?message=" + data.message;
})
.fail(function(data) {
if(data.responseJSON.error.indexOf("MailError") > -1)
@ -50,5 +49,6 @@ $(document).ajaxStart(function() {
});
</script>
</c:if>
</div>
</body>
</html>

View File

@ -0,0 +1,72 @@
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
<%@ page session="false"%>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title><spring:message code="message.changePassword"></spring:message></title>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand"href="#"><spring:message code="label.pages.home.title"></spring:message></a>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="<c:url value="/j_spring_security_logout" />"><spring:message code="label.pages.logout"></spring:message></a> </li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<div id="errormsg" class="alert alert-danger" style="display:none"></div>
<h1> <spring:message code="message.changePassword"></spring:message> </h1>
<div >
<br>
<label class="col-sm-2"><spring:message code="label.user.oldPassword"></spring:message></label>
<span class="col-sm-5"><input class="form-control" id="oldpass" name="oldpassword" type="password" value="" /></span>
<span class="col-sm-5"></span>
<br><br>
<label class="col-sm-2"><spring:message code="label.user.newPassword"></spring:message></label>
<span class="col-sm-5"><input class="form-control" id="pass" name="password" type="password" value="" /></span>
<span class="col-sm-5"></span>
<br><br>
<label class="col-sm-2"><spring:message code="label.user.confirmPass"></spring:message></label>
<span class="col-sm-5"><input class="form-control" id="passConfirm" type="password" value="" /></span>
<span id="error" class="alert alert-danger" style="display:none"><spring:message code="PasswordMatches.user"></spring:message></span>
<br><br>
<button class="btn btn-primary" type="submit" onclick="savePass()">
<spring:message code="message.changePassword"></spring:message>
</button>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function savePass(){
var pass = $("#pass").val();
var valid = pass == $("#passConfirm").val();
if(!valid) {
$("#error").show();
return;
}
$.post("<c:url value="/user/updatePassword"></c:url>",{password: pass, oldpassword: $("#oldpass").val()} ,function(data){
window.location.href = "<c:url value="/console.html"></c:url>" + "?message="+data.message;
})
.fail(function(data) {
$("#errormsg").show().html(data.responseJSON.message);
});
}
</script>
</body>
</html>

View File

@ -1,29 +1,42 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
uri="http://www.springframework.org/security/tags"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="span12">
<h1>This is the landing page for the admin</h1>
<sec:authorize access="hasRole('READ_PRIVILEGE')">
This text is only visible to a user
<br />
</sec:authorize>
<sec:authorize access="hasRole('WRITE_PRIVILEGE')">
This text is only visible to an admin
<br />
</sec:authorize>
<a href="<c:url value="/j_spring_security_logout" />"><spring:message
code="label.pages.logout"></spring:message></a> <a
href="<c:url value="/admin.html" />"><spring:message
code="label.pages.admin"></spring:message></a>
</div>
</div>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand"href="<c:url value="/home.html" />"><spring:message code="label.pages.home.title"></spring:message></a>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="<c:url value="/j_spring_security_logout" />"><spring:message code="label.pages.logout"></spring:message></a> </li>
</ul>
</div>
</nav>
<div class="container">
<c:if test="${param.message != null}">
<div class="alert alert-info">
${param.message}
</div>
</c:if>
<h1>This is the landing page for the admin</h1>
<sec:authorize access="hasRole('READ_PRIVILEGE')">
This text is only visible to a user
<br />
</sec:authorize>
<sec:authorize access="hasRole('WRITE_PRIVILEGE')">
This text is only visible to an admin
<br />
</sec:authorize>
<a class="btn btn-default" href="<c:url value="/changePassword.html" />"><spring:message code="message.changePassword"></spring:message></a>
<a class="btn btn-default" href="<c:url value="/admin.html" />"><spring:message code="label.pages.admin"></spring:message></a>
</div>
</body>
</html>

View File

@ -2,18 +2,16 @@
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title><spring:message code="label.pages.home.title"></spring:message></title>
</head>
<body>
<div class="container">
<div class="span12">
<h1 class="alert alert-error">
<spring:message code="message.email.config.error"></spring:message>
</h1>
</div>
</div>
<div class="container">
<h1 class="alert alert-danger">
<spring:message code="message.email.config.error"></spring:message>
</h1>
</div>
</body>
</html>
</html>

View File

@ -1,6 +1,6 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
uri="http://www.springframework.org/security/tags"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<fmt:setBundle basename="messages" />
@ -8,16 +8,17 @@
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<title><spring:message code="label.pages.home.title"></spring:message></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title><spring:message code="label.pages.home.title"></spring:message></title>
</head>
<body>
<h1>
<div class="container">
<h1 class="alert alert-info">
<spring:message code="auth.message.expired"></spring:message>
</h1>
<br>
<a href="<c:url value="/registration.html" />"><spring:message
<a class="btn btn-default" href="<c:url value="registration.html" />"><spring:message
code="label.form.loginSignUp"></spring:message></a>
</div>
</body>
</html>

View File

@ -4,41 +4,30 @@
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
uri="http://www.springframework.org/security/tags"%>
<%@ page session="false"%>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title><spring:message code="message.resetPassword"></spring:message></title>
</head>
<body>
<div class="container">
<div class="span12">
<h1>
<spring:message code="message.resetPassword"></spring:message>
</h1>
<div>
<br>
<tr>
<td><label><spring:message code="label.user.email"></spring:message></label></td>
<td><input id="email" name="email" type="email" value="" /></td>
</tr>
<button class="btn btn-primary" type="submit" onclick="resetPass()">
<spring:message code="message.resetPassword"></spring:message>
</button>
<h1><spring:message code="message.resetPassword"></spring:message></h1>
<br>
<div class="row">
<label class="col-sm-1"><spring:message code="label.user.email"></spring:message></label>
<span class="col-sm-5"><input class="form-control" id="email" name="email" type="email" value="" /></span>
<button class="btn btn-primary" type="submit" onclick="resetPass()"><spring:message code="message.resetPassword"></spring:message></button>
</div>
<br>
<a href="<c:url value="/registration.html" />"><spring:message code="label.form.loginSignUp"></spring:message></a>
<br>
<a href="<c:url value="login.html" />"><spring:message code="label.form.loginLink"></spring:message></a>
<a class="btn btn-default" href="<c:url value="registration.html" />"><spring:message code="label.form.loginSignUp"></spring:message></a>
<br><br>
<a class="btn btn-default" href="<c:url value="login.html" />"><spring:message code="label.form.loginLink"></spring:message></a>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function resetPass(){

View File

@ -4,19 +4,26 @@
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title><spring:message code="label.pages.home.title"></spring:message></title>
</head>
<body>
<div class="container">
<div class="span12">
<h1>
<spring:message code="label.pages.home.message"></spring:message>
</h1>
<a href="<c:url value="/j_spring_security_logout" />"><spring:message
code="label.pages.logout"></spring:message></a>
</div>
</div>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand"href="#"><spring:message code="label.pages.home.title"></spring:message></a>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="<c:url value="/j_spring_security_logout" />"><spring:message code="label.pages.logout"></spring:message></a> </li>
</ul>
</div>
</nav>
<div class="container">
<h1>
<spring:message code="label.pages.home.message"></spring:message>
</h1>
</div>
</body>
</html>

View File

@ -1,35 +1,38 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
uri="http://www.springframework.org/security/tags"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ page session="true"%>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title><spring:message code="label.pages.home.title"></spring:message></title>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand"href="<c:url value="/home.html" />"><spring:message code="label.pages.home.title"></spring:message></a>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="<c:url value="/j_spring_security_logout" />"><spring:message code="label.pages.logout"></spring:message></a> </li>
</ul>
</div>
</nav>
<div class="container">
<div class="span12">
<sec:authorize access="hasRole('READ_PRIVILEGE')">
<spring:message code="label.pages.user.message"></spring:message>
<br />
</sec:authorize>
<div class="container">
<sec:authorize access="hasRole('READ_PRIVILEGE')">
<spring:message code="label.pages.user.message"></spring:message>
<br />
</sec:authorize>
<sec:authorize access="hasRole('WRITE_PRIVILEGE')">
<spring:message code="label.pages.admin.message"></spring:message>
<br />
</sec:authorize>
${param.user}
<a href="<c:url value="/j_spring_security_logout" />"><spring:message
code="label.pages.logout"></spring:message></a> <a
href="<c:url value="/home.html" />"><spring:message
code="label.pages.home.title"></spring:message></a> <a
href="<c:url value="/admin.html" />"><spring:message
code="label.pages.admin"></spring:message></a>
</div>
</div>
<sec:authorize access="hasRole('WRITE_PRIVILEGE')">
<spring:message code="label.pages.admin.message"></spring:message>
<br />
</sec:authorize>
${param.user}
<a class="btn btn-default" href="<c:url value="/admin.html" />"><spring:message code="label.pages.admin"></spring:message></a>
</div>
</body>
</html>

View File

@ -2,19 +2,17 @@
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title><spring:message code="label.pages.home.title"></spring:message></title>
</head>
<body>
<div class="container">
<div class="span12">
<h1 class="alert alert-error">
<spring:message code="message.sessionExpired"></spring:message>
</h1>
<a href="<c:url value="login.html" />"><spring:message
code="label.form.loginLink"></spring:message></a>
</div>
</div>
<div class="container">
<h1 class="alert alert-danger">
<spring:message code="message.sessionExpired"></spring:message>
</h1>
<a class="btn btn-primary" href="<c:url value="login.html" />"><spring:message
code="label.form.loginLink"></spring:message></a>
</div>
</body>
</html>
</html>

View File

@ -1,6 +1,6 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
uri="http://www.springframework.org/security/tags"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<fmt:setBundle basename="messages" />
@ -8,58 +8,62 @@
<fmt:message key="message.password" var="noPass" />
<fmt:message key="message.username" var="noUser" />
<c:if test="${param.error != null}">
<c:choose>
<c:when
test="${SPRING_SECURITY_LAST_EXCEPTION.message == 'User is disabled'}">
<div class="alert alert-error">
<spring:message code="auth.message.disabled"></spring:message>
</div>
</c:when>
<c:when
test="${SPRING_SECURITY_LAST_EXCEPTION.message == 'User account has expired'}">
<div class="alert alert-error">
<spring:message code="auth.message.expired"></spring:message>
</div>
</c:when>
<c:when
<c:choose>
<c:when
test="${SPRING_SECURITY_LAST_EXCEPTION.message == 'User is disabled'}">
<div class="alert alert-danger">
<spring:message code="auth.message.disabled"></spring:message>
</div>
</c:when>
<c:when
test="${SPRING_SECURITY_LAST_EXCEPTION.message == 'User account has expired'}">
<div class="alert alert-danger">
<spring:message code="auth.message.expired"></spring:message>
</div>
</c:when>
<c:when
test="${SPRING_SECURITY_LAST_EXCEPTION.message == 'blocked'}">
<div class="alert alert-error">
<div class="alert alert-danger">
<spring:message code="auth.message.blocked"></spring:message>
</div>
</c:when>
<c:otherwise>
<div class="alert alert-error">
<!-- <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/> -->
<spring:message code="message.badCredentials"></spring:message>
</div>
</c:otherwise>
</c:choose>
<c:otherwise>
<div class="alert alert-danger">
<!-- <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/> -->
<spring:message code="message.badCredentials"></spring:message>
</div>
</c:otherwise>
</c:choose>
</c:if>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<title><spring:message code="label.pages.home.title"></spring:message></title>
<script type="text/javascript">
function validate() {
if (document.f.j_username.value == ""
&& document.f.j_password.value == "") {
alert("${noUser} & ${noPass}");
document.f.j_username.focus();
return false;
}
if (document.f.j_username.value == "") {
alert("${noUser}");
document.f.j_username.focus();
return false;
}
if (document.f.j_password.value == "") {
alert("${noPass}");
document.f.j_password.focus();
return false;
}
}
function validate() {
if (document.f.j_username.value == ""
&& document.f.j_password.value == "") {
alert("${noUser} & ${noPass}");
document.f.j_username.focus();
return false;
}
if (document.f.j_username.value == "") {
alert("${noUser}");
document.f.j_username.focus();
return false;
}
if (document.f.j_password.value == "") {
alert("${noPass}");
document.f.j_password.focus();
return false;
}
}
</script>
<style type="text/css">
.wrapper{width:400px;margin-left:auto;margin-right:auto}
label{padding-left:0 !important}
</style>
</head>
<body>
<c:if test="${param.message != null}">
@ -68,42 +72,38 @@ ${param.message}
</div>
</c:if>
<div class="container">
<div class="span12">
<h1>
<spring:message code="label.form.loginTitle"></spring:message>
</h1>
<a href="?lang=en"><spring:message code="label.form.loginEnglish"></spring:message></a>
| <a href="?lang=es_ES"><spring:message
code="label.form.loginSpanish"></spring:message></a>
<form name='f' action="j_spring_security_check" method='POST'
onsubmit="return validate();">
<table>
<tr>
<td><label><spring:message
code="label.form.loginEmail"></spring:message></label></td>
<td><input type='text' name='j_username' value=''></td>
</tr>
<tr>
<td><label><spring:message
code="label.form.loginPass"></spring:message></label></td>
<td><input type='password' name='j_password' /></td>
</tr>
<tr>
<td><input class="btn btn-primary" name="submit" type="submit"
value=<spring:message code="label.form.submit"></spring:message> /></td>
</tr>
</table>
<div class="container">
<div class="row wrapper">
<h1>
<spring:message code="label.form.loginTitle"></spring:message>
</h1>
<a href="?lang=en"><spring:message code="label.form.loginEnglish"></spring:message></a>
| <a href="?lang=es_ES"><spring:message
code="label.form.loginSpanish"></spring:message></a>
<br><br>
<form name='f' action="j_spring_security_check" method='POST'
onsubmit="return validate();">
<label class="col-sm-2"><spring:message code="label.form.loginEmail"></spring:message></label>
<span class="col-sm-10"><input class="form-control" type='text' name='j_username' value=''></span>
<br><br>
<label class="col-sm-2"><spring:message code="label.form.loginPass"></spring:message></label>
<span class="col-sm-10"><input class="form-control" type='password' name='j_password' /></span>
<br><br>
<input class="btn btn-primary" name="submit" type="submit"
value=<spring:message code="label.form.submit"></spring:message> />
</form>
<br> Current Locale : ${pageContext.response.locale} <br> <a
href="<c:url value="/registration.html" />"><spring:message
code="label.form.loginSignUp"></spring:message></a>
<br><br><br>
<a href="<c:url value="/forgetPassword.html" />"><spring:message
</form>
<br> Current Locale : ${pageContext.response.locale} <br><br>
<a class="btn btn-default" href="<c:url value="registration.html" />"><spring:message
code="label.form.loginSignUp"></spring:message></a>
<br><br>
<a class="btn btn-default" href="<c:url value="/forgetPassword.html" />"><spring:message
code="message.resetPassword"></spring:message></a>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@ -1,32 +1,31 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
uri="http://www.springframework.org/security/tags"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<c:if test="${not empty SPRING_SECURITY_LAST_EXCEPTION}">
<div id="error">
<spring:message code="message.logoutError"></spring:message>
</div>
<h1 id="error" class="alert alert-danger">
<spring:message code="message.logoutError"></spring:message>
</h1>
</c:if>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title><spring:message code="label.pages.home.title"></spring:message></title>
</head>
<body>
<div class="container">
<div class="span12">
<c:if test="${param.logSucc == true}">
<div id="success">
<spring:message code="message.logoutSucc"></spring:message>
</div>
</c:if>
<a href="<c:url value="login.html" />"><spring:message
code="label.form.loginLink"></spring:message></a>
</div>
</div>
<div class="container">
<c:if test="${param.logSucc == true}">
<h1 id="success" class="alert alert-info">
<spring:message code="message.logoutSucc"></spring:message>
</h1>
</c:if>
<a class="btn btn-primary" href="<c:url value="login.html" />"><spring:message
code="label.form.loginLink"></spring:message></a>
</div>
</body>
</html>

View File

@ -6,7 +6,13 @@
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<style>
.password-verdict{
color:#000;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="<c:url value="/resources/pwstrength.js" />"></script>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title><spring:message code="label.form.title"></spring:message></title>
</head>
@ -57,6 +63,14 @@
</div>
<script type="text/javascript">
$(document).ready(function () {
options = {
common: {minChar:8},
ui: {showVerdictsInsideProgressBar:true}
};
$('#password').pwstrength(options);
});
function register(){
event.preventDefault();
$(".alert").html("").hide();

View File

@ -1,6 +1,6 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
uri="http://www.springframework.org/security/tags"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<fmt:setBundle basename="messages" />
@ -10,13 +10,14 @@
</c:if>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title><spring:message code="label.pages.home.title"></spring:message></title>
</head>
<body>
<spring:message code="message.regSucc"></spring:message>
<a href="<c:url value="login.html" />"><spring:message code="label.login"></spring:message></a>
<div>
<h1 class="alert alert-info"><spring:message code="message.regSucc"></spring:message></h1>
<a class="btn btn-primary" href="<c:url value="login.html" />"><spring:message code="label.login"></spring:message></a>
</div>
</body>
</html>

View File

@ -8,31 +8,26 @@
<%@ page session="false"%>
<html>
<head>
<link href="<c:url value="/resources/bootstrap.css" />" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title><spring:message code="message.updatePassword"></spring:message></title>
</head>
<body>
<sec:authorize access="hasRole('READ_PRIVILEGE')">
<div class="container">
<div class="span12">
<H1>
<spring:message code="message.resetYourPassword"></spring:message>
</H1>
<div class="row">
<h1> <spring:message code="message.resetYourPassword"></spring:message> </h1>
<div >
<br>
<tr>
<td><label><spring:message code="label.user.password"></spring:message></label></td>
<td><input id="pass" name="password" type="password" value="" /></td>
</tr>
<tr>
<td><label><spring:message code="label.user.confirmPass"></spring:message></label></td>
<td>
<input id="passConfirm" type="password" value="" />
<span id="error" class="alert alert-error" style="display:none"><spring:message code="PasswordMatches.user"></spring:message></span>
</td>
</tr>
<label class="col-sm-2"><spring:message code="label.user.password"></spring:message></label>
<span class="col-sm-5"><input class="form-control" id="pass" name="password" type="password" value="" /></span>
<span class="col-sm-5"></span>
<br><br>
<label class="col-sm-2"><spring:message code="label.user.confirmPass"></spring:message></label>
<span class="col-sm-5"><input class="form-control" id="passConfirm" type="password" value="" /></span>
<span id="error" class="alert alert-danger" style="display:none"><spring:message code="PasswordMatches.user"></spring:message></span>
<br><br>
<button class="btn btn-primary" type="submit" onclick="savePass()">
<spring:message code="message.updatePassword"></spring:message>

File diff suppressed because one or more lines are too long