Package com.example.bookstore.domain

Examples of com.example.bookstore.domain.Account


    @Autowired
    private AccountService accountService;

    @Before
    public void setup() throws AuthenticationException {
        Account account = new AccountBuilder() {
            {
                address("Herve", "4650", "Rue de la station", "1", null, "Belgium");
                credentials("john", "secret");
                name("John", "Doe");
            }
View Full Code Here


        MockHttpSession mockHttpSession = new MockHttpSession();
        mockHttpSession.setAttribute(LoginController.REQUESTED_URL, "someUrl");

        String view = this.loginController.handleLogin("john", "secret", mockHttpSession);

        Account account = (Account) mockHttpSession.getAttribute(LoginController.ACCOUNT_ATTRIBUTE);

        assertNotNull(account);
        assertEquals("John", account.getFirstName());
        assertEquals("Doe", account.getLastName());
        assertNull(mockHttpSession.getAttribute(LoginController.REQUESTED_URL));
        assertEquals("redirect:someUrl", view);

        // Test the different view selection choices
        mockHttpSession = new MockHttpSession();
View Full Code Here

  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    if (StringUtils.isBlank(username)) {
      throw new UsernameNotFoundException("Username was empty");
    }

    Account account = accountService.getAccount(username);

    if (account == null) {
      throw new UsernameNotFoundException("Username not found");
    }

    List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();

    for (Role role : account.getRoles()) {
      grantedAuthorities.add(new SimpleGrantedAuthority(role.getRole()));
      for (Permission permission : role.getPermissions()) {
        grantedAuthorities.add(new SimpleGrantedAuthority(permission.getPermission()));
      }
    }
View Full Code Here

    return this.accountRepository.save(account);
  }

  @Override
  public Account login(String username, String password) throws AuthenticationException {
    Account account = this.accountRepository.findByUsername(username);
    if (account != null) {
      String pwd = DigestUtils.sha256Hex(password + "{" + username + "}");
      if (!account.getPassword().equalsIgnoreCase(pwd)) {
        throw new AuthenticationException("Wrong username/password combination.", "invalid.password");
      }
    } else {
      throw new AuthenticationException("Wrong username/password combination.", "invalid.username");
    }
View Full Code Here

*/
public class SecurityHandlerInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Account account = (Account) WebUtils.getSessionAttribute(request, LoginController.ACCOUNT_ATTRIBUTE);
        if (account == null) {

            //Retrieve and store the original URL.
            String url = request.getRequestURL().toString();
            WebUtils.setSessionAttribute(request, LoginController.REQUESTED_URL, url);
View Full Code Here

        return countries;
    }

    @RequestMapping(method = RequestMethod.GET)
    public void show(HttpSession session, Model model) {
        Account account = (Account) session.getAttribute(LoginController.ACCOUNT_ATTRIBUTE);
        Order order = this.bookstoreService.createOrder(this.cart, account);
        model.addAttribute(order);
    }
View Full Code Here

        ValidationUtils.rejectIfEmpty(errors, "address.street", "required", new Object[] { "Street" });
        ValidationUtils.rejectIfEmpty(errors, "address.city", "required", new Object[] { "City" });
        ValidationUtils.rejectIfEmpty(errors, "address.country", "required", new Object[] { "Country" });

        if (!errors.hasFieldErrors("emailAddress")) {
            Account account = (Account) target;
            String email = account.getEmailAddress();
            if (!email.matches(EMAIL_PATTERN)) {
                errors.rejectValue("emailAddress", "invalid");
            }
        }
    }
View Full Code Here

    }

    @RequestMapping(method = RequestMethod.GET)
    @ModelAttribute
    public Account register(Locale currentLocale) {
        Account account = new Account();
        account.getAddress().setCountry(currentLocale.getCountry());
        return account;
    }
View Full Code Here

    }

    @RequestMapping(method = RequestMethod.POST)
    public String handleLogin(@RequestParam String username, @RequestParam String password, HttpSession session)
            throws AuthenticationException {
        Account account = this.accountService.login(username, password);
        session.setAttribute(ACCOUNT_ATTRIBUTE, account);
        String url = (String) session.getAttribute(REQUESTED_URL);
        session.removeAttribute(REQUESTED_URL); // Remove the attribute
        if (StringUtils.hasText(url) && !url.contains("login")) { // Prevent loops for the login page.
            return "redirect:" + url;
View Full Code Here

    @Autowired
    private AccountRepository accountRepository;

    @Before
    public void setup() {
        Account account = new AccountBuilder() {
            {
                address("Herve", "4650", "Rue de la gare", "1", null, "Belgium");
                credentials("john", "secret");
                name("John", "Doe");
            }
View Full Code Here

TOP

Related Classes of com.example.bookstore.domain.Account

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.