Skip to content

Package: Authenticator

Authenticator

nameinstructionbranchcomplexitylinemethod
Authenticator()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getDefaultUserName()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPasswordAuthentication()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRequestingPort()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRequestingPrompt()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRequestingProtocol()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getRequestingSite()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
requestPasswordAuthentication(InetAddress, int, String, String, String)
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package jakarta.mail;
18:
19: import java.net.InetAddress;
20:
21: /**
22: * The class Authenticator represents an object that knows how to obtain
23: * authentication for a network connection. Usually, it will do this
24: * by prompting the user for information.
25: * <p>
26: * Applications use this class by creating a subclass, and registering
27: * an instance of that subclass with the session when it is created.
28: * When authentication is required, the system will invoke a method
29: * on the subclass (like getPasswordAuthentication). The subclass's
30: * method can query about the authentication being requested with a
31: * number of inherited methods (getRequestingXXX()), and form an
32: * appropriate message for the user.
33: * <p>
34: * All methods that request authentication have a default implementation
35: * that fails.
36: *
37: * @see java.net.Authenticator
38: * @see jakarta.mail.Session#getInstance(java.util.Properties,
39: *                                        jakarta.mail.Authenticator)
40: * @see jakarta.mail.Session#getDefaultInstance(java.util.Properties,
41: *                                        jakarta.mail.Authenticator)
42: * @see jakarta.mail.Session#requestPasswordAuthentication
43: * @see jakarta.mail.PasswordAuthentication
44: *
45: * @author Bill Foote
46: * @author Bill Shannon
47: */
48: public abstract class Authenticator {
49:
50: private InetAddress requestingSite;
51: private int requestingPort;
52: private String requestingProtocol;
53: private String requestingPrompt;
54: private String requestingUserName;
55:
56: /**
57: * Creates a default {@code Authenticator}.
58: * There are no abstract methods, but to be useful the user must subclass.
59: *
60: * @see #getPasswordAuthentication()
61: */
62: public Authenticator() {
63: }
64:
65: /**
66: * Ask the authenticator for a password.
67: * <p>
68: *
69: * @param addr The InetAddress of the site requesting authorization,
70: * or null if not known.
71: * @param port the port for the requested connection
72: * @param protocol The protocol that's requesting the connection
73: * (@see java.net.Authenticator.getProtocol())
74: * @param prompt A prompt string for the user
75: *
76: * @return The username/password, or null if one can't be gotten.
77: */
78: final synchronized PasswordAuthentication requestPasswordAuthentication(
79:                                 InetAddress addr, int port, String protocol,
80:                                 String prompt, String defaultUserName) {
81:         requestingSite = addr;
82:         requestingPort = port;
83:         requestingProtocol = protocol;
84:         requestingPrompt = prompt;
85:         requestingUserName = defaultUserName;
86:         return getPasswordAuthentication();
87: }
88:
89: /**
90: * @return the InetAddress of the site requesting authorization, or null
91: *                if it's not available.
92: */
93: protected final InetAddress getRequestingSite() {
94:         return requestingSite;
95: }
96:
97: /**
98: * @return the port for the requested connection
99: */
100: protected final int getRequestingPort() {
101:         return requestingPort;
102: }
103:
104: /**
105: * Give the protocol that's requesting the connection. Often this
106: * will be based on a URLName.
107: *
108: * @return the protcol
109: *
110: * @see jakarta.mail.URLName#getProtocol
111: */
112: protected final String getRequestingProtocol() {
113:         return requestingProtocol;
114: }
115:
116: /**
117: * @return the prompt string given by the requestor
118: */
119: protected final String getRequestingPrompt() {
120:         return requestingPrompt;
121: }
122:
123: /**
124: * @return the default user name given by the requestor
125: */
126: protected final String getDefaultUserName() {
127:         return requestingUserName;
128: }
129:
130: /**
131: * Called when password authentication is needed. Subclasses should
132: * override the default implementation, which returns null. <p>
133: *
134: * Note that if this method uses a dialog to prompt the user for this
135: * information, the dialog needs to block until the user supplies the
136: * information. This method can not simply return after showing the
137: * dialog.
138: * @return The PasswordAuthentication collected from the
139: *                user, or null if none is provided.
140: */
141: protected PasswordAuthentication getPasswordAuthentication() {
142:         return null;
143: }
144: }