2

I am trying to execute this google's directory api to signout users from my application. which is a POST call

POST https://admin.googleapis.com/admin/directory/v1/users/{userKey}/signOut

where userkey needs to be userEmail.

    private String m_strGoogleAdmin = null;

    public void TestSignout(String domain, String adminEmail, String p_strServiceAccountEmail,
            String p_strServiceAccountPkcs12FilePath, Boolean isAllScopes) {
        Collection<String> SCOPES = new ArrayList<String>();

        SCOPES = getScopes(isAllScopes);

        String pstr_AdminEmail = null;
        Configuration configObj = new GLoginManager(domain).getConfiguration();
        if (configObj != null && (configObj.getAdminEmail() != null && !(configObj.getAdminEmail().isEmpty()))) {
            pstr_AdminEmail = configObj.getAdminEmail();
        } else {
            pstr_AdminEmail = adminEmail;
        }

        HttpTransport httpTransport = new NetHttpTransport();
        
        JacksonFactory jsonFactory = new JacksonFactory();

        GoogleCredential credential = null;
        try {
            credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory)
                    .setServiceAccountId(p_strServiceAccountEmail).setServiceAccountScopes(SCOPES)
                    .setServiceAccountUser(pstr_AdminEmail) // adminEmail
                    .setServiceAccountPrivateKeyFromP12File(new java.io.File(p_strServiceAccountPkcs12FilePath))
                    .build();
            m_directoryService = new com.google.api.services.directory.Directory.Builder(httpTransport, jsonFactory, credential)
                    .setApplicationName("Directory ").build();//
            m_strGoogleAdmin = pstr_AdminEmail; // adminEmail
        } catch (Exception e) {
            ErrorHandler.errorHandler(this.getClass().getName(), e);
        }
    }
private Collection<String> getScopes(Boolean isAllScopes) {

        Collection<String> SCOPES = new ArrayList<String>()

        SCOPES.add("https://www.googleapis.com/auth/admin.directory.user");
        SCOPES.add("https://www.googleapis.com/auth/admin.directory.orgunit");
        SCOPES.add("https://www.googleapis.com/auth/admin.directory.group");
        SCOPES.add("https://www.googleapis.com/auth/admin.directory.user.security");
        return SCOPES;
    }

I think I have issue with my jar in my application may be conflicting

  • google-api-services-admin-directory-directory_v1-rev72-1.22.0
  • google-api-services-admin-directory-directory_v1-rev20210720-1.32.1

Can anyone just suggest how can i configure the issue i am getting to build the directory

com.google.apphosting.runtime.jetty9.JettyLogger warn: Error for /TestServletSignout (JettyLogger.java:30)
java.lang.ExceptionInInitializerError
    at com.google.api.services.directory.Directory$Builder.build(Directory.java:18690)
    at com.cloudcodes.gcontrol.backends.TestServletSignout.TestSignout(TestServletSignout.java:60)
    at com.cloudcodes.gcontrol.backends.TestServletSignout.doGet(TestServletSignout.java:71)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:848)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1780)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1767)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
    at com.google.apphosting.runtime.jetty9.ParseBlobUploadHandler.handle(ParseBlobUploadHandler.java:111)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1182)
    at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.doHandle(AppEngineWebAppContext.java:187)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:513)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:293)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
    at org.eclipse.jetty.server.Server.handle(Server.java:539)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:333)
    at com.google.apphosting.runtime.jetty9.RpcConnection.handle(RpcConnection.java:216)
    at com.google.apphosting.runtime.jetty9.RpcConnector.serviceRequest(RpcConnector.java:81)
    at com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:134)
    at com.google.apphosting.runtime.RequestRunner.dispatchServletRequest(RequestRunner.java:250)
    at com.google.apphosting.runtime.RequestRunner.dispatchRequest(RequestRunner.java:215)
    at com.google.apphosting.runtime.RequestRunner.run(RequestRunner.java:180)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:260)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: You are currently running with version 1.23.0 of google-api-client. You need at least version 1.31.1 of google-api-client to run version 1.32.1 of the Admin SDK API library.
    at com.google.common.base.Preconditions.checkState(Preconditions.java:200)
    at com.google.api.client.util.Preconditions.checkState(Preconditions.java:113)
    at com.google.api.services.directory.Directory.<clinit>(Directory.java:44)
    ... 34 more```

Anyone please help me with this?????
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449

1 Answers1

0

You are currently running with version 1.23.0 of google-api-client. You need at least version 1.31.1 of google-api-client to run version 1.32.1 of the Admin SDK API library

If you check the Setup guilde

It shows the latest is google-api-client-1.32.1.jar Have you tried updating to that?

Google APIs Client Library for Java

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Yes i have updated the ```google-api-client-1.32.1.jar``` but still i am having this issue and i have searched for many example. Didn't get any proper example or any solution regarding this Signout method for google-admin-sdk. – Saurabh Kohade Oct 02 '21 at 16:47
  • May i suggest if you updated to the current jar and it still says you need a the higher one that you didn't upgrade it properly. – Linda Lawton - DaImTo Oct 02 '21 at 17:16