Skip to content

Package: InMemoryIdentityStoreDefinition$Credentials

InMemoryIdentityStoreDefinition$Credentials

Coverage

1: /*
2: * Copyright (c) 2023, 2024 Contributors to Eclipse Foundation.
3: * Copyright (c) 2015, 2020 Oracle and/or its affiliates. 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: package jakarta.security.enterprise.identitystore;
18:
19: import static jakarta.security.enterprise.identitystore.IdentityStore.ValidationType.PROVIDE_GROUPS;
20: import static jakarta.security.enterprise.identitystore.IdentityStore.ValidationType.VALIDATE;
21: import static java.lang.annotation.ElementType.FIELD;
22: import static java.lang.annotation.ElementType.METHOD;
23: import static java.lang.annotation.ElementType.PARAMETER;
24: import static java.lang.annotation.ElementType.TYPE;
25: import static java.lang.annotation.RetentionPolicy.RUNTIME;
26:
27: import jakarta.security.enterprise.identitystore.IdentityStore.ValidationType;
28: import java.lang.annotation.Retention;
29: import java.lang.annotation.Target;
30:
31: /**
32: * Annotation used to define a container provided {@link IdentityStore} that stores
33: * caller credentials and identity attributes (together caller identities) in an
34: * in-memory store, and make that implementation available as an enabled CDI bean.
35: *
36: * <p>
37: * The data in this store is set at definition time only via the {@link #value()} attribute
38: * of this annotation.
39: *
40: * <p>
41: * The following shows an example:
42: *
43: * <pre>
44: * <code>
45: * {@literal @}InMemoryIdentityStoreDefinition({
46: * {@literal @}Credentials(callerName = "peter", password = "secret1", groups = { "foo", "bar" }),
47: * {@literal @}Credentials(callerName = "john", password = "secret2", groups = { "foo", "kaz" }),
48: * {@literal @}Credentials(callerName = "carla", password = "secret3", groups = { "foo" }) })
49: * </code>
50: * </pre>
51: *
52: * @since 4.0
53: */
54: @Retention(RUNTIME)
55: @Target(TYPE)
56: public @interface InMemoryIdentityStoreDefinition {
57:
58: /**
59: * Defines the caller identities stored in the in-memory identity store
60: *
61: * @return caller identities stored in the in-memory identity store
62: */
63: Credentials[] value() default {};
64:
65: /**
66: * Determines the order in case multiple IdentityStores are found.
67: * @return the priority.
68: */
69: int priority() default 90;
70:
71: /**
72: * Allow <code>priority</code> to be specified as a Jakarta Expression Language expression.
73: * If set, overrides any value set with <code>priority</code>.
74: *
75: * @return the <code>priority</code> Jakarta Expression Language expression
76: */
77: String priorityExpression() default "";
78:
79: /**
80: * Determines what the identity store is used for
81: *
82: * @return the type the identity store is used for
83: */
84: ValidationType[] useFor() default {VALIDATE, PROVIDE_GROUPS};
85:
86: /**
87: * Allow <code>useFor</code> to be specified as an Jakarta Expression Language expression.
88: * If set, overrides any value set with useFor.
89: *
90: * @return the <code>useFor</code> Jakarta Expression Language expression
91: */
92: String useForExpression() default "";
93:
94: /**
95: * <code>Credentials</code> define a single caller identity for
96: * use with the {@link InMemoryIdentityStoreDefinition} annotation.
97: *
98: */
99: @Retention(RUNTIME)
100: @Target({ TYPE, METHOD, FIELD, PARAMETER })
101: public @interface Credentials {
102:
103: /**
104: * Name of caller. This is the name a caller uses to authenticate with.
105: *
106: * @return Name of caller
107: */
108: String callerName();
109:
110: /**
111: * A text-based password used by the caller to authenticate.
112: *
113: * @return A text-based password
114: */
115: String password();
116:
117: /**
118: * The optional list of groups that the specified caller is in.
119: *
120: * @return optional list of groups
121: */
122: String[] groups() default {};
123: }
124:
125: }