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