diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/RequestObjectAuthorizationEndpoint.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/RequestObjectAuthorizationEndpoint.java index 9fdcede11..39098af0a 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/RequestObjectAuthorizationEndpoint.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/RequestObjectAuthorizationEndpoint.java @@ -1,40 +1,62 @@ package org.mitre.openid.connect.web; -import java.security.Principal; -import java.util.Map; +import java.net.URI; +import java.net.URISyntaxException; +import java.text.ParseException; + +import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint; +import org.apache.http.client.utils.URIBuilder; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.support.SessionStatus; -import org.springframework.web.servlet.ModelAndView; -// -// TODO: make this into a controller again, use the forward: or redirect: mechanism to send to auth endpoint -// +import com.google.common.base.Strings; +import com.nimbusds.jwt.JWT; +import com.nimbusds.jwt.JWTParser; -//@Controller("requestObjectAuthorzationEndpoint") + +/** + * This @Controller is a hack to get around SECOAUTH's AuthorizationEndpoint requiring the response_type parameter to be passed in. + * + * @author jricher + * + */ +@Controller("requestObjectAuthorzationEndpoint") +//@Component public class RequestObjectAuthorizationEndpoint { - + protected final Log logger = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationEndpoint authorizationEndpoint; - - @RequestMapping(value = "/oauth/authorize", params = "request") - public ModelAndView authorizeRequestObject(Map model, @RequestParam("request") String jwtString, - @RequestParam Map parameters, SessionStatus sessionStatus, Principal principal) { - - /* - * - * SEE Processing code in ConnectAuthorizationRequestManager.processRequestObject - * - */ + @RequestMapping(value = "/authorize", params = "request") + public String authorizeRequestObject(@RequestParam("request") String jwtString, @RequestParam(value = "response_type", required = false) String responseType, HttpServletRequest request) { - return null; + String query = request.getQueryString(); + + if (responseType == null) { + try { + JWT requestObject = JWTParser.parse(jwtString); + responseType = (String)requestObject.getJWTClaimsSet().getClaim("response_type"); + + URI uri = new URIBuilder(Strings.nullToEmpty(request.getServletPath()) + Strings.nullToEmpty(request.getPathInfo()) + "?" + query) + .addParameter("response_type", responseType) + .build(); + + query = uri.getRawQuery();//uri.toString(); + + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + return "forward:/oauth/authorize?" + query; } diff --git a/openid-connect-server/src/main/webapp/WEB-INF/application-context.xml b/openid-connect-server/src/main/webapp/WEB-INF/application-context.xml index 4a346ef16..57bb5dac7 100644 --- a/openid-connect-server/src/main/webapp/WEB-INF/application-context.xml +++ b/openid-connect-server/src/main/webapp/WEB-INF/application-context.xml @@ -27,7 +27,7 @@ - + diff --git a/pom.xml b/pom.xml index ed28ed7c2..a6e0cee7e 100644 --- a/pom.xml +++ b/pom.xml @@ -244,7 +244,7 @@ org.apache.httpcomponents httpclient - 4.1.1 + 4.2.3 mysql