title: Spring Security: How to get details from the principal?
body: <p>Using spring boot and spring security, the details of user are available in principal object. But it has only few methods to retrieve details, like <code>getName()</code>.</p>
  
  <p>How do I get other details out of it?</p>
  
  <p>Currently my class looks like this</p>
  
  <pre><code>@SpringBootApplication
  @RestController
  public class DemoOAuth2Application {
  
      @RequestMapping("/user")
      public Principal user(Principal principal) {
          return principal;
      }
  
  
      public static void main(String[] args) {
          SpringApplication.run(DemoOAuth2Application.class, args);
      }
  }
  </code></pre>
  
  <p>It returns this,</p>
  
  <pre><code>{
    "authorities": [
      {
        "authority": "ROLE_USER"
      }
    ],
    "details": {
      "remoteAddress": "0:0:0:0:0:0:0:1",
      "sessionId": "43Fxxxxxx",
      "tokenValue": "ya29.xxxxxxxxx",
      "tokenType": "Bearer",
      "decodedDetails": null
    },
    "authenticated": true,
    "userAuthentication": {
      "authorities": [
        {
          "authority": "ROLE_USER"
        }
      ],
      "details": {
        "id": "106xxxxx",
        "email": "xxxxxxxx@gmail.com",
        "verified_email": true,
        "name": "xxxx yyyyyy",
        "given_name": "xxxxxx",
        "family_name": "yyyyy",
        "link": "https://plus.google.com/xxxxxxxxxx",
        "picture": "https://lh5.googleusercontent.com/xxxxxx/photo.jpg",
        "locale": "en"
      },
      "authenticated": true,
      "principal": "106xxxxx",
      "credentials": "N/A",
      "name": "106xxxxxxx"
    },
    "principal": "106xxxxxxxxxxx",
    "clientOnly": false,
    "credentials": "",
    "oauth2Request": {
      "clientId": "xxxxxxxxx.apps.googleusercontent.com",
      "scope": [],
      "requestParameters": {},
      "resourceIds": [],
      "authorities": [],
      "approved": true,
      "refresh": false,
      "redirectUri": null,
      "responseTypes": [],
      "extensions": {},
      "refreshTokenRequest": null,
      "grantType": null
    },
    "name": "106xxxxxxxxxx"
  }
  </code></pre>
  
  <p>But instead of returning all the data, I'd like to return only specific data I need. How do I get that data(specifically email, name, link, picture). </p>