Skip to content

Commit

Permalink
#167 Fixed whitespace errors (mostly tabs to spaces)
Browse files Browse the repository at this point in the history
Signed-off-by: arjantijms <arjan.tijms@gmail.com>
  • Loading branch information
arjantijms committed Oct 7, 2020
1 parent 34a91c0 commit aef34f6
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,28 @@ public enum AuthenticationStatus {
* mechanism is called, but authentication is optional and would only take place when for
* instance a specific request header is present.
*/
NOT_DONE,
/**
* The authentication mechanism was called and a multi-step authentication dialog with the caller
* has been started (for instance, the caller has been redirected to a login page). Simply said
* authentication is "in progress". Calling application code (if any) should not write to the response
* when this status is received.
*/
SEND_CONTINUE,
/**
* The authentication mechanism was called and the caller was successfully authenticated. After the
* Jakarta EE server has processed this outcome, the caller principal is available.
*/
SUCCESS,
/**
* The authentication mechanism was called but the caller was <em>not</em> successfully authenticated and
* therefore the caller principal will not be made available.
* <p>
* Note that this status should be used to indicate a logical problem (such as a credential not matching or a caller
* ID that can not be found). Exceptions should be used for system level problems (such as a database connection timing out).
*/
SEND_FAILURE
NOT_DONE,
/**
* The authentication mechanism was called and a multi-step authentication dialog with the caller
* has been started (for instance, the caller has been redirected to a login page). Simply said
* authentication is "in progress". Calling application code (if any) should not write to the response
* when this status is received.
*/
SEND_CONTINUE,
/**
* The authentication mechanism was called and the caller was successfully authenticated. After the
* Jakarta EE server has processed this outcome, the caller principal is available.
*/
SUCCESS,
/**
* The authentication mechanism was called but the caller was <em>not</em> successfully authenticated and
* therefore the caller principal will not be made available.
* <p>
* Note that this status should be used to indicate a logical problem (such as a credential not matching or a caller
* ID that can not be found). Exceptions should be used for system level problems (such as a database connection timing out).
*/
SEND_FAILURE
}
85 changes: 41 additions & 44 deletions api/src/main/java/jakarta/security/enterprise/SecurityContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
import java.security.Principal;
import java.util.Set;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import jakarta.security.enterprise.authentication.mechanism.http.AuthenticationParameters;
import jakarta.security.enterprise.authentication.mechanism.http.HttpAuthenticationMechanism;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
* The SecurityContext provides an access point for programmatic security; an injectable type that is intended to be
Expand All @@ -33,7 +32,6 @@
* Unless otherwise indicated, this type must be usable in all Jakarta EE containers, specifically the Jakarta Servlet
* and Jakarta Enterprise Beans containers.
*
*
*/
public interface SecurityContext {

Expand All @@ -43,7 +41,7 @@ public interface SecurityContext {
*
* @return Principal representing the name of the current authenticated user, or null if not authenticated.
*/
Principal getCallerPrincipal();
Principal getCallerPrincipal();

/**
* Retrieve all Principals of the given type from the authenticated caller's Subject,
Expand All @@ -64,29 +62,28 @@ public interface SecurityContext {
*/
<T extends Principal> Set<T> getPrincipalsByType(Class<T> pType);

/**
* Checks whether the authenticated caller is included in the specified logical <em>application</em> "role".
* If the caller is not authenticated, this always returns <code>false</code>.
*
* <p>
* This method <em>can not</em> be used to test for roles that are mapped to specific named Jakarta Servlets or
* named Jakarta Enterprise Beans. For a Servlet an example of this would be the <code>role-name</code> nested in a
* <code>security-role-ref</code> element nested in a <code>servlet</code> element in <code>web.xml</code>.
*
* <p>
* Should code in either such Jakarta Servlet or Jakarta Enterprise Bean wish to take such mapped (aka referenced, linked)
* roles into account, the facilities for that specific container should be used instead. For instance for Servlet that
* would be {@link HttpServletRequest#isUserInRole(String)} and for Jakarta Enterprise Beans that would be
* {@link jakarta.ejb.SessionContext#isCallerInRole(String)}.
*
*
* @param role a <code>String</code> specifying the name of the logical application role
* @return <code>true</code> if the authenticated caller is in the given role, false if the caller is not authentication or
* is not in the given role.
*/
boolean isCallerInRole(String role);
/**
* Checks whether the authenticated caller is included in the specified logical <em>application</em> "role".
* If the caller is not authenticated, this always returns <code>false</code>.
*
* <p>
* This method <em>can not</em> be used to test for roles that are mapped to specific named Jakarta Servlets or
* named Jakarta Enterprise Beans. For a Servlet an example of this would be the <code>role-name</code> nested in a
* <code>security-role-ref</code> element nested in a <code>servlet</code> element in <code>web.xml</code>.
*
* <p>
* Should code in either such Jakarta Servlet or Jakarta Enterprise Bean wish to take such mapped (aka referenced, linked)
* roles into account, the facilities for that specific container should be used instead. For instance for Servlet that
* would be {@link HttpServletRequest#isUserInRole(String)} and for Jakarta Enterprise Beans that would be
* {@link jakarta.ejb.SessionContext#isCallerInRole(String)}.
*
* @param role a <code>String</code> specifying the name of the logical application role
* @return <code>true</code> if the authenticated caller is in the given role, false if the caller is not authentication or
* is not in the given role.
*/
boolean isCallerInRole(String role);

/**
/**
* Checks whether the caller has access to the provided "web resource" using the given methods,
* as specified by section 13.8 of the Servlet specification.
*
Expand All @@ -101,13 +98,13 @@ public interface SecurityContext {
*
* @return <code>true</code> if the caller has access to the web resource using one of the given methods, <code>false</code> otherwise.
*/
boolean hasAccessToWebResource(String resource, String... methods);
boolean hasAccessToWebResource(String resource, String... methods);

/**
* Signal to the container (programmatically trigger) that it should start or continue a web/HTTP based authentication dialog with
* the caller.
*
* <p>
/**
* Signal to the container (programmatically trigger) that it should start or continue a web/HTTP based authentication dialog with
* the caller.
*
* <p>
* Programmatically triggering means that the container responds as if the caller had attempted to access a constrained resource
* and acts by invoking a configured authentication mechanism (such as the {@link HttpAuthenticationMechanism}).
*
Expand All @@ -117,17 +114,17 @@ public interface SecurityContext {
* started. A new dialog can be forced to be started regardless of one being in progress or not by providing a value of
* <code>true</code> for the {@link AuthenticationParameters#newAuthentication} parameter with this call.
*
* <p>
* This method requires an {@link HttpServletRequest} and {@link HttpServletResponse} argument to be passed in, and
* can therefore only be used in a valid Servlet context.
*
* @param request The <code>HttpServletRequest</code> associated with the current web resource invocation.
* @param response The <code>HttpServletResponse</code> associated with the given <code>HttpServletRequest</code>.
* @param parameters The parameters that are provided along with a programmatic authentication request, for instance the credentials.
* collected by the application for continuing an authentication dialog.
*
* @return The state of the authentication mechanism after being triggered by this call
*/
* <p>
* This method requires an {@link HttpServletRequest} and {@link HttpServletResponse} argument to be passed in, and
* can therefore only be used in a valid Servlet context.
*
* @param request The <code>HttpServletRequest</code> associated with the current web resource invocation.
* @param response The <code>HttpServletResponse</code> associated with the given <code>HttpServletRequest</code>.
* @param parameters The parameters that are provided along with a programmatic authentication request, for instance the credentials.
* collected by the application for continuing an authentication dialog.
*
* @return The state of the authentication mechanism after being triggered by this call
*/
AuthenticationStatus authenticate(HttpServletRequest request, HttpServletResponse response, AuthenticationParameters parameters);

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public void clear() {
}

public boolean compareTo(String password) {
if (password == null) {
return false;
}
return Arrays.equals(password.toCharArray(), value);
if (password == null) {
return false;
}
return Arrays.equals(password.toCharArray(), value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Set;

import jakarta.security.auth.message.module.ServerAuthModule;

import jakarta.security.enterprise.CallerPrincipal;
import jakarta.security.enterprise.authentication.mechanism.http.HttpAuthenticationMechanism;
import jakarta.security.enterprise.credential.Credential;
Expand All @@ -44,7 +43,7 @@
* such as a database, LDAP server, or file.
*/
public interface IdentityStore {

/**
* Default set of validation types. Contains {@code VALIDATE} and {@code PROVIDE_GROUPS}.
*/
Expand All @@ -63,7 +62,7 @@ public CredentialValidationResult validate(UsernamePasswordCredential usernamePa
// Implementation ...
return INVALID_RESULT;
}
}
* }</pre></blockquote>
* <p>
Expand All @@ -74,23 +73,23 @@ public CredentialValidationResult validate(UsernamePasswordCredential usernamePa
* This method returns a {@link CredentialValidationResult} representing the result of the validation attempt:
* whether it succeeded or failed, and, for a successful validation, the {@link CallerPrincipal}, and possibly
* groups or other attributes, of the caller.
*
*
* @param credential The credential to validate.
* @return The validation result.
*/
default CredentialValidationResult validate(Credential credential) {
try {
return CredentialValidationResult.class.cast(
MethodHandles.lookup()
.bind(this, "validate", methodType(CredentialValidationResult.class, credential.getClass()))
.invoke(credential));
return CredentialValidationResult.class.cast(
MethodHandles.lookup()
.bind(this, "validate", methodType(CredentialValidationResult.class, credential.getClass()))
.invoke(credential));
} catch (NoSuchMethodException e) {
return NOT_VALIDATED_RESULT;
} catch (Throwable e) {
throw new IllegalStateException(e);
}
} catch (Throwable e) {
throw new IllegalStateException(e);
}
}

/**
* Returns groups for the caller, who is identified by the {@link CallerPrincipal}
* (and potentially other values) found in the {@code validationResult} parameter.
Expand All @@ -111,49 +110,49 @@ default CredentialValidationResult validate(Credential credential) {
* @throws SecurityException May be thrown if the calling code does not have {@link IdentityStorePermission}.
*/
default Set<String> getCallerGroups(CredentialValidationResult validationResult) {
return emptySet();
return emptySet();
}

/**
* Determines the order of invocation for multiple {@link IdentityStore}s.
* Stores with a lower priority value are consulted first.
*
*
* @return The priority value. Lower values indicate higher priorities.
*/
default int priority() {
return 100;
}

/**
* Determines the type of validation the {@link IdentityStore} should be used for.
* Determines the type of validation the {@link IdentityStore} should be used for.
* By default, its used for credential validation AND providing groups.
* <p>
* Implementations of this API should not return a direct reference
* to a {@link Set} used internally to represent an {@link IdentityStore}'s validation types,
* unless it is an immutable {@link Set}. Callers of the API should be aware that
* the returned {@link Set} may be immutable, or a copy, and that, in any case,
* it should not be modified by the caller.
*
*
* @return {@link Set} containing the validation types enabled for the {@link IdentityStore}.
*/
default Set<ValidationType> validationTypes() {
return DEFAULT_VALIDATION_TYPES;
}



/**
* Determines the type of validation (operations) that should be done by this store.
* <b>NOTE:</b> This does not set or determine what the {@link IdentityStore} is capable of,
* but only what the store is configured to be used for.
*/
enum ValidationType {

/**
* Only validation is performed, so no groups, are taken from this store.
**/
VALIDATE,

/**
* Only groups for a principal, possibly established by another IdentityStore, are taken from this store.
*/
Expand Down

0 comments on commit aef34f6

Please sign in to comment.