// Path: src/main/java/net/worldline/training/angular/data/user/RoleConsts.java
// public final class RoleConsts {
// 
//     public static final String ALL_ROLE = "*";
//     public static final String USER_ROLE = "USER";
//     public static final String ADMIN_ROLE = "ADMIN";
// 
// }
// 
// Path: src/main/java/net/worldline/training/angular/data/user/RoleEnum.java
// public enum RoleEnum {
//     ALL(RoleConsts.ALL_ROLE), ADMIN(RoleConsts.ADMIN_ROLE), USER(RoleConsts.USER_ROLE);
// 
//     private String role;
// 
//     private RoleEnum(String s) {
//         role = s;
//     }
// 
//     public String getRole() {
//         return role;
//     }
// 
// }
// 
// Path: src/main/java/net/worldline/training/angular/entity/User.java
// @Entity
// public class User implements Serializable
// {
//     private static final long serialVersionUID = 1L;
//     @Transient
//     private int id;
//     private String uri;
//     private String firstName;
//     private String lastName;
//     private Date lastModified;
//     private String email;
//     @Id
//     private String login;
//     private String password;
//     @ElementCollection
//     @CollectionTable(name="Roles", joinColumns=@JoinColumn(name="user_login"))
//     @Column(name="roles")
//     private List<String> roles;
// 
//     public User() {}
// 
//     public Date getLastModified() {
// 		return lastModified;
//     }
//     public void setLastModified(Date lastModified) {
// 		this.lastModified = lastModified;
// 	}
//     public int getId() {
// 		return id;
// 	}
//     public void setId(int id) {
// 		this.id = id;
// 	}
//     public String getFirstName() {
// 		return firstName;
// 	}
//     public void setFirstName(String firstName) {
// 		this.firstName = firstName;
// 	}
//     public String getLastName() {
// 		return lastName;
// 	}
//     public void setLastName(String lastName) {
// 		this.lastName = lastName;
// 	}
//     public String getUri() {
// 		return uri;
// 	}
//     public void setUri(String uri) {
// 		this.uri = uri;
// 	}
//     public String getEmail() {
//         return email;
//     }
//     public void setEmail(String email) {
//         this.email = email;
//     }
//     public String getLogin() {
//         return login;
//     }
//     public void setLogin(String login) {
//         this.login = login;
//     }
//     public String getPassword() {
//         return password;
//     }
//     public void setPassword(String password) {
//         this.password = password;
//     }
//     public List<String> getRoles() {
//         return roles;
//     }
//     public void setRoles(List<String> roles) {
//         this.roles = roles;
//     }
// }


import net.worldline.training.angular.data.user.RoleConsts;
import net.worldline.training.angular.data.user.RoleEnum;
import net.worldline.training.angular.data.user.Token;
import net.worldline.training.angular.entity.User;
import net.worldline.training.angular.services.UserDAO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
import org.jboss.resteasy.util.Base64;
import org.slf4j.Logger;
import org.tynamo.security.services.SecurityService;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.*;

    @GET
    @Path("/account")
    @PermitAll
    public Response account( @Context Request req, @Context HttpHeaders headers)
    {
        String auth = headers.getHeaderString(AUTHORIZATION_PROPERTY);
        //Get encoded username and password
        final String encodedUserPassword = auth.replaceFirst(AUTHENTICATION_SCHEME + " ", "");

        JSONObject JSONEntity = new JSONObject();
        //Decode username and password
        String usernameAndPassword;
        try {
            usernameAndPassword = new String(Base64.decode(encodedUserPassword));
        } catch (IOException e) {
            JSONEntity.put("message","invalid token");
            return Response.status(Response.Status.BAD_REQUEST).entity(JSONEntity.toString()).build();
        }

        //Split username and password tokens
        final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
        final String username = tokenizer.nextToken();
        final String password = tokenizer.nextToken();



        Subject subject;
        try {

            subject = securityService.getSubject();

// Path: src/main/java/net/worldline/training/angular/data/user/RoleConsts.java
// public final class RoleConsts {
// 
//     public static final String ALL_ROLE = "*";
//     public static final String USER_ROLE = "USER";
//     public static final String ADMIN_ROLE = "ADMIN";
// 
// }
// 
// Path: src/main/java/net/worldline/training/angular/data/user/RoleEnum.java
// public enum RoleEnum {
//     ALL(RoleConsts.ALL_ROLE), ADMIN(RoleConsts.ADMIN_ROLE), USER(RoleConsts.USER_ROLE);
// 
//     private String role;
// 
//     private RoleEnum(String s) {
//         role = s;
//     }
// 
//     public String getRole() {
//         return role;
//     }
// 
// }
// 
// Path: src/main/java/net/worldline/training/angular/entity/User.java
// @Entity
// public class User implements Serializable
// {
//     private static final long serialVersionUID = 1L;
//     @Transient
//     private int id;
//     private String uri;
//     private String firstName;
//     private String lastName;
//     private Date lastModified;
//     private String email;
//     @Id
//     private String login;
//     private String password;
//     @ElementCollection
//     @CollectionTable(name="Roles", joinColumns=@JoinColumn(name="user_login"))
//     @Column(name="roles")
//     private List<String> roles;
// 
//     public User() {}
// 
//     public Date getLastModified() {
// 		return lastModified;
//     }
//     public void setLastModified(Date lastModified) {
// 		this.lastModified = lastModified;
// 	}
//     public int getId() {
// 		return id;
// 	}
//     public void setId(int id) {
// 		this.id = id;
// 	}
//     public String getFirstName() {
// 		return firstName;
// 	}
//     public void setFirstName(String firstName) {
// 		this.firstName = firstName;
// 	}
//     public String getLastName() {
// 		return lastName;
// 	}
//     public void setLastName(String lastName) {
// 		this.lastName = lastName;
// 	}
//     public String getUri() {
// 		return uri;
// 	}
//     public void setUri(String uri) {
// 		this.uri = uri;
// 	}
//     public String getEmail() {
//         return email;
//     }
//     public void setEmail(String email) {
//         this.email = email;
//     }
//     public String getLogin() {
//         return login;
//     }
//     public void setLogin(String login) {
//         this.login = login;
//     }
//     public String getPassword() {
//         return password;
//     }
//     public void setPassword(String password) {
//         this.password = password;
//     }
//     public List<String> getRoles() {
//         return roles;
//     }
//     public void setRoles(List<String> roles) {
//         this.roles = roles;
//     }
// }


// Path: src/main/java/net/worldline/training/angular/ws/service/UserService.java
import net.worldline.training.angular.data.user.RoleConsts;
import net.worldline.training.angular.data.user.RoleEnum;
import net.worldline.training.angular.data.user.Token;
import net.worldline.training.angular.entity.User;
import net.worldline.training.angular.services.UserDAO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
import org.jboss.resteasy.util.Base64;
import org.slf4j.Logger;
import org.tynamo.security.services.SecurityService;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.*;

    @GET
    @Path("/account")
    @PermitAll
    public Response account( @Context Request req, @Context HttpHeaders headers)
    {
        String auth = headers.getHeaderString(AUTHORIZATION_PROPERTY);
        //Get encoded username and password
        final String encodedUserPassword = auth.replaceFirst(AUTHENTICATION_SCHEME + " ", "");

        JSONObject JSONEntity = new JSONObject();
        //Decode username and password
        String usernameAndPassword;
        try {
            usernameAndPassword = new String(Base64.decode(encodedUserPassword));
        } catch (IOException e) {
            JSONEntity.put("message","invalid token");
            return Response.status(Response.Status.BAD_REQUEST).entity(JSONEntity.toString()).build();
        }

        //Split username and password tokens
        final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
        final String username = tokenizer.nextToken();
        final String password = tokenizer.nextToken();



        Subject subject;
        try {

            subject = securityService.getSubject();

            if (!subject.isAuthenticated()) {
