public static String createToken(Office365Configuration configuration) {
    log.info("createConnection");
    JsonWebToken webToken;

    try {
      webToken =
          new JsonWebToken(
              configuration.getPrincipalID(),
              configuration.getTenancy(),
              (new URI(configuration.getAuthURL())).getHost(),
              configuration.getAcsPrincipalID(),
              JWTTokenHelper.getCurrentDateTime(),
              60 * 60);

      final String[] clearText = new String[1];
      GuardedString.Accessor accessor =
          new GuardedString.Accessor() {
            @Override
            public void access(char[] clearChars) {
              clearText[0] = new String(clearChars);
            }
          };
      configuration.getSymetricKey().access(accessor);

      try {
        String assertion = JWTTokenHelper.generateAssertion(webToken, clearText[0]);
        String resource =
            String.format(
                "%s/%s@%s",
                configuration.getResourceID(),
                configuration.getApiEndPoint(),
                configuration.getTenancy());
        String token =
            JWTTokenHelper.getOAuthAccessTokenFromACS(
                configuration.getAuthURL(), assertion, resource);
        return token;
      } catch (Exception e) {
        log.error("Error creating token, error {0}", e);
      }
    } catch (URISyntaxException use) {
      log.error(
          "Error connecting to authetication server {0} error is {1}",
          configuration.getAuthURL(), use);
    }

    return null;
  }
 private Office365Connection(Office365Configuration configuration, String token) {
   this.configuration = configuration;
   this.token = token;
   log.ok("New Office365Connection for tenancy {0}", configuration.getTenancy());
 }