
/*
 *  Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
*/
package oracle.jcs.ws.sample.oauth.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.UriInfo;

@Path ("/helloworld")
public class HelloWorld
{
  @Context 
    SecurityContext securityContext;
  
  public HelloWorld()
  {
  }
  
  @GET
  @Path("sayHello")
  @Produces("text/plain")
  public String sayHello() 
  {
     return "Hello World!";
  }
  
  @GET
  @Path("sayHelloWithName")
  @Produces("text/plain")
  public String sayHelloWithName(@QueryParam("name")String name) 
  {
      String user = "";
      if (securityContext!=null){
          if( securityContext.getUserPrincipal()!=null){
          user=securityContext.getUserPrincipal().getName();
          }else{
          user="UserPrincipal is null.";
          }
      }
          else{
              user="securityContext is null.";
          }
     return String.format("Hello %s",user);
  }  
}
