Package org.springframework.security.userdetails

Examples of org.springframework.security.userdetails.UsernameNotFoundException


  @Override
  public UserDetails loadUserByUsername(String username)
      throws UsernameNotFoundException, DataAccessException {
    Users user = usersDao.findByName(username);
    if (user == null) {
      throw new UsernameNotFoundException("User test_user is not a valid user");
    }
   
    User userDetails = new User();
    userDetails.setUsername(user.getName());
    userDetails.setPassword(user.getPassword());
View Full Code Here


        if (user != null) {
            return new UserDetailsAdaptor(user);

        } else {
            throw new UsernameNotFoundException("UserDetailsService.loadUserByUsername()");
        }
    }
View Full Code Here

        user = new NotFoundUserDetails( principleName, e );
      }

      if ( user == null ) {
        user =
            new NotFoundUserDetails( principleName, new UsernameNotFoundException( "UserDetailsService " + delegate
                + " returned null for username " + username + ". " + "This is an interface contract violation" ) );
      }

      userCache.putUserInCache( user );
    }

    if ( user instanceof NotFoundUserDetails ) {
      UsernameNotFoundException e = ( (NotFoundUserDetails) user ).getOriginalException();
      throw new UsernameNotFoundException( e.getMessage(), e );
    }

    return user;
  }
View Full Code Here

        }
      } catch ( UsernameNotFoundException ignored ) {
        // ignore and continue;
      }
    }
    throw new UsernameNotFoundException( Messages.getInstance().getString(
      "UserRoleDaoUserDetailsService.ERROR_0001_USER_NOT_FOUND" ) );
  }
View Full Code Here

            roller = WebloggerFactory.getWeblogger();
        } catch (Exception e) {
            // Should only happen in case of 1st time startup, setup required
            log.debug("Ignorabale error getting Roller instance", e);
            // Thowing a "soft" exception here allows setup to procede
            throw new UsernameNotFoundException("User info not available yet.");
        }
        try {
            UserManager umgr = roller.getUserManager();
            User userData = null
            if (userName.startsWith("http://")) {
                if (userName.endsWith("/")) {
                    userName = userName.substring(0, userName.length() -1 );
                }
                try {
                    userData = umgr.getUserByAttribute(
                        UserAttribute.Attributes.OPENID_URL.toString(),
                        userName);
                } catch (WebloggerException ex) {
                    throw new DataRetrievalFailureException("ERROR in user lookup", ex);
                }
                String name;
                String password;
                GrantedAuthority[] authorities;
               
                // We are not throwing UsernameNotFound exception in case of
                // openid authentication in order to recieve user SREG attributes
                // from the authentication filter and save them               
                if (userData == null) {
                     authorities = new GrantedAuthority[1];
                     GrantedAuthority g = new GrantedAuthorityImpl("openidLogin");
                     authorities[0] = g;
                     name = "openid";
                     password = "openid";
                } else {
                     authorities =  getAuthorities(userData, umgr);
                     name = userData.getUserName();
                     password = userData.getPassword();
                }
                UserDetails usr = new org.springframework.security.userdetails.User(name, password, true, authorities);
                return  usr;
               
            } else {
                try {
                    userData = umgr.getUserByUserName(userName);
                } catch (WebloggerException ex) {
                    throw new DataRetrievalFailureException("ERROR in user lookup", ex);
                }
                if (userData == null) {
                    throw new UsernameNotFoundException("ERROR no user: " + userName);
                }
                GrantedAuthority[] authorities =  getAuthorities(userData, umgr);       
                return new org.springframework.security.userdetails.User(userData.getUserName(), userData.getPassword(), true, authorities);
            }           
        } catch (WebloggerException ex) {
View Full Code Here

        } catch (WebloggerException ex) {
            throw new DataRetrievalFailureException("ERROR in user lookup", ex);
        }

        if (user == null) {
            throw new UsernameNotFoundException("ERROR user: " + username + " not found while granting authorities");
        }

        int roleCount = roles.size() + (defaultRole != null ? 1 : 0);
        GrantedAuthority[] authorities = new GrantedAuthorityImpl[roleCount];
        int i = 0;
        for(String role : roles) {
            authorities[i++] = new GrantedAuthorityImpl(role);
        }
       
        if (defaultRole != null) {
            authorities[roleCount-1] = defaultRole;
        }

        if (authorities.length == 0) {
            // TODO: This doesn't seem like the right type of exception to throw here, but retained it, fixed the message
            throw new UsernameNotFoundException("User " + username + " has no roles granted and there is no default role set.");
        }

        return authorities;
    }
View Full Code Here

                sREGAttributesList);
            */
           
            // Username not found in Roller for this user, so throw exception
            // which will route user to the new user registration page.
            throw new UsernameNotFoundException("ERROR no user: new openid user");
        }
        return auth;
    }
View Full Code Here

      throw new UserRoleDaoUserDetailsServiceException( Messages.getInstance().getString(
          "UserRoleDaoUserDetailsService.ERROR_0003_DATA_ACCESS_EXCEPTION" ), e ); //$NON-NLS-1$
    }

    if ( user == null ) {
      throw new UsernameNotFoundException( Messages.getInstance().getString(
          "UserRoleDaoUserDetailsService.ERROR_0001_USER_NOT_FOUND" ) ); //$NON-NLS-1$
    }
    // convert IPentahoUser to a UserDetails instance
    List<IPentahoRole> userRoles = userRoleDao.getUserRoles( null, username );
    int authsSize = userRoles != null ? userRoles.size() : 0;
    GrantedAuthority[] auths = new GrantedAuthority[authsSize];
    int i = 0;
    for ( IPentahoRole role : userRoles ) {
      auths[i++] = new GrantedAuthorityImpl( role.getName() );
    }

    List<GrantedAuthority> dbAuths = new ArrayList<GrantedAuthority>( Arrays.asList( auths ) );
    addCustomAuthorities( user.getUsername(), dbAuths );

    // Store the Tenant ID in the session
    IPentahoSession session = PentahoSessionHolder.getSession();
    String tenantId = (String) session.getAttribute( IPentahoSession.TENANT_ID_KEY );
    if ( tenantId == null ) {
      ITenant tenant = JcrTenantUtils.getTenant( username, true );
      session.setAttribute( IPentahoSession.TENANT_ID_KEY, tenant.getId() );
    }

    if ( !StringUtils.isEmpty( defaultRoleString ) ) {
      defaultRole = new GrantedAuthorityImpl( defaultRoleString );
    }

    if ( defaultRole != null && !dbAuths.contains( defaultRole ) ) {
      dbAuths.add( defaultRole );
    }

    if ( dbAuths.size() == 0 ) {
      throw new UsernameNotFoundException( Messages.getInstance().getString(
          "UserRoleDaoUserDetailsService.ERROR_0002_NO_AUTHORITIES" ) ); //$NON-NLS-1$
    }

    GrantedAuthority[] arrayAuths = dbAuths.toArray( new GrantedAuthority[dbAuths.size()] );
View Full Code Here

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
        try {
            UserDetails user = userDetailsService.loadUserByUsername(username);
            if (user == null) {
                throw new UsernameNotFoundException(username);
            }
            return user;
        }
        catch (Exception e) {
            throw new DataAccessException(username) {
View Full Code Here

  public UserDetails loadUserByUsername(String username)
      throws UsernameNotFoundException, DataAccessException {

    int index = username.indexOf('_');
    if (index == -1)
      throw new UsernameNotFoundException(
          "username did not take the form type_value: " + username);

    String type = username.substring(0, index);
    String value = username.substring(index + 1);
View Full Code Here

TOP

Related Classes of org.springframework.security.userdetails.UsernameNotFoundException

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.