ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/websocket/Authenticator.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/websocket/Authenticator.java
Status
scanned
Type
file
Name
Authenticator.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4364 (4.3 KB)
MD5
f73fca1531a096ebc935a6e5a5d11422
SHA1
9f251f6c55ee8c71e88c31fe1bd562e970e61922
SHA256
e49b8aeb235d26c47c4546dd65bbeaa5b573c40777310c5b2f1d0ef704c1ca34
SHA512

      
    
SHA1_git
3780715a7cf0332caa4b1624d1ce8bea5cf627d9
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
Authenticator.java | 4.3 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.tomcat.websocket; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.tomcat.util.res.StringManager; /** * Base class for the authentication methods used by the WebSocket client. */ public abstract class Authenticator { private static final StringManager sm = StringManager.getManager(Authenticator.class); private static final Pattern pattern = Pattern.compile("(\\w+)\\s*=\\s*(\"([^\"]+)\"|([^,=\"]+))\\s*,?"); /** * Generate the authorization header value that will be sent to the server. * * @param requestUri The request URI * @param authenticateHeader The server authentication header received * @param userName The username * @param userPassword The user password * @param userRealm The realm for which the provided username and password are valid. {@code null} to * indicate all realms. * * @return The generated authorization header value * * @throws AuthenticationException When an error occurs */ public abstract String getAuthorization(String requestUri, String authenticateHeader, String userName, String userPassword, String userRealm) throws AuthenticationException; /** * Get the authentication method. * * @return the authentication scheme */ public abstract String getSchemeName(); /** * Utility method to parse the authentication header. * * @param authenticateHeader The server authenticate header received * * @return a map of authentication parameter names and values */ public Map<String,String> parseAuthenticateHeader(String authenticateHeader) { Matcher m = pattern.matcher(authenticateHeader); Map<String,String> parameterMap = new HashMap<>(); while (m.find()) { String key = m.group(1); String qtedValue = m.group(3); String value = m.group(4); parameterMap.put(key, qtedValue != null ? qtedValue : value); } return parameterMap; } protected void validateUsername(String userName) throws AuthenticationException { if (userName == null) { throw new AuthenticationException(sm.getString("authenticator.nullUserName")); } } protected void validatePassword(String password) throws AuthenticationException { if (password == null) { throw new AuthenticationException(sm.getString("authenticator.nullPassword")); } } protected void validateRealm(String userRealm, String serverRealm) throws AuthenticationException { if (userRealm == null) { return; } userRealm = userRealm.trim(); if (userRealm.isEmpty()) { return; } /* * User has configured a realm. Only allow authentication to proceed if the realm in the authentication * challenge matches (both BASIC and DIGEST are required to include a realm). */ if (serverRealm != null) { serverRealm = serverRealm.trim(); if (userRealm.equals(serverRealm)) { return; } } throw new AuthenticationException(sm.getString("authenticator.realmMismatch", userRealm, serverRealm)); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
27.05
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9