gluu
公開メンバ関数 | 静的公開メンバ関数 | 静的公開変数類 | 限定公開メンバ関数 | 限定公開変数類 | 非公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.gluu.oxauth.client.authentication.AuthenticationFilter クラス
org.gluu.oxauth.client.authentication.AuthenticationFilter の継承関係図
Inheritance graph
org.gluu.oxauth.client.authentication.AuthenticationFilter 連携図
Collaboration graph

公開メンバ関数

final void init (final FilterConfig filterConfig) throws ServletException
 
final void destroy ()
 
final void doFilter (final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException
 
String getOAuthRedirectUrl (final HttpServletRequest request, final HttpServletResponse response) throws Exception
 

静的公開メンバ関数

static String getParameter (final HttpServletRequest request, final String parameter)
 

静的公開変数類

static final String SESSION_CONVERSATION_KEY = "saml_idp_conversation_key"
 

限定公開メンバ関数

final boolean preFilter (final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException
 
final String constructRedirectUrl (final HttpServletRequest request)
 
final String getPropertyFromInitParams (final FilterConfig filterConfig, final String propertyName, final String defaultValue)
 

限定公開変数類

final Log log = LogFactory.getLog(getClass())
 

非公開メンバ関数

Cookie getCurrentShibstateCookie (HttpServletRequest request)
 
void updateShibstateCookie (HttpServletResponse response, Cookie shibstateCookie, String requestUri, String acrPathParam)
 
Cookie cloneCokie (Cookie sourceCookie, String newValue, int maxAge)
 
String decodeCookieValue (String cookieValue)
 
String encodeCookieValue (String cookieValue)
 
String determineAuthenticationMode (String requestUri)
 
String determineAuthenticationParameter (String requestUri, Pattern pattern)
 

非公開変数類

final Pattern authModePattern = Pattern.compile(".+/acr_values/([\\d\\w]+)$")
 

詳解

Filter implementation to intercept all requests and attempt to authorize the client by redirecting them to OAuth (unless the client has get authorization code).

This filter allows you to specify the following parameters (at either the context-level or the filter-level):

Please see AbstractOAuthFilter for additional properties

著者
Yuriy Movchan

関数詳解

◆ cloneCokie()

Cookie org.gluu.oxauth.client.authentication.AuthenticationFilter.cloneCokie ( Cookie  sourceCookie,
String  newValue,
int  maxAge 
)
inlineprivate
246  {
247  Cookie resultCookie = new Cookie(sourceCookie.getName(), newValue);
248 
249  resultCookie.setPath("/");
250  resultCookie.setMaxAge(maxAge);
251  resultCookie.setVersion(1);
252  resultCookie.setSecure(true);
253 
254  return resultCookie;
255  }

◆ constructRedirectUrl()

final String org.gluu.oxauth.client.session.AbstractOAuthFilter.constructRedirectUrl ( final HttpServletRequest  request)
inlineprotectedinherited
21  {
22  int serverPort = request.getServerPort();
23 
24  String redirectUrl;
25  if ((serverPort == 80) || (serverPort == 443)) {
26  redirectUrl = String.format("%s://%s%s%s", request.getScheme(), request.getServerName(), request.getContextPath(), "/auth-code.jsp");
27  } else {
28  redirectUrl = String.format("%s://%s:%s%s%s", request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath(), "/auth-code.jsp");
29  }
30 
31  return redirectUrl.toLowerCase();
32  }

◆ decodeCookieValue()

String org.gluu.oxauth.client.authentication.AuthenticationFilter.decodeCookieValue ( String  cookieValue)
inlineprivate
257  {
258  if (StringHelper.isEmpty(cookieValue)) {
259  return null;
260  }
261 
262  return URLDecoder.decode(cookieValue);
263  }

◆ destroy()

final void org.gluu.oxauth.client.authentication.AuthenticationFilter.destroy ( )
inline
79  {
80  }

◆ determineAuthenticationMode()

String org.gluu.oxauth.client.authentication.AuthenticationFilter.determineAuthenticationMode ( String  requestUri)
inlineprivate
273  {
275  }
String determineAuthenticationParameter(String requestUri, Pattern pattern)
Definition: AuthenticationFilter.java:277
final Pattern authModePattern
Definition: AuthenticationFilter.java:72

◆ determineAuthenticationParameter()

String org.gluu.oxauth.client.authentication.AuthenticationFilter.determineAuthenticationParameter ( String  requestUri,
Pattern  pattern 
)
inlineprivate
277  {
278  Matcher matcher = pattern.matcher(requestUri);
279  if (matcher.find()) {
280  return matcher.group(1);
281  }
282 
283  return null;
284  }

◆ doFilter()

final void org.gluu.oxauth.client.authentication.AuthenticationFilter.doFilter ( final ServletRequest  servletRequest,
final ServletResponse  servletResponse,
final FilterChain  filterChain 
) throws IOException, ServletException
inline
84  {
85 
86  if (!preFilter(servletRequest, servletResponse, filterChain)) {
87  log.debug("Execute validation filter");
88  filterChain.doFilter(servletRequest, servletResponse);
89  return;
90  }
91 
92  log.debug("No code and no OAuth data found");
93 
94  final HttpServletRequest request = (HttpServletRequest) servletRequest;
95  final HttpServletResponse response = (HttpServletResponse) servletResponse;
96 
97  String urlToRedirectTo;
98  try {
99  urlToRedirectTo = getOAuthRedirectUrl(request, response);
100  } catch (Exception ex) {
101  log.error("Failed to preapre request to OAuth server", ex);
102  return;
103  }
104 
105  log.debug("Redirecting to \"" + urlToRedirectTo + "\"");
106 
107  response.sendRedirect(urlToRedirectTo);
108  }
String getOAuthRedirectUrl(final HttpServletRequest request, final HttpServletResponse response)
Definition: AuthenticationFilter.java:134
final Log log
Definition: AbstractConfigurationFilter.java:24
final boolean preFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain)
Definition: AuthenticationFilter.java:113

◆ encodeCookieValue()

String org.gluu.oxauth.client.authentication.AuthenticationFilter.encodeCookieValue ( String  cookieValue)
inlineprivate
265  {
266  if (StringHelper.isEmpty(cookieValue)) {
267  return null;
268  }
269 
270  return URLEncoder.encode(cookieValue);
271  }

◆ getCurrentShibstateCookie()

Cookie org.gluu.oxauth.client.authentication.AuthenticationFilter.getCurrentShibstateCookie ( HttpServletRequest  request)
inlineprivate
207  {
208  Cookie[] cookies = request.getCookies();
209  if (ArrayHelper.isEmpty(cookies)) {
210  return null;
211  }
212 
213  Cookie resultCookie = null;
214  for (Cookie cookie : cookies) {
215  String cookieName = cookie.getName();
216  if (cookieName.startsWith("_shibstate_")) {
217  if (resultCookie == null) {
218  resultCookie = cookie;
219  } else {
220  if (cookieName.compareTo(resultCookie.getName()) > 0) {
221  resultCookie = cookie;
222  }
223  }
224  }
225  }
226 
227  if (resultCookie == null) {
228  return null;
229  }
230  return resultCookie;
231  }

◆ getOAuthRedirectUrl()

String org.gluu.oxauth.client.authentication.AuthenticationFilter.getOAuthRedirectUrl ( final HttpServletRequest  request,
final HttpServletResponse  response 
) throws Exception
inline
134  {
135  String authorizeUrl = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_AUTHORIZE_URL, null);
136  String clientScopes = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_CLIENT_SCOPE, null);
137 
138  String clientId = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_CLIENT_ID, null);
139  String clientSecret = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_CLIENT_PASSWORD, null);
140  if (clientSecret != null) {
141  try {
142  clientSecret = StringEncrypter.defaultInstance().decrypt(clientSecret, Configuration.instance().getCryptoPropertyValue());
143  } catch (EncryptionException ex) {
144  log.error("Failed to decrypt property: " + Configuration.OAUTH_PROPERTY_CLIENT_PASSWORD, ex);
145  }
146  }
147 
148  String redirectUri = constructRedirectUrl(request);
149 
150  List<String> scopes = Arrays.asList(clientScopes.split(StringUtils.SPACE));
151  List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
152 
153  String nonce = UUID.randomUUID().toString();
154  String rfp = UUID.randomUUID().toString();
155  String jti = UUID.randomUUID().toString();
156 
157  // Lookup for relying party ID
158  final String key = request.getParameter(ExternalAuthentication.CONVERSATION_KEY);
159  request.getSession().setAttribute(SESSION_CONVERSATION_KEY, key);
160  ProfileRequestContext prc = ExternalAuthentication.getProfileRequestContext(key, request);
161 
162  String relyingPartyId = "";
163  final RelyingPartyContext relyingPartyCtx = prc.getSubcontext(RelyingPartyContext.class);
164  if (relyingPartyCtx != null) {
165  relyingPartyId = relyingPartyCtx.getRelyingPartyId();
166  log.info("relyingPartyId found: " + relyingPartyId);
167  } else
168  log.warn("No RelyingPartyContext was available");
169 
170  // JWT
171  OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();
172  JwtState jwtState = new JwtState(SignatureAlgorithm.HS256, clientSecret, cryptoProvider);
173  jwtState.setRfp(rfp);
174  jwtState.setJti(jti);
175  if (relyingPartyId != null && !"".equals(relyingPartyId)) {
176  String additionalClaims = String.format("{relyingPartyId: '%s'}", relyingPartyId);
177  jwtState.setAdditionalClaims(new JSONObject(additionalClaims));
178  } else
179  log.warn("No relyingPartyId was available");
180  String encodedState = jwtState.getEncodedJwt();
181 
182  AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce);
183  authorizationRequest.setState(encodedState);
184 
185  Cookie currentShibstateCookie = getCurrentShibstateCookie(request);
186  if (currentShibstateCookie != null) {
187  String requestUri = decodeCookieValue(currentShibstateCookie.getValue());
188  log.debug("requestUri = \"" + requestUri + "\"");
189 
190  String authenticationMode = determineAuthenticationMode(requestUri);
191 
192  if (StringHelper.isNotEmpty(authenticationMode)) {
193  log.debug("acr_values = \"" + authenticationMode + "\"");
194  authorizationRequest.setAcrValues(Arrays.asList(authenticationMode));
195  updateShibstateCookie(response, currentShibstateCookie, requestUri, "/" + Configuration.OXAUTH_ACR_VALUES + "/" + authenticationMode);
196  }
197  }
198 
199  // Store for validation in session
200  final HttpSession session = request.getSession(false);
201  session.setAttribute(Configuration.SESSION_AUTH_STATE, encodedState);
202  session.setAttribute(Configuration.SESSION_AUTH_NONCE, nonce);
203 
204  return authorizeUrl + "?" + authorizationRequest.getQueryString();
205  }
void updateShibstateCookie(HttpServletResponse response, Cookie shibstateCookie, String requestUri, String acrPathParam)
Definition: AuthenticationFilter.java:233
String decodeCookieValue(String cookieValue)
Definition: AuthenticationFilter.java:257
String determineAuthenticationMode(String requestUri)
Definition: AuthenticationFilter.java:273
final String constructRedirectUrl(final HttpServletRequest request)
Definition: AbstractOAuthFilter.java:21
final Log log
Definition: AbstractConfigurationFilter.java:24
Cookie getCurrentShibstateCookie(HttpServletRequest request)
Definition: AuthenticationFilter.java:207
static final String SESSION_CONVERSATION_KEY
Definition: AuthenticationFilter.java:66
final String getPropertyFromInitParams(final FilterConfig filterConfig, final String propertyName, final String defaultValue)
Definition: AbstractConfigurationFilter.java:35

◆ getParameter()

static String org.gluu.oxauth.client.session.AbstractOAuthFilter.getParameter ( final HttpServletRequest  request,
final String  parameter 
)
inlinestaticinherited

Method for retrieving a parameter from the request without disrupting the reader UNLESS the parameter actually exists in the query string.

引数
requestthe request to check.
parameterthe parameter to look for.
戻り値
the value of the parameter.
42  {
43  return request.getQueryString() == null || request.getQueryString().indexOf(parameter) == -1 ? null : request.getParameter(parameter);
44  }

◆ getPropertyFromInitParams()

final String org.gluu.oxauth.client.util.AbstractConfigurationFilter.getPropertyFromInitParams ( final FilterConfig  filterConfig,
final String  propertyName,
final String  defaultValue 
)
inlineprotectedinherited

Retrieves the property from the FilterConfig. First it checks the FilterConfig's initParameters to see if it has a value. If it does, it returns that, otherwise it retrieves the ServletContext's initParameters and returns that value if any.

引数
filterConfigthe Filter Configuration.
propertyNamethe property to retrieve.
defaultValuethe default value if the property is not found.
戻り値
the property value, following the above conventions. It will always return the more specific value (i.e. filter vs. context).
35  {
36 // final String value = filterConfig.getInitParameter(propertyName);
37 //
38 // if (StringHelper.isNotEmpty(value)) {
39 // log.info("Property [" + propertyName + "] loaded from FilterConfig.getInitParameter with value [" + value + "]");
40 // return value;
41 // }
42 //
43 // final String value2 = filterConfig.getServletContext().getInitParameter(propertyName);
44 // if (StringHelper.isNotEmpty(value2)) {
45 // log.info("Property [" + propertyName + "] loaded from ServletContext.getInitParameter with value [" + value2 + "]");
46 // return value2;
47 // }
48 
49  final String value3 = Configuration.instance().getPropertyValue(propertyName);
50  if (StringHelper.isNotEmpty(value3)) {
51  log.info("Property [" + propertyName + "] loaded from oxTrust.properties");
52  return value3;
53  }
54 
55  log.info("Property [" + propertyName + "] not found. Using default value [" + defaultValue + "]");
56  return defaultValue;
57  }
final Log log
Definition: AbstractConfigurationFilter.java:24

◆ init()

final void org.gluu.oxauth.client.authentication.AuthenticationFilter.init ( final FilterConfig  filterConfig) throws ServletException
inline
75  {
76  }

◆ preFilter()

final boolean org.gluu.oxauth.client.authentication.AuthenticationFilter.preFilter ( final ServletRequest  servletRequest,
final ServletResponse  servletResponse,
final FilterChain  filterChain 
) throws IOException, ServletException
inlineprotected

Determine filter execution conditions

114  {
115 
116  final HttpServletRequest request = (HttpServletRequest) servletRequest;
117 
118  final HttpSession session = request.getSession(false);
119 
120  final OAuthData oAuthData = session != null ? (OAuthData) session.getAttribute(Configuration.SESSION_OAUTH_DATA) : null;
121  if (oAuthData != null) {
122  return false;
123  }
124 
125  final String code = getParameter(request, Configuration.OAUTH_CODE);
126  log.trace("code value: " + code);
127  if (StringHelper.isNotEmpty(code)) {
128  return false;
129  }
130 
131  return true;
132  }
final Log log
Definition: AbstractConfigurationFilter.java:24
static String getParameter(final HttpServletRequest request, final String parameter)
Definition: AbstractOAuthFilter.java:42

◆ updateShibstateCookie()

void org.gluu.oxauth.client.authentication.AuthenticationFilter.updateShibstateCookie ( HttpServletResponse  response,
Cookie  shibstateCookie,
String  requestUri,
String  acrPathParam 
)
inlineprivate
233  {
234  // Check if parameter exists
235  if (!requestUri.contains(acrPathParam)) {
236  return;
237  }
238 
239  String newRequestUri = requestUri.replace(acrPathParam, "");
240 
241  // Set new cookie
242  Cookie updateShibstateCookie = cloneCokie(shibstateCookie, encodeCookieValue(newRequestUri), shibstateCookie.getMaxAge());
243  response.addCookie(updateShibstateCookie);
244  }
void updateShibstateCookie(HttpServletResponse response, Cookie shibstateCookie, String requestUri, String acrPathParam)
Definition: AuthenticationFilter.java:233
String encodeCookieValue(String cookieValue)
Definition: AuthenticationFilter.java:265
Cookie cloneCokie(Cookie sourceCookie, String newValue, int maxAge)
Definition: AuthenticationFilter.java:246

メンバ詳解

◆ authModePattern

final Pattern org.gluu.oxauth.client.authentication.AuthenticationFilter.authModePattern = Pattern.compile(".+/acr_values/([\\d\\w]+)$")
private

The URL to the OAuth Server authorization services

◆ log

final Log org.gluu.oxauth.client.util.AbstractConfigurationFilter.log = LogFactory.getLog(getClass())
protectedinherited

◆ SESSION_CONVERSATION_KEY

final String org.gluu.oxauth.client.authentication.AuthenticationFilter.SESSION_CONVERSATION_KEY = "saml_idp_conversation_key"
static

このクラス詳解は次のファイルから抽出されました: