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, 2023 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: * @author Bill Foote
38: * @author Bill Shannon
39: * @see java.net.Authenticator
40: * @see jakarta.mail.Session#getInstance(java.util.Properties,
41: * jakarta.mail.Authenticator)
42: * @see jakarta.mail.Session#getDefaultInstance(java.util.Properties,
43: * jakarta.mail.Authenticator)
44: * @see jakarta.mail.Session#requestPasswordAuthentication
45: * @see jakarta.mail.PasswordAuthentication
46: */
47: public abstract class Authenticator {
48:
49: private InetAddress requestingSite;
50: private int requestingPort;
51: private String requestingProtocol;
52: private String requestingPrompt;
53: private String requestingUserName;
54:
55: /**
56: * Creates a default {@code Authenticator}.
57: * There are no abstract methods, but to be useful the user must subclass.
58: *
59: * @see #getPasswordAuthentication()
60: */
61: public Authenticator() {
62: }
63:
64: /**
65: * Ask the authenticator for a password.
66: * <p>
67: *
68: * @param addr The InetAddress of the site requesting authorization,
69: * or null if not known.
70: * @param port the port for the requested connection
71: * @param protocol The protocol that's requesting the connection
72: * (@see java.net.Authenticator.getProtocol())
73: * @param prompt A prompt string for the user
74: * @return The username/password, or null if one can't be gotten.
75: */
76: final synchronized PasswordAuthentication requestPasswordAuthentication(
77: InetAddress addr, int port, String protocol,
78: String prompt, String defaultUserName) {
79: requestingSite = addr;
80: requestingPort = port;
81: requestingProtocol = protocol;
82: requestingPrompt = prompt;
83: requestingUserName = defaultUserName;
84: return getPasswordAuthentication();
85: }
86:
87: /**
88: * @return the InetAddress of the site requesting authorization, or null
89: * if it's not available.
90: */
91: protected final InetAddress getRequestingSite() {
92: return requestingSite;
93: }
94:
95: /**
96: * @return the port for the requested connection
97: */
98: protected final int getRequestingPort() {
99: return requestingPort;
100: }
101:
102: /**
103: * Give the protocol that's requesting the connection. Often this
104: * will be based on a URLName.
105: *
106: * @return the protcol
107: * @see jakarta.mail.URLName#getProtocol
108: */
109: protected final String getRequestingProtocol() {
110: return requestingProtocol;
111: }
112:
113: /**
114: * @return the prompt string given by the requestor
115: */
116: protected final String getRequestingPrompt() {
117: return requestingPrompt;
118: }
119:
120: /**
121: * @return the default user name given by the requestor
122: */
123: protected final String getDefaultUserName() {
124: return requestingUserName;
125: }
126:
127: /**
128: * Called when password authentication is needed. Subclasses should
129: * override the default implementation, which returns null. <p>
130: *
131: * Note that if this method uses a dialog to prompt the user for this
132: * information, the dialog needs to block until the user supplies the
133: * information. This method can not simply return after showing the
134: * dialog.
135: *
136: * @return The PasswordAuthentication collected from the
137: * user, or null if none is provided.
138: */
139: protected PasswordAuthentication getPasswordAuthentication() {
140: return null;
141: }
142: }