Skip to content

Package: LoginToContinue$Literal

LoginToContinue$Literal

nameinstructionbranchcomplexitylinemethod
LoginToContinue.Literal(String, boolean, String, String)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
errorPage()
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%
loginPage()
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%
of(String, boolean, String, String)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
useForwardToLogin()
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%
useForwardToLoginExpression()
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%

Coverage

1: /*
2: * Copyright (c) 2021, 2023 Contributors to Eclipse Foundation.
3: * Copyright (c) 2015, 2021 Oracle and/or its affiliates and others. All rights reserved.
4: *
5: * This program and the accompanying materials are made available under the
6: * terms of the Eclipse Public License v. 2.0, which is available at
7: * http://www.eclipse.org/legal/epl-2.0.
8: *
9: * This Source Code may also be made available under the following Secondary
10: * Licenses when the conditions for such availability set forth in the
11: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12: * version 2 with the GNU Classpath Exception, which is available at
13: * https://www.gnu.org/software/classpath/license.html.
14: *
15: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16: */
17:
18: package jakarta.security.enterprise.authentication.mechanism.http;
19:
20: import static java.lang.annotation.ElementType.TYPE;
21: import static java.lang.annotation.RetentionPolicy.RUNTIME;
22:
23: import java.lang.annotation.Inherited;
24: import java.lang.annotation.Retention;
25: import java.lang.annotation.Target;
26:
27: import jakarta.enterprise.util.AnnotationLiteral;
28: import jakarta.enterprise.util.Nonbinding;
29: import jakarta.interceptor.InterceptorBinding;
30:
31: /**
32: * The <code>LoginToContinue</code> annotation provides an application the ability to declaratively
33: * add login to continue functionality to an authentication mechanism.
34: *
35: * <p>
36: * When the <code>LoginToContinue</code> annotation is used on a custom authentication mechanism, Expression Language
37: * expressions in attributes of type <code>String</code> are evaluated for every request requiring
38: * authentication. Both immediate and deferred syntax is supported, but effectively the semantics
39: * are always deferred.
40: *
41: * <p>
42: * When the <code>LoginToContinue</code> annotation is used as attribute in either the
43: * {@link FormAuthenticationMechanismDefinition} or {@link CustomFormAuthenticationMechanismDefinition},
44: * expressions using immediate syntax are evaluated only once when the {@link HttpAuthenticationMechanism}
45: * bean is created. Since these beans are application scoped, this means only once per application.
46: * Expressions using deferred syntax are evaluated as described above when the <code>LoginToContinue</code> annotation
47: * is used on a custom authentication mechanism.
48: *
49: */
50: @Inherited
51: @InterceptorBinding
52: @Retention(RUNTIME)
53: @Target(TYPE)
54: public @interface LoginToContinue {
55:
56: /**
57: * The resource (page) a caller should get to see in case the originally requested
58: * resource requires authentication, and the caller is currently not authenticated.
59: *
60: * @return page a caller is directed to to authenticate (login)
61: */
62: @Nonbinding
63: String loginPage() default "/login";
64:
65: /**
66: * Use a forward to reach the page set by the {@link LoginToContinue#loginPage()}
67: * if true, otherwise use a redirect.
68: *
69: * @return true if a forward is to be used, false for a redirect
70: */
71: @Nonbinding
72: boolean useForwardToLogin() default true;
73:
74: /**
75: * Jakarta Expression Language expression variant of <code>useForwardToLogin()</code>.
76: * The expression needs to evaluate to a boolean outcome. All named CDI beans are available
77: * to the expression. If both this attribute and <code>useForwardToLogin()</code> are specified, this
78: * attribute take precedence.
79: *
80: * @return an expression evaluating to true if a forward is to be used, false for a redirect
81: */
82: @Nonbinding
83: String useForwardToLoginExpression() default "";
84:
85: /**
86: * The resource (page) a caller should get to see in case an error, such as providing invalid
87: * credentials, occurs on the page set by {@link LoginToContinue#loginPage()}.
88: *
89: * @return page a caller is directed to after an authentication (login) error
90: */
91: @Nonbinding
92: String errorPage() default "/login-error";
93:
94: /**
95: * Supports inline instantiation of the LoginToContinue annotation.
96: *
97: * @since 3.0
98: */
99: public static final class Literal extends AnnotationLiteral<LoginToContinue> implements LoginToContinue {
100: private static final long serialVersionUID = 1L;
101:
102: private final String loginPage;
103: private final boolean useForwardToLogin;
104: private final String useForwardToLoginExpression;
105: private final String errorPage;
106:
107: /**
108: * Default instance of the {@link LoginToContinue} Interceptor Binding.
109: */
110: public static final Literal INSTANCE = of("/login", true, "", "/login-error");
111:
112: /**
113: * Instance of the {@link LoginToContinue} Interceptor Binding.
114: *
115: * @param loginPage page a caller is directed to to authenticate (login)
116: * @param useForwardToLogin true if a forward is to be used, false for a redirect
117: * @param useForwardToLoginExpression an expression evaluating to true if a forward is to be used, false for a redirect
118: * @param errorPage page a caller is directed to after an authentication (login) error
119: * @return instance of the {@link LoginToContinue} Interceptor Binding.
120: */
121: public static Literal of(String loginPage, boolean useForwardToLogin, String useForwardToLoginExpression, String errorPage) {
122: return new Literal(loginPage, useForwardToLogin, useForwardToLoginExpression, errorPage);
123: }
124:
125: private Literal(String loginPage, boolean useForwardToLogin, String useForwardToLoginExpression, String errorPage) {
126: this.loginPage = loginPage;
127: this.useForwardToLogin = useForwardToLogin;
128: this.useForwardToLoginExpression = useForwardToLoginExpression;
129: this.errorPage = errorPage;
130: }
131:
132: @Override
133: public String loginPage() {
134: return loginPage;
135: }
136:
137: @Override
138: public boolean useForwardToLogin() {
139: return useForwardToLogin;
140: }
141:
142: @Override
143: public String useForwardToLoginExpression() {
144: return useForwardToLoginExpression;
145: }
146:
147: @Override
148: public String errorPage() {
149: return errorPage;
150: }
151:
152: }
153:
154: }