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.client.keypublisher; 022 023import java.util.Locale; 024 025import org.springframework.core.Ordered; 026import org.springframework.web.servlet.View; 027import org.springframework.web.servlet.ViewResolver; 028 029/** 030 * 031 * Simple view resolver to map JWK view names to appropriate beans 032 * 033 * @author jricher 034 * 035 */ 036public class JwkViewResolver implements ViewResolver, Ordered { 037 038 private String jwkViewName = "jwkKeyList"; 039 private View jwk; 040 041 private int order = HIGHEST_PRECEDENCE; // highest precedence, most specific -- avoids hitting the catch-all view resolvers 042 043 /** 044 * Map "jwkKeyList" to the jwk property on this bean. 045 * Everything else returns null 046 */ 047 @Override 048 public View resolveViewName(String viewName, Locale locale) throws Exception { 049 if (viewName != null) { 050 if (viewName.equals(getJwkViewName())) { 051 return getJwk(); 052 } else { 053 return null; 054 } 055 } else { 056 return null; 057 } 058 } 059 060 /** 061 * @return the jwk 062 */ 063 public View getJwk() { 064 return jwk; 065 } 066 067 /** 068 * @param jwk the jwk to set 069 */ 070 public void setJwk(View jwk) { 071 this.jwk = jwk; 072 } 073 074 /** 075 * @return the order 076 */ 077 @Override 078 public int getOrder() { 079 return order; 080 } 081 082 /** 083 * @param order the order to set 084 */ 085 public void setOrder(int order) { 086 this.order = order; 087 } 088 089 /** 090 * @return the jwkViewName 091 */ 092 public String getJwkViewName() { 093 return jwkViewName; 094 } 095 096 /** 097 * @param jwkViewName the jwkViewName to set 098 */ 099 public void setJwkViewName(String jwkViewName) { 100 this.jwkViewName = jwkViewName; 101 } 102 103}