Pages

Wednesday, March 26, 2014

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: weblogic


Problem:

The weblogic server throwing exception while establishing the secure URLConnection using url.openConnection method.


Error:


javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at edu.sfsu.identity.boxconnector.AbstractHttpClientSocket_TokenDB.getRequest(AbstractHttpClientSocket_TokenDB.java:551)
    at edu.sfsu.identity.boxconnector.BoxConnection.getUserByEmail(BoxConnection.java:71)
    at edu.sfsu.identity.boxconnector.BoxIdentityConnector.create(BoxIdentityConnector.java:199)
    at org.identityconnectors.framework.impl.api.local.operations.CreateImpl.create(CreateImpl.java:80)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.identityconnectors.framework.impl.api.local.operations.ConnectorAPIOperationRunnerProxy.invoke(ConnectorAPIOperationRunnerProxy.java:93)
    at $Proxy349.create(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.identityconnectors.framework.impl.api.local.operations.ThreadClassLoaderManagerProxy.invoke(ThreadClassLoaderManagerProxy.java:107)
    at $Proxy349.create(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.identityconnectors.framework.impl.api.DelegatingTimeoutProxy.invoke(DelegatingTimeoutProxy.java:107)
    at $Proxy349.create(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.identityconnectors.framework.impl.api.LoggingProxy.invoke(LoggingProxy.java:76)
    at $Proxy349.create(Unknown Source)
    at org.identityconnectors.framework.impl.api.AbstractConnectorFacade.create(AbstractConnectorFacade.java:123)
    at oracle.iam.connectors.icfcommon.prov.ICProvisioningManager.createObject(ICProvisioningManager.java:267)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.thortech.xl.adapterGlue.ScheduleItemEvents.adpBOXCON_PROSTASK_CREATEUSER.CREATEUSER(adpBOXCON_PROSTASK_CREATEUSER.java:109)
    at com.thortech.xl.adapterGlue.ScheduleItemEvents.adpBOXCON_PROSTASK_CREATEUSER.implementation(adpBOXCON_PROSTASK_CREATEUSER.java:54)
    at com.thortech.xl.client.events.tcBaseEvent.run(tcBaseEvent.java:196)
    at com.thortech.xl.dataobj.tcDataObj.runEvent(tcDataObj.java:2492)
    at com.thortech.xl.dataobj.tcScheduleItem.runMilestoneEvent(tcScheduleItem.java:2917)
    at com.thortech.xl.dataobj.tcScheduleItem.eventPostInsert(tcScheduleItem.java:547)
    at com.thortech.xl.dataobj.tcDataObj.insert(tcDataObj.java:602)
    at com.thortech.xl.dataobj.tcDataObj.save(tcDataObj.java:474)
    at com.thortech.xl.ejb.beansimpl.tcProvisioningOperationsBean.retryTasks(tcProvisioningOperationsBean.java:4042)
    at Thor.API.Operations.tcProvisioningOperationsIntfEJB.retryTasksx(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37)
    at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54)
    at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy326.retryTasksx(Unknown Source)
    at Thor.API.Operations.tcProvisioningOperationsIntfEJB_4xftoh_tcProvisioningOperationsIntfRemoteImpl.__WL_invoke(Unknown Source)
    at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:40)
    at Thor.API.Operations.tcProvisioningOperationsIntfEJB_4xftoh_tcProvisioningOperationsIntfRemoteImpl.retryTasksx(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:85)
    at $Proxy171.retryTasksx(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
    at $Proxy325.retryTasksx(Unknown Source)
    at Thor.API.Operations.tcProvisioningOperationsIntfDelegate.retryTasks(Unknown Source)
    at com.thortech.xl.webclient.actions.ResourceProfileProvisioningTasksAction.retryTasks(ResourceProfileProvisioningTasksAction.java:702)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
    at com.thortech.xl.webclient.actions.tcLookupDispatchAction.execute(tcLookupDispatchAction.java:133)
    at com.thortech.xl.webclient.actions.tcActionBase.execute(tcActionBase.java:894)
    at com.thortech.xl.webclient.actions.tcAction.execute(tcAction.java:213)
    at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at com.thortech.xl.webclient.security.CSRFFilter.doFilter(CSRFFilter.java:76)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at oracle.iam.platform.auth.web.PwdMgmtNavigationFilter.doFilter(PwdMgmtNavigationFilter.java:121)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at oracle.iam.platform.auth.web.OIMAuthContextFilter.doFilter(OIMAuthContextFilter.java:108)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
    at java.security.AccessController.doPrivileged(Native Method)
    at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
    at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
    at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
    at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
    at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1649)
    at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:241)
    at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:235)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1206)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136)
    at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
    at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:893)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1165)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1149)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
    at edu.sfsu.identity.boxconnector.AbstractHttpClientSocket_TokenDB.getRequest(AbstractHttpClientSocket_TokenDB.java:531)
    ... 133 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:323)
    at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:217)
    at sun.security.validator.Validator.validate(Validator.java:218)
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1185)
    ... 146 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:318)
    ... 152 more



Cause:

The external application ssl certificates are not available in the DemoTrust.jks and cacerts in the weblogic key stores.

Solution:

1. login to the weblogic server
2. Download the SSL certicate using the openssl as follows.
    echo -n | openssl s_client -connect app.box.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > server.cert
3. Go to the $JAVA_HOME/jre/lib/security and execute the following command to import the server cert into the cacerts key store

 keytool -importcert -keystore cacerts -storepass <Key Store Password> -alias server -file server.crt

The default password for cacerts is changeit

4. Go to the $WL_HOME/server/lib and execute the following command to import the server cert into the DemoTrust.jks key store


 keytool -importcert -keystore DemoTrust.jks -storepass <Key Store Password> -alias server -file server.crt

The default password for DemoTrust.jks is DemoTrustKeyStorePassPhrase

5. Restart the Web Logic Server with related to the OIM Server

The issue will be resolved.

java.lang.ClassCastException: weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection

Problem:

The Oracle Identity Manager throwing the exception in weblogic server while connecting to the external application using the HttpsURLConnection class.

Error:


java.lang.ClassCastException: weblogic.net.http.SOAPHttpsURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection
    at edu.sfsu.identity.boxconnector.AbstractHttpClientSocket_TokenDB.getRequest(AbstractHttpClientSocket_TokenDB.java:518)
    at edu.sfsu.identity.boxconnector.BoxConnection.getUserByEmail(BoxConnection.java:71)
    at edu.sfsu.identity.boxconnector.BoxIdentityConnector.create(BoxIdentityConnector.java:199)
    at org.identityconnectors.framework.impl.api.local.operations.CreateImpl.create(CreateImpl.java:80)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.identityconnectors.framework.impl.api.local.operations.ConnectorAPIOperationRunnerProxy.invoke(ConnectorAPIOperationRunnerProxy.java:93)
    at $Proxy462.create(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.identityconnectors.framework.impl.api.local.operations.ThreadClassLoaderManagerProxy.invoke(ThreadClassLoaderManagerProxy.java:107)
    at $Proxy462.create(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.identityconnectors.framework.impl.api.DelegatingTimeoutProxy.invoke(DelegatingTimeoutProxy.java:107)
    at $Proxy462.create(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.identityconnectors.framework.impl.api.LoggingProxy.invoke(LoggingProxy.java:76)
    at $Proxy462.create(Unknown Source)
    at org.identityconnectors.framework.impl.api.AbstractConnectorFacade.create(AbstractConnectorFacade.java:123)
    at oracle.iam.connectors.icfcommon.prov.ICProvisioningManager.createObject(ICProvisioningManager.java:267)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.thortech.xl.adapterGlue.ScheduleItemEvents.adpBOXCON_PROSTASK_CREATEUSER.CREATEUSER(adpBOXCON_PROSTASK_CREATEUSER.java:109)
    at com.thortech.xl.adapterGlue.ScheduleItemEvents.adpBOXCON_PROSTASK_CREATEUSER.implementation(adpBOXCON_PROSTASK_CREATEUSER.java:54)
    at com.thortech.xl.client.events.tcBaseEvent.run(tcBaseEvent.java:196)
    at com.thortech.xl.dataobj.tcDataObj.runEvent(tcDataObj.java:2492)
    at com.thortech.xl.dataobj.tcScheduleItem.runMilestoneEvent(tcScheduleItem.java:2917)
    at com.thortech.xl.dataobj.tcScheduleItem.eventPostInsert(tcScheduleItem.java:547)
    at com.thortech.xl.dataobj.tcDataObj.insert(tcDataObj.java:602)
    at com.thortech.xl.dataobj.tcDataObj.save(tcDataObj.java:474)
    at com.thortech.xl.ejb.beansimpl.tcProvisioningOperationsBean.retryTasks(tcProvisioningOperationsBean.java:4042)
    at Thor.API.Operations.tcProvisioningOperationsIntfEJB.retryTasksx(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37)
    at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54)
    at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy335.retryTasksx(Unknown Source)
    at Thor.API.Operations.tcProvisioningOperationsIntfEJB_4xftoh_tcProvisioningOperationsIntfRemoteImpl.__WL_invoke(Unknown Source)
    at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:40)
    at Thor.API.Operations.tcProvisioningOperationsIntfEJB_4xftoh_tcProvisioningOperationsIntfRemoteImpl.retryTasksx(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:85)
    at $Proxy171.retryTasksx(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
    at $Proxy334.retryTasksx(Unknown Source)
    at Thor.API.Operations.tcProvisioningOperationsIntfDelegate.retryTasks(Unknown Source)
    at com.thortech.xl.webclient.actions.ResourceProfileProvisioningTasksAction.retryTasks(ResourceProfileProvisioningTasksAction.java:702)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
    at com.thortech.xl.webclient.actions.tcLookupDispatchAction.execute(tcLookupDispatchAction.java:133)
    at com.thortech.xl.webclient.actions.tcActionBase.execute(tcActionBase.java:894)
    at com.thortech.xl.webclient.actions.tcAction.execute(tcAction.java:213)
    at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at com.thortech.xl.webclient.security.CSRFFilter.doFilter(CSRFFilter.java:76)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at oracle.iam.platform.auth.web.PwdMgmtNavigationFilter.doFilter(PwdMgmtNavigationFilter.java:121)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at oracle.iam.platform.auth.web.OIMAuthContextFilter.doFilter(OIMAuthContextFilter.java:108)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
    at java.security.AccessController.doPrivileged(Native Method)
    at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
    at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
    at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
    at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
    at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)


Cause:

The Sun Implementation HttpsURLConnection not using the weblogic server while creating  URLConnection instance using the url.openConnection.

Solution:

1. Login to the Web Logic Server Machine.
2  Go to the $DOMAIN_HOME/bin directory and edit the setDomainEnv.sh file and add the following system property to the JAVA_OPTIONS
JAVA_OPTIONS="${JAVA_OPTIONS} -DUseSunHttpHandler=true"

3. Restart the Web Logic managed Servers with related to Oracle Identity Manager.

The issue will be resolved.




Friday, March 7, 2014

Box.com User CRUD API Example

Box.com User CRUD API Example

The Box REST API end point Usage examples are Create User, Update User, Add Email Alias to the User, Get Email Aliases for the User, Update Primary Email Account, Remove the Existing Primary email Account  as an Alias, and Remove the User from the box.com

Pre-Requisite

1. Download and Install Gradle

Creating Eclipse Project Using Gradle

1. Set the Java Home Environment Variable

export JAVA_HOME=/usr/lib/jvm/java

2. Set the Gradle Home Environment Variable

export GRADLE_HOME=/home/gradle/gradle-1.10

3. Create the eclipse Project, and source Directory

    mkdir box-api-usage
    mkdir box-api-usage/src
    mkdir box-api-usage/src/main
    mkdir box-api-usage/src/main/java
    mkdir box-api-usage/src/main/resources

4. Create the build.gradle file in the box-api-usage directory

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'

repositories{
                mavenCentral()
        }

dependencies{
        compile 'org.apache.httpcomponents:httpclient:4.2.2'
        compile 'org.slf4j:slf4j-api:1.7.5','org.slf4j:slf4j-log4j12:1.7.5'
        compile 'com.google.code.gson:gson:2.2.2'

}
mainClassName='box.api.usage.client.BoxAPIUsage'

5. Create the Eclipse Project
  gradle cleanEclipse eclipse

6. Import the Project into the Eclipse

File --> Import --> Existing Project Into Workspace --> Next -->Select box-api-usage directory and click finish. It will create the eclipse project directory.

Get the Access Token from Box.com



Convert the Access Token to Map Object

        GenerateBoxCode accessCode= new GenerateBoxCode();
        String accessToken=accessCode.getAccessToken();
        Map<String, Object> tokenMap= null;
        Gson gson= new Gson();
        tokenMap=gson.fromJson(accessToken, Map.class);
        String accessToken= tokenMap.get("access_token");
        System.out.println(tokenMap);


Create User in Box.com


1. Build Create Request Attributes

  String emailId="<Replace With Your Email Id>";
  String displayName="<Replace With Your Display Name>";
  String role="<Replace With your Role>";
  String id="";
  Gson gson= new Gson();

  Map<String, String> createRequest= new HashMap<String,String>();
  createRequest.put("login", emailId);
  createRequest.put("name", displayName);
  createRequest.put("role", role);

2. Convert Map object to Json Object
      
  String jsonCreateRequest= gson.toJson(createRequest);

3. Send the Post Request to create the User in Box.com
  
  HttpClient client= new DefaultHttpClient();
  HttpPost post= new HttpPost(provisionEndPoint);
  post.addHeader("Authorization", "Bearer " + accessToken);
  try
  {
     post.setEntity(new StringEntity(jsonCreateRequest));
     HttpResponse response= client.execute(post);
     int statusCode=response.getStatusLine().getStatusCode();

     System.out.println(String.format("Response Status Code : %d" , statusCode));
     if( statusCode == 200 || statusCode == 201)
     {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    Map<String, Object> data= gson.fromJson(strresponse, Map.class);
                    id=data.get("id").toString();
                    System.out.println(String.format("Raw Jason Data : %s" , strresponse));
                    EntityUtils.consume(entity);
                }
     }
      else
      {
         System.out.println("User Creation Error");
      }
   } catch (UnsupportedEncodingException e)
   {
      e.printStackTrace();
   }
   finally
   {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
     }
  

Update User in Box.com


1. Build Update Request Attributes

  displayName="<Replace With Your Display Name>";



  Map<String, String> updateRequest= new HashMap<String,String>();

  updateRequest.put("name", displayName);



2. Convert Map object to Json Object

      
  String jsonUpdateRequest= gson.toJson(updateRequest);

3. Send the PUT Request to create the User in Box.com

        HttpClient client= new DefaultHttpClient();
       
        HttpPut put= new HttpPut(provisionEndPoint+"/"+id);
        put.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            put.setEntity(new StringEntity(jsonUpdateRequest));
            HttpResponse response= client.execute(put);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 200 || statusCode == 201)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    Map<String, Object> data= gson.fromJson(strresponse, Map.class);
                    id=data.get("id").toString();
                    System.out.println(String.format("Raw Jason Data : %s" , strresponse));
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Update Failed Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }


Add Aliases for the User in Box.com


String aliasName="<Replace With your Alias Name>";
String aliasId="";
1. Build Add Alias Request Attributes

  Map<String, String> addEmailAlias= new HashMap<String,String>();  addEmailAlias.put("email", aliasName);

2. Convert Map object to Json Object
      
  String jsonEmailAliasRequest= gson.toJson(addEmailAlias);

3. Send the POST Request to create the User in Box.com

        HttpClient client= new DefaultHttpClient();
       
        HttpPost post= new HttpPost(provisionEndPoint+"/"+id+"/email_aliases");
        post.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            post.setEntity(new StringEntity(jsonEmailAliasRequest));
            HttpResponse response= client.execute(post);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 200 || statusCode == 201)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    Map<String, Object> data= gson.fromJson(strresponse, Map.class);
                    aliasId=data.get("id").toString();
                    System.out.println(String.format("Raw Jason Data : %s" , strresponse));
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Add Alias Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }

Update Primary Email User in Box.com



1. Build Update Request Attributes

  Map<String, String> updateEmail= new HashMap<String,String>();  updateEmail.put("login", aliasName);

2. Convert Map object to Json Object
      
  String jsonEmailUpdateRequest= gson.toJson(updateEmail);

3. Send the PUT Request to update the User in Box.com

        HttpClient client= new DefaultHttpClient();
       
        HttpPut put= new HttpPut(provisionEndPoint+"/"+id);
        put.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            put.setEntity(new StringEntity(jsonEmailUpdateRequest));
            HttpResponse response= client.execute(put);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 200 || statusCode == 201)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    Map<String, Object> data= gson.fromJson(strresponse, Map.class);
                    id=data.get("id").toString();
                    System.out.println(String.format("Raw Jason Data : %s" , strresponse));
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Update Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }



Get All Email Aliases for the User in Box.com


1. Send the Get Request to Get All Email Aliases for the User in Box.com
        Map<String, List<Map<String, String>>> data=null;
        HttpClient client= new DefaultHttpClient();
        HttpGet get= new HttpGet(provisionEndPoint+"/"+id+"/email_aliases");
        get.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            HttpResponse response= client.execute(get);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 200 || statusCode == 201)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    data= gson.fromJson(strresponse, Map.class);
                    System.out.println(String.format("Raw Jason Data : %s" , data));
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Get Alias Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }


Remove Aliases for the User in Box.com

 1. Send the Delete Request to Delete the Email Alias for the User in Box.com

        HttpClient client= new DefaultHttpClient();
        HttpDelete delete= new HttpDelete(provisionEndPoint+"/"+id+"/email_aliases/"+aliasId);
        delete.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            HttpResponse response= client.execute(delete);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 204)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    System.out.println(strresponse);
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Alias Deletion Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }
 

Remove the User from Box.com

 1. Send the Delete Request to Delete the User in Box.com

        HttpClient client= new DefaultHttpClient();
        HttpDelete delete= new HttpDelete(provisionEndPoint+"/"+id);
        delete.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            HttpResponse response= client.execute(delete);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 204)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    System.out.println(strresponse);
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Deletion Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }
 

Sample Code 

package box.api.usage.client;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import com.google.gson.Gson;


public class BoxAPIUsage {

    public BoxAPIUsage() {
       
    }

    private static String emailId="<Replace Your BoxUser Login Email>";
    private static String displayName="<Replace Your Display Name>";
    private static String role="user";
    private static String accessToken="";
    private static String provisionEndPoint = "https://api.box.com/2.0/users";
    private static String emailAlias="<Replacing Your Alias to modify the Primary Email Account>";
    private static Gson gson= new Gson();
   
    public static void main(String[] args) {
       
        GenerateBoxCode accessCode= new GenerateBoxCode();
        String accessToken=accessCode.getAccessToken();
        Map<String, Object> tokenMap= null;
        tokenMap=gson.fromJson(accessToken, Map.class);
       
        accessToken=tokenMap.get("access_token").toString();
        System.out.println(accessToken);
        // Creating User
        String id=createUser(accessToken);
        System.out.println("Created ID :"+id);
        // Updating user DsiplayName
        id=updateUser(accessToken, id);
        // Adding alias to the user to modify the primary email account
        String aliasId=addAlias(accessToken, id);
        System.out.println("Alias id :"+aliasId);
        //Updating Email Account
        id=updateEmailUser(accessToken, id);
        // Getting the Email Aliases to remove the existing email
        Map<String, List<Map<String, String>>> aliases= getAliases(accessToken, id);
        if(aliases != null)
        {
            List<Map<String, String>> entries= aliases.get("entries");
            for (Map<String, String> map : entries)
            {
                aliasId=map.get("id");
                // removing the Email Alias
                removeAlias(accessToken, id, aliasId);
            }
        }
        // Removing the User
        removeUser(accessToken, id);
    }
   
    public static String createUser(String accessToken)
    {
        String id="";
        Map<String, String> createRequest= new HashMap<String,String>();
        createRequest.put("login", emailId);
        createRequest.put("name", displayName);
        createRequest.put("role", role);

       
        String jsonCreateRequest= gson.toJson(createRequest);
       
        HttpClient client= new DefaultHttpClient();
       
        HttpPost post= new HttpPost(provisionEndPoint);
        post.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            post.setEntity(new StringEntity(jsonCreateRequest));
            HttpResponse response= client.execute(post);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 200 || statusCode == 201)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    Map<String, Object> data= gson.fromJson(strresponse, Map.class);
                    id=data.get("id").toString();
                    System.out.println(String.format("Raw Jason Data : %s" , strresponse));
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Creation Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }

       
        return id;
    }
    public static String updateUser(String accessToken,String boxid)
    {
        String id="";
        displayName=displayName+ "M";
        Map<String, String> updateRequest= new HashMap<String,String>();
        updateRequest.put("name", displayName);
       
        String jsonUpdateRequest= gson.toJson(updateRequest);
       
        HttpClient client= new DefaultHttpClient();
       
        HttpPut put= new HttpPut(provisionEndPoint+"/"+boxid);
        put.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            put.setEntity(new StringEntity(jsonUpdateRequest));
            HttpResponse response= client.execute(put);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 200 || statusCode == 201)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    Map<String, Object> data= gson.fromJson(strresponse, Map.class);
                    id=data.get("id").toString();
                    System.out.println(String.format("Raw Jason Data : %s" , strresponse));
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Creation Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }
       
        return id;
    }

    public static String addAlias(String accessToken,String boxid)
    {
        String aliasId="";
        displayName=displayName+ "M";
        Map<String, String> addEmailAlias= new HashMap<String,String>();
        addEmailAlias.put("email", emailAlias);
       
       
        String jsonEmailAliasRequest= gson.toJson(addEmailAlias);
       
        HttpClient client= new DefaultHttpClient();
       
        HttpPost post= new HttpPost(provisionEndPoint+"/"+boxid+"/email_aliases");
        post.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            post.setEntity(new StringEntity(jsonEmailAliasRequest));
            HttpResponse response= client.execute(post);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 200 || statusCode == 201)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    Map<String, Object> data= gson.fromJson(strresponse, Map.class);
                    aliasId=data.get("id").toString();
                    System.out.println(String.format("Raw Jason Data : %s" , strresponse));
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Update Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }
       
        return aliasId;
    }

    public static Map<String, List<Map<String, String>>> getAliases(String accessToken,String boxid)
    {
        Map<String, List<Map<String, String>>> data=null;
        HttpClient client= new DefaultHttpClient();
        HttpGet get= new HttpGet(provisionEndPoint+"/"+boxid+"/email_aliases");
        get.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            HttpResponse response= client.execute(get);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 200 || statusCode == 201)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    data= gson.fromJson(strresponse, Map.class);
                    System.out.println(String.format("Raw Jason Data : %s" , data));
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Get Aliases Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }
       
        return data;
    }

   
    public static void removeAlias(String accessToken,String boxid,String aliasId)
    {
        HttpClient client= new DefaultHttpClient();
        HttpDelete delete= new HttpDelete(provisionEndPoint+"/"+boxid+"/email_aliases/"+aliasId);
        delete.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            HttpResponse response= client.execute(delete);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 204)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    System.out.println(strresponse);
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Remove Alias Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }
    }

   
    public static String updateEmailUser(String accessToken,String boxid)
    {
        String id="";
        displayName=displayName+ "M";
        Map<String, String> updateEmail= new HashMap<String,String>();
        updateEmail.put("login", emailAlias);
       
        String jsonEmailUpdateRequest= gson.toJson(updateEmail);
       
        HttpClient client= new DefaultHttpClient();
       
        HttpPut put= new HttpPut(provisionEndPoint+"/"+boxid);
        put.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            put.setEntity(new StringEntity(jsonEmailUpdateRequest));
            HttpResponse response= client.execute(put);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 200 || statusCode == 201)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    Map<String, Object> data= gson.fromJson(strresponse, Map.class);
                    id=data.get("id").toString();
                    System.out.println(String.format("Raw Jason Data : %s" , strresponse));
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Update Email Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }
       
        return id;
    }

    public static void removeUser(String accessToken,String boxid)
    {
        HttpClient client= new DefaultHttpClient();
        HttpDelete delete= new HttpDelete(provisionEndPoint+"/"+boxid);
        delete.addHeader("Authorization", "Bearer " + accessToken);
        try
        {
            HttpResponse response= client.execute(delete);
            int statusCode=response.getStatusLine().getStatusCode();
            System.out.println(String.format("Response Status Code : %d" , statusCode));
            if( statusCode == 204)
            {
                HttpEntity entity=response.getEntity();
                if (entity != null) {
                   
                    BasicResponseHandler handler= new BasicResponseHandler();
                    String strresponse =handler.handleResponse(response);
                    System.out.println(strresponse);
                    EntityUtils.consume(entity);
                }
            }
            else
            {
                System.out.println("User Deletion Error");
            }
        } catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally
        {
            if(client != null)
            {
                client.getConnectionManager().shutdown();   
            }
        }
    }


}