// Path: soap-server/src/main/java/com/cookbook/tutorial/service/Constants.java
// public class Constants {
//     public static final String DEFAULT_TOKEN = "ASD9807123#123POI";
// }
// 
// Path: webservice/src/main/java/com/cookbook/tutorial/service/InvalidEntityException.java
// @WebFault(name = "InvalidEntity", faultBean = "com.cookbook.tutorial.service.FaultBean")
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlRootElement
// public class InvalidEntityException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     /**
//      * Field containing the CookBook entity that caused the exception
//      */
//     private FaultBean faultBean;
// 
//     public InvalidEntityException(){
// 
//     }
// 
//     public InvalidEntityException(String message, FaultBean faultBean, Throwable cause) {
//         super(message, cause);
//         this.faultBean = faultBean;
//     }
// 
//     public InvalidEntityException(String message, FaultBean faultBean) {
//         super(message);
//         this.faultBean = faultBean;
//     }
// 
//     public FaultBean getFaultBean() {
//         return faultBean;
//     }
// 
//     public void setFaultBean(FaultBean faultBean) {
//         this.faultBean = faultBean;
//     }
// }
// 
// Path: webservice/src/main/java/com/cookbook/tutorial/service/NoSuchEntityException.java
// @WebFault(name = "NoSuchEntity", faultBean = "com.cookbook.tutorial.service.FaultBean")
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlRootElement
// public class NoSuchEntityException extends RuntimeException {
//     private static final long serialVersionUID = 1L;
// 
//     /**
//      * Field containing the CookBook entity that caused the exception
//      */
//     private FaultBean faultBean;
// 
//     public NoSuchEntityException(){
// 
//     }
// 
//     public NoSuchEntityException(String message, FaultBean faultBean, Throwable cause) {
//         super(message, cause);
//         this.faultBean = faultBean;
//     }
// 
//     public NoSuchEntityException(String message, FaultBean faultBean) {
//         super(message);
//         this.faultBean = faultBean;
//     }
// 
//     public FaultBean getFaultBean() {
//         return faultBean;
//     }
// 
//     public void setFaultBean(FaultBean faultBean) {
//         this.faultBean = faultBean;
//     }
// }


import com.cookbook.tutorial.service.Constants;
import com.cookbook.tutorial.service.InvalidEntityException;
import com.cookbook.tutorial.service.NoSuchEntityException;
import com.cookbook.tutorial.service.Recipe;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
package com.cookbook.tutorial;



@Path("/oauth")
public class AuthorizeResource {

    @GET
    @Path("/authorize")
    @Produces(MediaType.APPLICATION_JSON)
    public Response authorize(@QueryParam("client_id") String accountId, @QueryParam("redirect_uri") String redirectTo) {

        if (CLIENT_ID.equals(accountId)) {
            return Response.status(302).location(
                    UriBuilder.fromUri(redirectTo).queryParam("code", new String[] { CODE }).build()).build();
        } else {
            return Response.status(400).entity(
                    UriBuilder.fromUri(redirectTo).queryParam("error", new String[] { "invalid_client" }).build()).build();
        }
    }

    @POST
    @Path("/accessToken")
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public Response token(MultivaluedMap<String, String> params) {
        try {
            if (params.get("code").get(0).equals(CODE) &&
                    params.get("client_id").get(0).equals(CLIENT_ID) &&
                    params.get("client_secret").get(0).equals(CLIENT_SECRET)
                    ) {
                Map<String, Object> map = new HashMap<>();
// Path: soap-server/src/main/java/com/cookbook/tutorial/service/Constants.java
// public class Constants {
//     public static final String DEFAULT_TOKEN = "ASD9807123#123POI";
// }
// 
// Path: webservice/src/main/java/com/cookbook/tutorial/service/InvalidEntityException.java
// @WebFault(name = "InvalidEntity", faultBean = "com.cookbook.tutorial.service.FaultBean")
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlRootElement
// public class InvalidEntityException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     /**
//      * Field containing the CookBook entity that caused the exception
//      */
//     private FaultBean faultBean;
// 
//     public InvalidEntityException(){
// 
//     }
// 
//     public InvalidEntityException(String message, FaultBean faultBean, Throwable cause) {
//         super(message, cause);
//         this.faultBean = faultBean;
//     }
// 
//     public InvalidEntityException(String message, FaultBean faultBean) {
//         super(message);
//         this.faultBean = faultBean;
//     }
// 
//     public FaultBean getFaultBean() {
//         return faultBean;
//     }
// 
//     public void setFaultBean(FaultBean faultBean) {
//         this.faultBean = faultBean;
//     }
// }
// 
// Path: webservice/src/main/java/com/cookbook/tutorial/service/NoSuchEntityException.java
// @WebFault(name = "NoSuchEntity", faultBean = "com.cookbook.tutorial.service.FaultBean")
// @XmlAccessorType(XmlAccessType.FIELD)
// @XmlRootElement
// public class NoSuchEntityException extends RuntimeException {
//     private static final long serialVersionUID = 1L;
// 
//     /**
//      * Field containing the CookBook entity that caused the exception
//      */
//     private FaultBean faultBean;
// 
//     public NoSuchEntityException(){
// 
//     }
// 
//     public NoSuchEntityException(String message, FaultBean faultBean, Throwable cause) {
//         super(message, cause);
//         this.faultBean = faultBean;
//     }
// 
//     public NoSuchEntityException(String message, FaultBean faultBean) {
//         super(message);
//         this.faultBean = faultBean;
//     }
// 
//     public FaultBean getFaultBean() {
//         return faultBean;
//     }
// 
//     public void setFaultBean(FaultBean faultBean) {
//         this.faultBean = faultBean;
//     }
// }


// Path: rest-server/src/main/java/com/cookbook/tutorial/AuthorizeResource.java
import com.cookbook.tutorial.service.Constants;
import com.cookbook.tutorial.service.InvalidEntityException;
import com.cookbook.tutorial.service.NoSuchEntityException;
import com.cookbook.tutorial.service.Recipe;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

package com.cookbook.tutorial;



@Path("/oauth")
public class AuthorizeResource {

    @GET
    @Path("/authorize")
    @Produces(MediaType.APPLICATION_JSON)
    public Response authorize(@QueryParam("client_id") String accountId, @QueryParam("redirect_uri") String redirectTo) {

        if (CLIENT_ID.equals(accountId)) {
            return Response.status(302).location(
                    UriBuilder.fromUri(redirectTo).queryParam("code", new String[] { CODE }).build()).build();
        } else {
            return Response.status(400).entity(
                    UriBuilder.fromUri(redirectTo).queryParam("error", new String[] { "invalid_client" }).build()).build();
        }
    }

    @POST
    @Path("/accessToken")
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public Response token(MultivaluedMap<String, String> params) {
        try {
            if (params.get("code").get(0).equals(CODE) &&
                    params.get("client_id").get(0).equals(CLIENT_ID) &&
                    params.get("client_secret").get(0).equals(CLIENT_SECRET)
                    ) {
                Map<String, Object> map = new HashMap<>();
                map.put("access_token", Constants.DEFAULT_TOKEN);