• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 755

14 Feb 2026 07:14PM UTC coverage: 80.526%. Remained the same
755

push

github

hazendaz
[ci] Fix badge

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10124 relevant lines covered (81.44%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/src/main/java/com/meterware/httpunit/AuthorizationRequiredException.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2000-2026 Russell Gold
6
 * Copyright 2021-2000 hazendaz
7
 */
8
package com.meterware.httpunit;
9

10
import java.util.Map;
11
import java.util.Properties;
12

13
/**
14
 * This exception is thrown when an unauthorized request is made for a page that requires authentication.
15
 **/
16
public class AuthorizationRequiredException extends RuntimeException {
17

18
    /** The Constant serialVersionUID. */
19
    private static final long serialVersionUID = 1L;
20

21
    /**
22
     * Creates the basic authentication required exception.
23
     *
24
     * @param realm
25
     *            the realm
26
     *
27
     * @return the authorization required exception
28
     */
29
    public static AuthorizationRequiredException createBasicAuthenticationRequiredException(String realm) {
30
        Properties props = new Properties();
1✔
31
        props.put("realm", realm);
1✔
32
        return new AuthorizationRequiredException("Basic", props);
1✔
33
    }
34

35
    /**
36
     * Creates the exception.
37
     *
38
     * @param scheme
39
     *            the scheme
40
     * @param properties
41
     *            the properties
42
     *
43
     * @return the authorization required exception
44
     */
45
    static AuthorizationRequiredException createException(String scheme, Map properties) {
46
        return new AuthorizationRequiredException(scheme, properties);
1✔
47
    }
48

49
    /**
50
     * Instantiates a new authorization required exception.
51
     *
52
     * @param scheme
53
     *            the scheme
54
     * @param properties
55
     *            the properties
56
     */
57
    private AuthorizationRequiredException(String scheme, Map properties) {
1✔
58
        _scheme = scheme;
1✔
59
        _properties = properties;
1✔
60
    }
1✔
61

62
    @Override
63
    public String getMessage() {
64
        return _scheme + " authentication required: " + _properties;
×
65
    }
66

67
    /**
68
     * Returns the name of the <a href="http://www.freesoft.org/CIE/RFC/Orig/rfc2617.txt">authentication scheme</a>.
69
     *
70
     * @return the scheme
71
     **/
72
    public String getAuthenticationScheme() {
73
        return _scheme;
1✔
74
    }
75

76
    /**
77
     * Returns the named authentication parameter. For Basic authentication, the only parameter is "realm".
78
     *
79
     * @param parameterName
80
     *            the name of the parameter to fetch
81
     *
82
     * @return the parameter, without quotes
83
     **/
84
    public String getAuthenticationParameter(String parameterName) {
85
        return unQuote((String) _properties.get(parameterName));
1✔
86
    }
87

88
    /**
89
     * Un quote.
90
     *
91
     * @param value
92
     *            the value
93
     *
94
     * @return the string
95
     */
96
    private String unQuote(String value) {
97
        if (value == null || value.length() <= 1 || !value.startsWith("\"") || !value.endsWith("\"")) {
1!
98
            return value;
1✔
99
        }
100

101
        return value.substring(1, value.length() - 1);
1✔
102
    }
103

104
    // ------------------------------------- private members ------------------------------------------
105

106
    /** The scheme. */
107
    private String _scheme;
108

109
    /** The properties. */
110
    private Map _properties;
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc