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

hazendaz / httpunit / 656

06 Dec 2025 09:11PM UTC coverage: 80.452% (+0.02%) from 80.435%
656

push

github

hazendaz
[maven-release-plugin] prepare for next development iteration

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10137 relevant lines covered (81.34%)

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
 * MIT License
3
 *
4
 * Copyright 2011-2025 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.httpunit;
21

22
import java.util.Map;
23
import java.util.Properties;
24

25
/**
26
 * This exception is thrown when an unauthorized request is made for a page that requires authentication.
27
 **/
28
public class AuthorizationRequiredException extends RuntimeException {
29

30
    /** The Constant serialVersionUID. */
31
    private static final long serialVersionUID = 1L;
32

33
    /**
34
     * Creates the basic authentication required exception.
35
     *
36
     * @param realm
37
     *            the realm
38
     *
39
     * @return the authorization required exception
40
     */
41
    public static AuthorizationRequiredException createBasicAuthenticationRequiredException(String realm) {
42
        Properties props = new Properties();
1✔
43
        props.put("realm", realm);
1✔
44
        return new AuthorizationRequiredException("Basic", props);
1✔
45
    }
46

47
    /**
48
     * Creates the exception.
49
     *
50
     * @param scheme
51
     *            the scheme
52
     * @param properties
53
     *            the properties
54
     *
55
     * @return the authorization required exception
56
     */
57
    static AuthorizationRequiredException createException(String scheme, Map properties) {
58
        return new AuthorizationRequiredException(scheme, properties);
1✔
59
    }
60

61
    /**
62
     * Instantiates a new authorization required exception.
63
     *
64
     * @param scheme
65
     *            the scheme
66
     * @param properties
67
     *            the properties
68
     */
69
    private AuthorizationRequiredException(String scheme, Map properties) {
1✔
70
        _scheme = scheme;
1✔
71
        _properties = properties;
1✔
72
    }
1✔
73

74
    @Override
75
    public String getMessage() {
76
        return _scheme + " authentication required: " + _properties;
×
77
    }
78

79
    /**
80
     * Returns the name of the <a href="http://www.freesoft.org/CIE/RFC/Orig/rfc2617.txt">authentication scheme</a>.
81
     *
82
     * @return the scheme
83
     **/
84
    public String getAuthenticationScheme() {
85
        return _scheme;
1✔
86
    }
87

88
    /**
89
     * Returns the named authentication parameter. For Basic authentication, the only parameter is "realm".
90
     *
91
     * @param parameterName
92
     *            the name of the parameter to fetch
93
     *
94
     * @return the parameter, without quotes
95
     **/
96
    public String getAuthenticationParameter(String parameterName) {
97
        return unQuote((String) _properties.get(parameterName));
1✔
98
    }
99

100
    /**
101
     * Un quote.
102
     *
103
     * @param value
104
     *            the value
105
     *
106
     * @return the string
107
     */
108
    private String unQuote(String value) {
109
        if (value == null || value.length() <= 1 || !value.startsWith("\"") || !value.endsWith("\"")) {
1!
110
            return value;
1✔
111
        }
112

113
        return value.substring(1, value.length() - 1);
1✔
114
    }
115

116
    // ------------------------------------- private members ------------------------------------------
117

118
    /** The scheme. */
119
    private String _scheme;
120

121
    /** The properties. */
122
    private Map _properties;
123
}
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