title: Spring security Role cannot be converted to granted authority
body: <p><strong>User.java</strong></p>
  
  <pre><code>public class User implements Serializable{
      @Id
      @Size(min=5,max=15)
      @Column(name="username", unique=true)
      private String username;
  
      @OneToMany(mappedBy="user")
      private Collection&lt;Role&gt; roles;
  
  public User(User user) {
          this.username=user.username;
          this.roles=user.getRoles();
      }
  }
  </code></pre>
  
  <p><strong>Role.java</strong></p>
  
  <pre><code>public class Role implements Serializable{
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
  
      private String role;
  
      @ManyToOne
      @JoinColumn(name="username")
      private User user;
  }
  </code></pre>
  
  <p><strong>UserServiceImpl.java</strong></p>
  
  <pre><code>public class UserServiceImpl implements UserServiceDetails {
  
      private UserRepo userRepo;
  
      @Autowired
      public void setUserRepo(UserRepo userRepo) {
          this.userRepo = userRepo;
      }
  
      @Override
      public UserDetails loadUserByUsername(String username)
              throws UsernameNotFoundException {
          User user=userRepo.findUserByUsername(username);
          if(user == null) {
              throw new UsernameNotFoundException("Could not find user " + username);
          }
          CustomUser customUser=new CustomUser(user);
          return customUser;
      }
  
      public final static class CustomUser extends User implements UserDetails
      {
          public CustomUser(User user) {
              super(user);
          }
  
          @SuppressWarnings("unchecked")
          @Override
          public Collection&lt;? extends GrantedAuthority&gt; getAuthorities() {
              List&lt;GrantedAuthority&gt; authorities =
                      new ArrayList&lt;GrantedAuthority&gt;();
              authorities.addAll((Collection&lt;? extends GrantedAuthority&gt;) getRoles());
  
              return authorities;
          }
  
          @Override
          public boolean isAccountNonExpired() {
              return true;
          }
  
          @Override
          public boolean isAccountNonLocked() {
              return true;
          }
  
          @Override
          public boolean isCredentialsNonExpired() {
              return true;
          }
  
      }
  
  }
  </code></pre>
  
  <p><strong>SecurityCOnfig.java</strong></p>
  
  <pre><code>public class SecurityConfig extends WebSecurityConfigurerAdapter{
  
      @Autowired
      private UserDetailsService userDetailsService;
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth)
              throws Exception {
          auth
              .userDetailsService(userDetailsService); 
      }
  }
  </code></pre>
  
  <p><strong>Errors:</strong>
  Role cannot be cast to org.springframework.security.core.GrantedAuthority
  my roles table contain roles in the form string "user", "admin" etc</p>
  
  <p>Any suggestions?</p>
  
  <p>Thanks</p>