title: Why is GlobalAuthenticationConfigurerAdapter.init() invisible?
body: <p>I am trying to use a <code>GlobalAuthenticationConfigurerAdapter</code> to hook up a custom <code>UserDetailsService</code> to the <a href="https://github.com/spring-guides/tut-spring-security-and-angular-js/blob/master/oauth2/authserver/src/main/java/demo/AuthserverApplication.java" rel="nofollow"><code>AuthserverApplication.java</code></a> root class of <a href="https://github.com/spring-guides/tut-spring-security-and-angular-js/tree/master/oauth2" rel="nofollow">this sample Spring Boot OAuth2 sample app</a>.  </p>
  
  <p>The <a href="http://projects.spring.io/spring-security-oauth/docs/oauth2.html#grant-types" rel="nofollow">Spring OAuth2 Developer Guide</a> says to use a <code>GobalAuthenticationConfigurerAdapter</code> to hook up the <code>UserDetailsService</code>.  And <a href="http://ryanjbaxter.com/2015/01/06/securing-rest-apis-with-spring-boot/" rel="nofollow">I modified code from the example in this blog post</a>.  </p>
  
  <p>However, when I try to launch the modified <code>authserver</code> app using <code>mvn spring-boot:run</code>, the following root error is reported:  </p>
  
  <pre><code>nested exception is java.lang.NoSuchMethodException:  
  demo.AuthserverApplication$WebSecurityConfiguration$$EnhancerBySpringCGLIB$$43683c11.&lt;init&gt;()  
  </code></pre>
  
  <p>The complete log from the <code>mvn spring-boot:run</code> including the full stack trace of the error message <a href="https://jumpshare.com/v/fBM6hYgwVi0i90a9lD2Z" rel="nofollow">can be read at a file sharing site by clicking on this link</a>.  </p>
  
  <p><strong>I then read <a href="http://docs.spring.io/autorepo/docs/spring-security/4.0.4.RELEASE/apidocs/org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.html" rel="nofollow">the documentation for <code>GlobalAuthenticationConfigurerAdapter</code></a>, and confirmed that there is an <code>init()</code> method.</strong>  </p>
  
  <p><strong>What specific changes need to be made to the code below (or the other code in <a href="https://github.com/spring-guides/tut-spring-security-and-angular-js/tree/master/oauth2" rel="nofollow">the GitHub sample app</a>) in order to resolve this error and successfully hook up the custom <code>UserDetailsService</code> to the sample GitHub app?</strong>  </p>
  
  <hr/>  
  
  <p><strong>REPRODUCING THE PROBLEM ON YOUR MACHINE:</strong>  </p>
  
  <hr/>  
  
  <p>You can reproduce this problem on any machine within minutes by re-creating my steps as follows:  </p>
  
  <p>1.) Download the Spring Oauth2 sample apps onto your computer by typing:  </p>
  
  <pre><code>git clone https://github.com/spring-guides/tut-spring-security-and-angular-js/  
  </code></pre>
  
  <p>2.) Navigate to <code>tut-spring-security-and-angular-js/tree/master/oauth2/authserver</code>.  This is the app that is breaking.  When you type <code>mvn spring-boot:run</code> without making any changes, it should launch correctly.  But then make the following changes to re-create the problem:  </p>
  
  <p>3.) Added the following to <code>AuthserverApplication.java</code> to connect a custom <code>UserDetailsService</code>:  </p>
  
  <pre><code>@Configuration
  class WebSecurityConfiguration extends GlobalAuthenticationConfigurerAdapter {
  
      @Autowired
      Users users;
  
      @Override
      public void init(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(users);
      }
  
  }
  </code></pre>
  
  <p>4.) Add the following <code>Users.java</code> class to <a href="https://github.com/spring-guides/tut-spring-security-and-angular-js/tree/master/oauth2/authserver/src/main/java/demo" rel="nofollow">the <code>demo</code> package of the <code>authserver</code> app</a>, so that the <code>GlobalAuthenticationConfigurerAdapter</code> from <strong>3</strong> above points to a real custom <code>UserDetailsService</code>.  Note that I unhooked the JDBC so that there is no database dependency in this code sample:  </p>
  
  <pre><code>package demo;
  
  import java.util.List;
  import org.springframework.security.core.GrantedAuthority;
  import org.springframework.security.core.authority.AuthorityUtils;
  import org.springframework.security.core.userdetails.UserDetails;
  import org.springframework.security.core.userdetails.UsernameNotFoundException;
  import org.springframework.security.provisioning.UserDetailsManager;
  import org.springframework.stereotype.Service;
  
  @Service
  class Users implements UserDetailsManager {
  
      @Override
      public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
          String password;
          List&lt;GrantedAuthority&gt; auth = AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER");
          if (username.equals("Samwise")) {
              auth = AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_HOBBIT");
              password = "TheShire";
          }
          else if (username.equals("Frodo")){
              auth = AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_HOBBIT");
              password = "MyRing";
          }
          else{throw new UsernameNotFoundException("Username was not found. ");}
          return new org.springframework.security.core.userdetails.User(username, password, auth);
      }
  
      @Override
      public void createUser(UserDetails user) {// TODO Auto-generated method stub
      }
  
      @Override
      public void updateUser(UserDetails user) {// TODO Auto-generated method stub
      }
  
      @Override
      public void deleteUser(String username) {// TODO Auto-generated method stub
      }
  
      @Override
      public void changePassword(String oldPassword, String newPassword) {
          // TODO Auto-generated method stub
      }
  
      @Override
      public boolean userExists(String username) {
          // TODO Auto-generated method stub
          return false;
      }
  }
  </code></pre>
  
  <p>The complete code of the modified <code>AuthserverApplication.java</code>, including the new <code>GlobalAuthenticationConfigurerAdapter</code> <a href="https://jumpshare.com/v/Xu2yl7qnvFWxzWuklp2N" rel="nofollow">can be found at a file sharing site by clicking on this link</a>.</p>
  
  <p>5.) Type <code>mvn spring-boot:run</code> to try to launch the <code>authserver</code> app.  This will trigger the <code>nested exception is java.lang.NoSuchMethodException: demo.AuthserverApplication$WebSecurityConfiguration$$EnhancerBySpringCGLIB$$43683c11.&lt;init&gt;()</code> error described above.    </p>