Example usage for org.springframework.security.core AuthenticationException getLocalizedMessage

List of usage examples for org.springframework.security.core AuthenticationException getLocalizedMessage

Introduction

In this page you can find the example usage for org.springframework.security.core AuthenticationException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:cz.lbenda.coursing.client.gui.LoginForm.java

public static void showLoginDialog() {
    final LoginForm form = new LoginForm();
    JButton login = new JButton();
    login.setText("Login"); // FIXME localizable
    JButton cancel = new JButton();
    cancel.setText("Cancel"); // FIXME localizable

    cancel.addActionListener(new ActionListener() {
        @Override//  w ww  .  j  av  a  2 s  .  c o  m
        public void actionPerformed(ActionEvent e) {
            exit();
        }
    });

    login.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                SecurityService ss = (SecurityService) ClientServiceLocator.getInstance()
                        .getBean(SecurityService.SERVICE_NAME);
                ss.login(form.getUsername(), form.getPassword());
            } catch (AuthenticationException ex) {
                NotifyDescriptor info = new NotifyDescriptor.Message(ex.getLocalizedMessage(),
                        NotifyDescriptor.INFORMATION_MESSAGE);
                DialogDisplayer.getDefault().notify(info);
                LoginForm.showLoginDialog();
            }
        }
    });

    NotifyDescriptor nd = new NotifyDescriptor.Confirmation(form, Bundle.CTL_LoginForm());
    nd.setOptions(new Object[] { login, cancel });
    nd.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (NotifyDescriptor.CLOSED_OPTION.equals(evt.getNewValue())) {
                exit();
            }
        }
    });
    DialogDisplayer.getDefault().notifyLater(nd);
}

From source file:net.thewaffleshop.nimbus.web.LoginController.java

@RequestMapping(value = "/authenticationFailure", method = RequestMethod.POST)
@ResponseBody//from   w w  w  .j a v a 2s . c  o  m
public Object authenticationFailure(HttpServletRequest request, HttpServletResponse response) {
    AuthenticationException ae = (AuthenticationException) request.getAttribute("authenticationException");

    ExtAjaxResponse ret = new ExtAjaxResponse(false);
    if (!(ae instanceof InternalAuthenticationServiceException)) {
        ret.setMsg(ae.getLocalizedMessage());
    }
    return ret;
}

From source file:com.coinblesk.server.controller.UserController.java

@RequestMapping(value = "/login", method = POST, consumes = APPLICATION_JSON_UTF8_VALUE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<?> login(@Valid @RequestBody LoginDTO loginDTO, HttpServletResponse response) {

    UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
            loginDTO.getUsername().toLowerCase(Locale.ENGLISH), loginDTO.getPassword());

    try {/*from  w  ww . j a v a2 s  . c om*/
        Authentication authentication = this.authenticationManager.authenticate(authenticationToken);
        SecurityContextHolder.getContext().setAuthentication(authentication);

        String jwt = tokenProvider.createToken(authentication);
        response.addHeader(JWTConfigurer.AUTHORIZATION_HEADER, "Bearer " + jwt);

        return ResponseEntity.ok(Collections.singletonMap("token", jwt));
    } catch (AuthenticationException exception) {
        return new ResponseEntity<>(
                Collections.singletonMap("AuthenticationException", exception.getLocalizedMessage()),
                HttpStatus.UNAUTHORIZED);
    }
}