// Path: web/src/main/java/org/sample/web/app/SSAuthenticatedWebSession.java
// public class SSAuthenticatedWebSession extends AuthenticatedWebSession {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 
// 	protected final Logger log = LoggerFactory.getLogger(getClass());
//     
// 
//     @SpringBean(name = "authenticationManagerBean")
//     private AuthenticationManager authenticationManager;
// 
// 
// 	private HttpSession httpSession;
// 
//     public SSAuthenticatedWebSession(Request request) {
//         super(request);
//         Injector.get().inject(this);
//         this.httpSession = ((HttpServletRequest) request.getContainerRequest()).getSession();
//         if (authenticationManager == null) {
//             throw new IllegalStateException("Injection of AuthenticationManager failed.");
//         }
//         
//     }
// 
//     public static SSAuthenticatedWebSession getSSAuthenticatedWebSession() {
//         return (SSAuthenticatedWebSession) Session.get();
//     }
//     
//     @Override
//     public boolean authenticate(String username, String password) {
//         boolean authenticated;
//         try {
//             Authentication authentication = authenticationManager.authenticate(
//                     new UsernamePasswordAuthenticationToken(username, password));
//             SecurityContextHolder.getContext().setAuthentication(authentication);      
//         	httpSession.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
//         			SecurityContextHolder.getContext());
//             authenticated = authentication.isAuthenticated();
//         } catch (AuthenticationException e) {
//             log.warn("User '{}' failed to login. Reason: {}", username, e.getMessage());
//             authenticated = false;
//         }
//         return authenticated;
//     }
// 
//     @Override
//     public Roles getRoles() {
//         Roles roles = new Roles();
//         getRolesIfSignedIn(roles);
//         return roles;
//     }
// 
//     private void getRolesIfSignedIn(Roles roles) {
//         if (isSignedIn()) {
//             Authentication authentication = SecurityContextHolder.getContext().getAuthentication();                        
//             addRolesFromAuthentication(roles, authentication);
//         }
//     }
// 
//     private void addRolesFromAuthentication(Roles roles, Authentication authentication) {
//         for (GrantedAuthority authority : authentication.getAuthorities()) {
//             roles.add(authority.getAuthority().replaceFirst("ROLE_",""));
//         }
//     }
// 
// }
// 
// Path: web/src/main/java/org/sample/web/components/PlaceholderBehavior.java
// public class PlaceholderBehavior extends Behavior {
// 
// 
// 	private static final long serialVersionUID = 1L;
// 	private final String placeholder;
// 
//     public PlaceholderBehavior(String placeholder) {
//         this.placeholder = placeholder;
//     }
// 
//     @Override
//     public void onComponentTag(Component component, ComponentTag tag) {
//         super.onComponentTag(component, tag);
//         tag.put("placeholder", placeholder);
//     }
// }
// 
// Path: web/src/main/java/org/sample/web/components/RequiredBehavior.java
// public class RequiredBehavior extends Behavior {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	@Override
//     public void onComponentTag(Component component, ComponentTag tag) {
//         super.onComponentTag(component, tag);
//         tag.put("required", "required");
//     }
// }


import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.form.validation.FormComponentFeedbackBorder;
import org.apache.wicket.model.Model;
import org.sample.web.app.SSAuthenticatedWebSession;
import org.sample.web.components.PlaceholderBehavior;
import org.sample.web.components.RequiredBehavior;
import org.wicketstuff.annotation.mount.MountPath;
import de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapForm;
package org.sample.web.pages;




/**
 * @author mpostelnicu
 * 
 */
@MountPath("/login")
public class Login extends HeaderFooter {

	private static final long serialVersionUID = 1L;


	class LoginForm extends BootstrapForm<Void> { 
  
    	private static final long serialVersionUID = 1L;
    	
    	private TextField<String> usernameField;
    	private TextField<String> passwordField;
    	 	
    	public void createAndAddToLoginFormUsernameAndPasswordFields() {
    	        add(new FormComponentFeedbackBorder("border").add(
    	                (usernameField = new RequiredTextField<String>("username", Model.of("")))));
    	        usernameField.add(new PlaceholderBehavior(getString("label.username")));
    	        usernameField.add(new RequiredBehavior());
    	        add(passwordField = new PasswordTextField("password", Model.of("")));
// Path: web/src/main/java/org/sample/web/app/SSAuthenticatedWebSession.java
// public class SSAuthenticatedWebSession extends AuthenticatedWebSession {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 
// 	protected final Logger log = LoggerFactory.getLogger(getClass());
//     
// 
//     @SpringBean(name = "authenticationManagerBean")
//     private AuthenticationManager authenticationManager;
// 
// 
// 	private HttpSession httpSession;
// 
//     public SSAuthenticatedWebSession(Request request) {
//         super(request);
//         Injector.get().inject(this);
//         this.httpSession = ((HttpServletRequest) request.getContainerRequest()).getSession();
//         if (authenticationManager == null) {
//             throw new IllegalStateException("Injection of AuthenticationManager failed.");
//         }
//         
//     }
// 
//     public static SSAuthenticatedWebSession getSSAuthenticatedWebSession() {
//         return (SSAuthenticatedWebSession) Session.get();
//     }
//     
//     @Override
//     public boolean authenticate(String username, String password) {
//         boolean authenticated;
//         try {
//             Authentication authentication = authenticationManager.authenticate(
//                     new UsernamePasswordAuthenticationToken(username, password));
//             SecurityContextHolder.getContext().setAuthentication(authentication);      
//         	httpSession.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
//         			SecurityContextHolder.getContext());
//             authenticated = authentication.isAuthenticated();
//         } catch (AuthenticationException e) {
//             log.warn("User '{}' failed to login. Reason: {}", username, e.getMessage());
//             authenticated = false;
//         }
//         return authenticated;
//     }
// 
//     @Override
//     public Roles getRoles() {
//         Roles roles = new Roles();
//         getRolesIfSignedIn(roles);
//         return roles;
//     }
// 
//     private void getRolesIfSignedIn(Roles roles) {
//         if (isSignedIn()) {
//             Authentication authentication = SecurityContextHolder.getContext().getAuthentication();                        
//             addRolesFromAuthentication(roles, authentication);
//         }
//     }
// 
//     private void addRolesFromAuthentication(Roles roles, Authentication authentication) {
//         for (GrantedAuthority authority : authentication.getAuthorities()) {
//             roles.add(authority.getAuthority().replaceFirst("ROLE_",""));
//         }
//     }
// 
// }
// 
// Path: web/src/main/java/org/sample/web/components/PlaceholderBehavior.java
// public class PlaceholderBehavior extends Behavior {
// 
// 
// 	private static final long serialVersionUID = 1L;
// 	private final String placeholder;
// 
//     public PlaceholderBehavior(String placeholder) {
//         this.placeholder = placeholder;
//     }
// 
//     @Override
//     public void onComponentTag(Component component, ComponentTag tag) {
//         super.onComponentTag(component, tag);
//         tag.put("placeholder", placeholder);
//     }
// }
// 
// Path: web/src/main/java/org/sample/web/components/RequiredBehavior.java
// public class RequiredBehavior extends Behavior {
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	@Override
//     public void onComponentTag(Component component, ComponentTag tag) {
//         super.onComponentTag(component, tag);
//         tag.put("required", "required");
//     }
// }


// Path: web/src/main/java/org/sample/web/pages/Login.java
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.form.validation.FormComponentFeedbackBorder;
import org.apache.wicket.model.Model;
import org.sample.web.app.SSAuthenticatedWebSession;
import org.sample.web.components.PlaceholderBehavior;
import org.sample.web.components.RequiredBehavior;
import org.wicketstuff.annotation.mount.MountPath;
import de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapForm;

package org.sample.web.pages;




/**
 * @author mpostelnicu
 * 
 */
@MountPath("/login")
public class Login extends HeaderFooter {

	private static final long serialVersionUID = 1L;


	class LoginForm extends BootstrapForm<Void> { 
  
    	private static final long serialVersionUID = 1L;
    	
    	private TextField<String> usernameField;
    	private TextField<String> passwordField;
    	 	
    	public void createAndAddToLoginFormUsernameAndPasswordFields() {
    	        add(new FormComponentFeedbackBorder("border").add(
    	                (usernameField = new RequiredTextField<String>("username", Model.of("")))));
    	        usernameField.add(new PlaceholderBehavior(getString("label.username")));
    	        usernameField.add(new RequiredBehavior());
    	        add(passwordField = new PasswordTextField("password", Model.of("")));
    	        passwordField.add(new PlaceholderBehavior(getString("label.password")));