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

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

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.gm.wine.web.LoginvalidateAction.java

@Override
public String execute() throws Exception {
    HttpServletRequest request = Struts2Utils.getRequest();
    String loginName = request.getParameter("loginName");
    String password = request.getParameter("password");
    UserVO u = new UserVO();

    try {//  www.ja v  a 2 s. c  o  m
        User user = userManager.getUserByUsername(loginName);
        if (user != null) {
            UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(loginName,
                    password);
            token.setDetails(new WebAuthenticationDetails(request));
            Authentication authenticatedUser = authenticationManager.authenticate(token);

            SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
            request.getSession().setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
                    SecurityContextHolder.getContext());
            u.setErrorCode(GlobalMessage.SUCCESS_CODE);
            u.setErrorMessage("?");
            u.setId(user.getId());
            u.setLoginName(user.getLoginName());
            u.setName(user.getName());
        } else {
            u.setErrorCode(GlobalMessage.ERROR_CODE);
            u.setErrorMessage("?");
        }
    } catch (AuthenticationException e) {
        e.printStackTrace();
        u.setErrorCode(GlobalMessage.ERROR_CODE);
        u.setErrorMessage("?");
    }

    data = new Gson().toJson(u);
    return SUCCESS;
}

From source file:org.vaadin.spring.samples.security.ui.login.views.LoginView.java

private Component buildFields() {
    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);/*  w w  w.  j a  v  a2 s  .  c  o m*/
    fields.addStyleName("fields");

    username = new TextField("Username");
    username.setIcon(FontAwesome.USER);
    username.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    password = new PasswordField("Password");
    password.setIcon(FontAwesome.LOCK);
    password.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    final Button signin = new Button("Sign In");
    signin.addStyleName(ValoTheme.BUTTON_PRIMARY);
    signin.setClickShortcut(KeyCode.ENTER);
    signin.focus();

    fields.addComponents(username, password, signin);
    fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);

    signin.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {

            try {

                security.login(username.getValue(), password.getValue());

            } catch (AuthenticationException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            // TODO Register Remember me Token

            /*
             * Redirect is handled by the VaadinRedirectStrategy
             * User is redirected to either always the default
             * or the URL the user request before authentication
             * 
             * Strategy is configured within SecurityConfiguration
             * Defaults to User request URL.
             */
        }
    });

    return fields;
}

From source file:com.gm.machine.web.IndexAction.java

public String login() throws Exception {
    try {/*w  w  w. ja va2  s .c  o  m*/
        HttpServletRequest request = Struts2Utils.getRequest();
        User entity = userManager.getUserByUsername(request.getParameter("username"));
        if (entity == null) {
            mess = "???";
            return "login";
        } else {
            if (entity.isUserlock()) {
                mess = "???";
                return "login";
            }
        }

        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
                request.getParameter("username"), request.getParameter("loginpwd"));
        token.setDetails(new WebAuthenticationDetails(request));
        Authentication authenticatedUser = authenticationManager.authenticate(token);

        SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
        request.getSession().setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
                SecurityContextHolder.getContext());

        entity.setLastLoginDate(new Date());// ?
        entity.setLoginTimes(entity.getLoginTimes() + 1);// 
        userManager.save(entity);
        request.getSession().setAttribute("loginuser", entity);
        request.getSession().setAttribute("userid", entity.getId());
        mess = "?";
        return "login";
    } catch (AuthenticationException e) {
        mess = "?";
        e.printStackTrace();
        return "login";

    }
}

From source file:org.pac4j.cas.client.CasClientWrapper.java

protected CasWrapperCredentials retrieveCredentials(final WebContext wc) throws RequiresHttpAction {

    J2EContext jc = (J2EContext) wc;//  w w w  . j  a v a  2 s.  c o m
    HttpServletRequest request = jc.getRequest();
    HttpServletResponse response = jc.getResponse();

    org.springframework.security.core.Authentication authentication = null;

    try {

        authentication = casFilterCas.attemptAuthentication(request, response);

    } catch (AuthenticationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    org.springframework.security.core.userdetails.User user = (org.springframework.security.core.userdetails.User) authentication
            .getPrincipal();

    CasWrapperCredentials casCredentials = new CasWrapperCredentials(user.getUsername(),
            this.getClass().getSimpleName(), authentication);

    return casCredentials;

}

From source file:org.infoscoop.api.oauth2.provider.ISAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication auth) throws AuthenticationException {
    String userid = auth.getName();
    String password = auth.getCredentials().toString();

    AuthenticationService service = AuthenticationService.getInstance();
    try {//from w w w  . ja va  2  s.c o  m
        // login
        service.login(userid, password);

        // authority
        List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
        PortalAdminsService portalService = PortalAdminsService.getHandle();
        portalService.getPortalAdmins();
        Portaladmins admin = portalService.getPortalAdmin(userid);
        if (admin != null) {
            grantedAuths.add(new SimpleGrantedAuthority(ROLE_ADMIN));
        } else {
            grantedAuths.add(new SimpleGrantedAuthority(ROLE_USER));
        }

        if (log.isDebugEnabled())
            log.debug("complete login " + userid + " - authotiry:" + grantedAuths.toString());

        return new UsernamePasswordAuthenticationToken(userid, password, grantedAuths);
    } catch (AuthenticationException e) {
        // login error
        log.error(e);
        e.printStackTrace();
        return null;
    } catch (org.infoscoop.account.AuthenticationException e) {
        log.error(e);
        e.printStackTrace();
        return null;
    } catch (Exception ex) {
        log.error(ex);
        ex.printStackTrace();
        return null;
    }
}