private AeroGearUser buildUser(String username, String password) {
   AeroGearUser aeroGearUser = new AeroGearUser();
   aeroGearUser.setId(username);
   aeroGearUser.setPassword(password);
   aeroGearUser.setEmail(username + "@doe.com");
   return aeroGearUser;
 }
 /**
  * This method creates a new {@link AeroGearUser}
  *
  * @param aeroGearUser
  */
 @Override
 public void create(AeroGearUser aeroGearUser) {
   User picketLinkUser = new SimpleUser(aeroGearUser.getUsername());
   picketLinkUser.setEmail(aeroGearUser.getEmail());
   picketLinkUser.setFirstName(aeroGearUser.getFirstName());
   picketLinkUser.setLastName(aeroGearUser.getLastName());
   identityManager.add(picketLinkUser);
 }
  @Override
  public void isRouteAllowed(Route route) throws ServletException {

    if (!user.hasRoles(route.getRoles())) {
      ExceptionMessage.AUTHENTICATION_FAILED.throwException();
    }
  }
  /**
   * This method applies roles specified on {@link
   * org.jboss.aerogear.security.authz.IdentityManagement#grant(String...)}
   *
   * @param aeroGearUser represents a simple user's implementation to hold credentials.
   */
  @Override
  public void to(AeroGearUser aeroGearUser) {

    User user =
        entityManager
            .createNamedQuery("User.findByUsername", User.class)
            .setParameter("username", aeroGearUser.getUsername())
            .getSingleResult();

    user.setRoles(list);
    entityManager.merge(user);
  }
 @Override
 public void remove(AeroGearUser aeroGearUser) {
   identityManager.remove(identityManager.getUser(aeroGearUser.getUsername()));
 }