001/******************************************************************************* 002 * Copyright 2017 The MIT Internet Trust Consortium 003 * 004 * Portions copyright 2011-2013 The MITRE Corporation 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 *******************************************************************************/ 018/** 019 * 020 */ 021package org.mitre.openid.connect.view; 022 023import java.io.IOException; 024import java.io.Writer; 025import java.util.ArrayList; 026import java.util.Map; 027 028import javax.servlet.http.HttpServletRequest; 029import javax.servlet.http.HttpServletResponse; 030 031import org.slf4j.Logger; 032import org.slf4j.LoggerFactory; 033import org.springframework.http.MediaType; 034import org.springframework.stereotype.Component; 035import org.springframework.web.servlet.view.AbstractView; 036 037import com.nimbusds.jose.jwk.JWK; 038import com.nimbusds.jose.jwk.JWKSet; 039 040/** 041 * @author jricher 042 * 043 */ 044@Component(JWKSetView.VIEWNAME) 045public class JWKSetView extends AbstractView { 046 047 public static final String VIEWNAME = "jwkSet"; 048 /** 049 * Logger for this class 050 */ 051 private static final Logger logger = LoggerFactory.getLogger(JWKSetView.class); 052 053 @Override 054 protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { 055 056 response.setContentType(MediaType.APPLICATION_JSON_VALUE); 057 058 059 //BiMap<String, PublicKey> keyMap = (BiMap<String, PublicKey>) model.get("keys"); 060 Map<String, JWK> keys = (Map<String, JWK>) model.get("keys"); 061 062 JWKSet jwkSet = new JWKSet(new ArrayList<>(keys.values())); 063 064 try { 065 066 Writer out = response.getWriter(); 067 out.write(jwkSet.toString()); 068 069 } catch (IOException e) { 070 071 logger.error("IOException in JWKSetView.java: ", e); 072 073 } 074 075 } 076 077}