Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8950

Re: OAuth2SAMLBearerAssertion Authentication Problem

$
0
0

Hey mate,

 

I also have our desination in the XML (our web.xml is quite big)

 

<resource-ref>  <res-ref-name>sap_hcmcloud_core_odata</res-ref-name>  <res-type>com.sap.core.connectivity.api.http.HttpDestination</res-type></resource-ref>


I am not sure if it important but if I remember correctly we used the latest SDK and we are using Java Web as server (not tomcat).

 

Quick question first is your user logged in in SuccessFactors ? (in other words, do you get to the successfactors login screen ?) It might just be as easy as the SSO is not configured ?


I made a quick working example here:

package com.sample.sfsf;
import static java.net.HttpURLConnection.HTTP_OK;
import java.io.IOException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.security.auth.login.LoginContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import com.sap.core.connectivity.api.DestinationFactory;
import com.sap.core.connectivity.api.configuration.ConnectivityConfiguration;
import com.sap.core.connectivity.api.configuration.DestinationConfiguration;
import com.sap.core.connectivity.api.http.HttpDestination;
import com.sap.security.auth.login.LoginContextFactory;
@SuppressWarnings("javadoc")
@WebServlet("/ConnectSF") 
public class connectSF extends HttpServlet {
 /**  *   */  private static final long  serialVersionUID  = -4749334084832519842L;
 /*  * (non-Javadoc)  *   * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)  */
 @Override  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {  doPost(req, resp);  }
 /*  * (non-Javadoc)  *   * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)  */
 @Override  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {  ConnectivityConfiguration configuration = null;  HttpClient httpClient = null;  LoginContext loginContext = null;  try {  Context ctx = new InitialContext();  // login  loginContext = LoginContextFactory.createLoginContext("FORM");  loginContext.login();  // Get the configuration  DestinationFactory destinationFactory = (DestinationFactory) ctx.lookup(DestinationFactory.JNDI_NAME);  HttpDestination destination = (HttpDestination) destinationFactory.getDestination("sap_hcmcloud_core_odata");  configuration = (ConnectivityConfiguration) ctx.lookup("java:comp/env/connectivityConfiguration");  DestinationConfiguration destConfiguration = configuration.getConfiguration("sap_hcmcloud_core_odata");  // Create HTTP client  httpClient = destination.createHttpClient();  // Construct the URL for the metadata  // ----------------------------------------------------  String urlMetadata = destConfiguration.getProperty("URL") + "?" + "$metadata";  HttpGet httpGet = new HttpGet(urlMetadata);  HttpResponse httpResponse = httpClient.execute(httpGet);  HttpEntity entity = httpResponse.getEntity();  // Check response status code  int statusCode = httpResponse.getStatusLine().getStatusCode();  if (statusCode != HTTP_OK) {  resp.getWriter().print("Expected response status code is 200 but it is " + statusCode + " .");  } else {  resp.getWriter().print("data received");  }  // close the connection  entity.getContent().close();  } catch (Exception e) {  e.printStackTrace();  }  }
}


Cheers

Greg


Viewing all articles
Browse latest Browse all 8950

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>