Package org.springframework.security

Examples of org.springframework.security.BadCredentialsException


        panel.setBorder(GuiStandardUtils.createEvenlySpacedBorder(UIConstants.ONE_SPACE));
        return panel;
    }

    private void loginWithBadCredentials() {
        throw new BadCredentialsException("Wrong username/password");
    }
View Full Code Here


    /**
     * Authenticate a token
     */
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        if( authentication == BAD_CREDENTIALS ) {
            throw new BadCredentialsException( "Bad credentials" );
        } else if( authentication == LOCKED ) {
            throw new LockedException( "Account is locked" );
        }
        return authentication;
    }
View Full Code Here

      case success:
        UserDetails userDetails = _userDetailsService.loadUserByUsername(String.valueOf(token.getUserId()));
        return new FacebookAuthenticationToken(userDetails.getAuthorities(),
            token.getUserId(), token.getSessionKey());
      case failure:
        throw new BadCredentialsException("Log in failed - identity could not be verified");
      case error:
        throw new AuthenticationServiceException("Error message from server: " + token.getErrorMessage());
    }

    // unreachable
View Full Code Here

            case success:
                UserDetails userDetails = _userDetailsService.loadUserByUsername(String.valueOf(token.getUserId()));
                return new FacebookAuthenticationToken(userDetails.getAuthorities(),
                        token.getUserId(), token.getSessionKey());
            case failure:
                throw new BadCredentialsException("Log in failed - identity could not be verified");
            case error:
                throw new AuthenticationServiceException("Error message from server: " + token.getErrorMessage());
        }

        // unreachable
View Full Code Here

            break;
          }
        }
        // force the prompt for credentials
        getAuthenticationEntryPoint()
            .commence( request, response, new BadCredentialsException( "Clearing Basic-Auth" ) );
        return;
      } else if ( expiredCookie != null ) {
        // Session is expired but this request does not include basic-auth, drop a cookie to keep track of this event.
        Cookie c = new Cookie( "session-flushed", "true" );
        c.setPath( request.getContextPath() != null ? request.getContextPath() : "/" );
        c.setMaxAge( -1 );
        response.addCookie( c );
      }
    } else {
      String header = request.getHeader( "Authorization" );
      if ( header != null && header.indexOf( "Basic" ) == 0
          && SecurityContextHolder.getContext().getAuthentication() == null ) {
        // Session is valid, but Basic-auth is supplied. Check to see if the session end cookie we created is present,
        // if so, force reauthentication.

        Cookie[] cookies;
        cookies = request.getCookies();
        if ( cookies != null ) {
          for ( Cookie c : cookies ) {
            if ( "session-flushed".equals( c.getName() ) ) {
              c.setMaxAge( 0 );
              c.setPath( request.getContextPath() != null ? request.getContextPath() : "/" );
              response.addCookie( c );
              getAuthenticationEntryPoint().commence( request, response,
                  new BadCredentialsException( "Clearing Basic-Auth" ) );
              return;
            }
          }
        }
      }
View Full Code Here

            userDetailsChecker.check(userDetails);
            return new FederationAuthenticationToken(userDetails, authentication.getCredentials(),
                    userDetails.getAuthorities(), userDetails, wfRes);
        } catch (Exception e) {
            LOG.error("Failed to validate SignIn request", e);
            throw new BadCredentialsException(e.getMessage(), e);
        }
    }
View Full Code Here

            return null;
        }

        // Ensure credentials are provided
        if ((authentication.getCredentials() == null) || "".equals(authentication.getCredentials())) {
            throw new BadCredentialsException(messages.getMessage("FederationAuthenticationProvider.noSignInRequest",
                    "Failed to get SignIn request"));
        }

        FederationAuthenticationToken result = null;
       
View Full Code Here

        RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
       
        boolean isAnonymous = workflowUserManager.isCurrentUserAnonymous();
        UserSecurity us = DirectoryUtil.getUserSecurity();
        if (us != null && us.getForceSessionTimeout() && !isAnonymous) {
            throw new BadCredentialsException(ResourceBundleUtil.getMessage("authentication.failed.sessionTimeOut"));
        }
       
        Authentication auth = null;

        // check for username/password in request
        String username = super.obtainUsername(request);
        String password = super.obtainPassword(request);

        String loginAs = request.getParameter("loginAs");
        String loginHash = request.getParameter("hash");
       
        // Place the last username attempted into HttpSession for views
        HttpSession session = request.getSession(false);

        if (session != null || getAllowSessionCreation()) {
            request.getSession().setAttribute(SPRING_SECURITY_LAST_USERNAME_KEY, TextUtils.escapeEntities(username));
        }

        if (username != null && (password != null || loginHash != null)) {
            User currentUser = null;

            //diable master login based on UserSecurity
            if (us != null && us.getDisableHashLogin()) {
                loginAs = null;
            }
           
            if (loginAs != null) {
                String masterLoginUsername = getSetupManager().getSettingValue("masterLoginUsername");
                String masterLoginPassword = getSetupManager().getSettingValue("masterLoginPassword");
               
                //decryt masterLoginPassword
                masterLoginPassword = SecurityUtil.decrypt(masterLoginPassword);

                if ((masterLoginUsername != null && masterLoginUsername.trim().length() > 0) &&
                        (masterLoginPassword != null && masterLoginPassword.trim().length() > 0)) {

                    User master = new User();
                    master.setUsername(masterLoginUsername.trim());
                    master.setPassword(StringUtil.md5Base16(masterLoginPassword.trim()));

                    if (username.trim().equals(master.getUsername()) &&
                            ((password != null && StringUtil.md5Base16(password.trim()).equalsIgnoreCase(master.getPassword())) ||
                            (loginHash != null && loginHash.trim().equalsIgnoreCase(master.getLoginHash())))) {
                        currentUser = directoryManager.getUserByUsername(loginAs);
                        if (currentUser != null) {
                            WorkflowUserDetails user = new WorkflowUserDetails(currentUser);
                           
                            auth = new UsernamePasswordAuthenticationToken(user, user.getUsername(), user.getAuthorities());
                            super.setDetails(request, (UsernamePasswordAuthenticationToken) auth);
                        } else {
                            LogUtil.info(getClass().getName(), "Authentication for user " + loginAs + ": " + false);
           
                            WorkflowHelper workflowHelper = (WorkflowHelper) AppUtil.getApplicationContext().getBean("workflowHelper");
                            workflowHelper.addAuditTrail("WorkflowHttpAuthProcessingFilter", "authenticate", "Authentication for user " + loginAs + ": " + false);
                       
                            throw new BadCredentialsException("");
                        }
                    }
                }
            } else {
                if (loginHash != null) {
                    password = loginHash;
                }
                if (password != null) {
                    // use existing authentication manager
                    try {
                        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username.trim(), password.trim());
                        super.setDetails(request, authRequest);

                        auth = getAuthenticationManager().authenticate(authRequest);

                        // no direct way in Spring Security 2, so use reflection to clear password in token
                        Field field = null;
                        try {
                            field = auth.getClass().getDeclaredField("credentials");
                            field.setAccessible(true);
                            field.set(auth, null);
                        } catch (Exception ex) {
                            LogUtil.error(getClass().getName(), ex, "Error clearing credentials in token");
                        } finally {
                            if (field != null) {
                                field.setAccessible(false);
                            }
                        }
                       
                        if (auth.isAuthenticated()) {
                            currentUser = directoryManager.getUserByUsername(username);
                        }
                    } catch (BadCredentialsException be) {
                        LogUtil.info(getClass().getName(), "Authentication for user " + ((loginAs == null) ? username : loginAs) + ": " + false);
           
                        WorkflowHelper workflowHelper = (WorkflowHelper) AppUtil.getApplicationContext().getBean("workflowHelper");
                        workflowHelper.addAuditTrail("WorkflowHttpAuthProcessingFilter", "authenticate", "Authentication for user " + ((loginAs == null) ? username : loginAs) + ": " + false);
           
                        throw be;
                    }
                }
            }

            if (currentUser != null) {
                workflowUserManager.setCurrentThreadUser(currentUser.getUsername());
            }

            if (!"/WEB-INF/jsp/unauthorized.jsp".equals(request.getServletPath())) {
                LogUtil.info(getClass().getName(), "Authentication for user " + ((loginAs == null) ? username : loginAs) + ": " + true);
                WorkflowHelper workflowHelper = (WorkflowHelper) AppUtil.getApplicationContext().getBean("workflowHelper");
                workflowHelper.addAuditTrail("WorkflowHttpAuthProcessingFilter", "authenticate", "Authentication for user " + ((loginAs == null) ? username : loginAs) + ": " + true);
            }
        } else {
            if (us != null && us.getAuthenticateAllApi()) {
                throw new BadCredentialsException("");
            }
        }

        return auth;
    }
View Full Code Here

        // check credentials
        boolean validLogin = false;
        try {
            validLogin = directoryManager.authenticate(username, password);
        } catch (Exception e) {
            throw new BadCredentialsException(e.getMessage());
        }
        if (!validLogin) {
            throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
        }

        // get authorities
        Collection<Role> roles = directoryManager.getUserRoles(username);
        List<GrantedAuthority> gaList = new ArrayList<GrantedAuthority>();
View Full Code Here

TOP

Related Classes of org.springframework.security.BadCredentialsException

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.