Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit ba209bd

Browse files
committed
Added simplified identity store proposal
1 parent 559bc88 commit ba209bd

16 files changed

Lines changed: 1002 additions & 0 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
= Proposed read-only simplified Identity Store
2+
3+
A somewhat simplified variant of the the "identity-store-read-only" proposal.
4+
5+
In particular, this proposal omits the persistence and query packages and adds
6+
"[storeType]Definition" annotations that in analogy to @DataSourceDefinition
7+
are intended to instruct the container to make an implementation of the requested type available.
8+
9+
10+
11+
12+
13+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>net.java.jsr375</groupId>
8+
<artifactId>identity-store</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>identity-store-readonly-simplified</artifactId>
13+
14+
</project>
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package javax.security.identitystore;
41+
42+
import static java.util.Collections.unmodifiableList;
43+
import static javax.security.identitystore.CredentialValidationResult.Status.INVALID;
44+
import static javax.security.identitystore.CredentialValidationResult.Status.NOT_VALIDATED;
45+
import static javax.security.identitystore.CredentialValidationResult.Status.VALID;
46+
47+
import java.util.ArrayList;
48+
import java.util.List;
49+
50+
/**
51+
* <code>CredentialValidationResult</code> is the result from an attempt to
52+
* validate an instance of
53+
* {@link javax.security.identitystore.credential.Credential}.
54+
*
55+
* @see javax.security.identitystore.IdentityStore#validate
56+
*/
57+
public class CredentialValidationResult {
58+
59+
public static final CredentialValidationResult INVALID_RESULT = new CredentialValidationResult(INVALID, null, null, null);
60+
public static final CredentialValidationResult NOT_VALIDATED_RESULT = new CredentialValidationResult(NOT_VALIDATED, null, null, null);
61+
62+
private final String callerName;
63+
private final Status status;
64+
private final List<String> roles;
65+
private final List<String> groups;
66+
67+
public enum Status {
68+
/**
69+
* Indicates that the credential could not be validated, for example, if
70+
* no suitable
71+
* {@link javax.security.identitystore.credential.CredentialValidator}
72+
* could be found.
73+
*/
74+
NOT_VALIDATED,
75+
76+
/**
77+
* Indicates that the credential is not valid after a validation
78+
* attempt.
79+
*/
80+
INVALID,
81+
82+
/**
83+
* Indicates that the credential is valid after a validation attempt.
84+
*/
85+
VALID
86+
};
87+
88+
public CredentialValidationResult(Status status, String callerName, List<String> groups) {
89+
this(status, callerName, groups, null);
90+
}
91+
92+
/**
93+
* Constructor
94+
*
95+
* @param status
96+
* Validation status
97+
* @param callerName
98+
* Validated caller
99+
* @param groups
100+
* Groups associated with the caller from the identity store
101+
* @param roles
102+
* Roles associated with the caller from the identity store
103+
*/
104+
public CredentialValidationResult(Status status, String callerName, List<String> groups, List<String> roles) {
105+
106+
if (null == status)
107+
throw new NullPointerException("status");
108+
109+
this.status = status;
110+
this.callerName = callerName;
111+
112+
if (VALID == status) {
113+
if (null != groups)
114+
groups = unmodifiableList(new ArrayList<>(groups));
115+
this.groups = groups;
116+
117+
if (null != roles)
118+
roles = unmodifiableList(new ArrayList<>(roles));
119+
this.roles = roles;
120+
} else {
121+
this.groups = null;
122+
this.roles = null;
123+
}
124+
}
125+
126+
/**
127+
* Determines the validation status.
128+
*
129+
* @return The validation status
130+
*/
131+
public Status getStatus() {
132+
return status;
133+
}
134+
135+
/**
136+
* Determines the Caller used to validate the credential.
137+
*
138+
* @return The caller name, <code>null</code> if {@link #getStatus} does not
139+
* return {@link Status#VALID VALID}.
140+
*/
141+
public String getCallerName() {
142+
return callerName;
143+
}
144+
145+
/**
146+
* Determines the list of groups that the specified Caller is in, based on
147+
* the associated persistence store..
148+
*
149+
* @return The list of groups that the specified Caller is in, empty if
150+
* none. <code>null</code> if {@link #getStatus} does not return
151+
* {@link Status#VALID VALID} or if the identity store does not
152+
* support groups.
153+
*/
154+
public List<String> getCallerGroups() {
155+
return groups;
156+
}
157+
158+
/**
159+
* Determines the list of roles that the specified caller is in, based on
160+
* the associated persistence store. The returned role list would include
161+
* roles directly assigned to the Caller, and roles assigned to groups which
162+
* contain the Caller.
163+
*
164+
* @return The list of roles that the specified caller is in, empty if none.
165+
* <code>null</code> if {@link #getStatus} does not return
166+
* {@link Status#VALID VALID} or if the identity store does not
167+
* support roles.
168+
*/
169+
public List<String> getCallerRoles() {
170+
return roles;
171+
}
172+
173+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package javax.security.identitystore;
41+
42+
import javax.security.identitystore.credential.Credential;
43+
44+
/**
45+
* <code>IdentityStore</code> is a mechanism for validating a Caller's
46+
* credentials and accessing a Caller's identity attributes, and would be used
47+
* by an authentication mechanism, such as JASPIC. An <code>IdentityStore</code>
48+
* obtains identity data from a persistence mechanism, such as a file, database,
49+
* or LDAP.
50+
*/
51+
public interface IdentityStore {
52+
53+
/**
54+
* Validates the given credential.
55+
*
56+
* @param credential
57+
* The credential
58+
* @return The validation result, including associated caller roles and
59+
* groups.
60+
*/
61+
public CredentialValidationResult validate(Credential credential);
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package javax.security.identitystore.annotation;
2+
3+
import static java.lang.annotation.ElementType.FIELD;
4+
import static java.lang.annotation.ElementType.METHOD;
5+
import static java.lang.annotation.ElementType.PARAMETER;
6+
import static java.lang.annotation.ElementType.TYPE;
7+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
8+
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.Target;
11+
12+
@Retention(RUNTIME)
13+
@Target({ TYPE, METHOD, FIELD, PARAMETER })
14+
public @interface Credentials {
15+
String callerName();
16+
17+
String password();
18+
19+
String[] groups() default {};
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package javax.security.identitystore.annotation;
2+
3+
import static java.lang.annotation.ElementType.FIELD;
4+
import static java.lang.annotation.ElementType.METHOD;
5+
import static java.lang.annotation.ElementType.PARAMETER;
6+
import static java.lang.annotation.ElementType.TYPE;
7+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
8+
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.Target;
11+
12+
@Retention(RUNTIME)
13+
@Target({ TYPE, METHOD, FIELD, PARAMETER })
14+
public @interface DataBaseIdentityStoreDefinition {
15+
16+
String dataSourceLookup() default "java:comp/DefaultDataSource"; // default data source when omitted
17+
String callerQuery();
18+
String groupsQuery();
19+
String hashAlgorithm() default ""; // default no hash (for now) todo: make enum?
20+
String hashEncoding() default ""; // default no encoding (for now) todo: make enum?
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package javax.security.identitystore.annotation;
2+
3+
import static java.lang.annotation.ElementType.FIELD;
4+
import static java.lang.annotation.ElementType.METHOD;
5+
import static java.lang.annotation.ElementType.PARAMETER;
6+
import static java.lang.annotation.ElementType.TYPE;
7+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
8+
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.Target;
11+
12+
@Retention(RUNTIME)
13+
@Target({ TYPE, METHOD, FIELD, PARAMETER })
14+
public @interface EmbeddedIdentityStoreDefinition {
15+
16+
Credentials[] value() default {};
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package javax.security.identitystore.annotation;
2+
3+
import static java.lang.annotation.ElementType.FIELD;
4+
import static java.lang.annotation.ElementType.METHOD;
5+
import static java.lang.annotation.ElementType.PARAMETER;
6+
import static java.lang.annotation.ElementType.TYPE;
7+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
8+
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.Target;
11+
12+
@Retention(RUNTIME)
13+
@Target({ TYPE, METHOD, FIELD, PARAMETER })
14+
public @interface LdapIdentityStoreDefinition {
15+
16+
String url() default "";
17+
18+
String callerBaseDn() default "";
19+
String callerNameAttribute() default "uid";
20+
21+
String groupBaseDn() default "";
22+
String groupNameAttribute() default "cn";
23+
String groupCallerDnAttribute() default "member";
24+
25+
}

0 commit comments

Comments
 (0)