org.modeshape.jcr.security

## Class JaasSecurityContext

- java.lang.Object
- - org.modeshape.jcr.security.JaasSecurityContext

- All Implemented Interfaces:
    SecurityContext

      @NotThreadSafe
      public class JaasSecurityContext
      extends Object
      implements SecurityContext

  JAAS-based `security context` that provides authentication and authorization through the JAAS `login context`.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `JaasSecurityContext.UserPasswordCallbackHandler` A simple `callback handler` implementation that attempts to provide a user ID and password to any callbacks that it handles.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JaasSecurityContext(LoginContext loginContext)` Creates a new JAAS security context based on the given login context.
    `JaasSecurityContext(String realmName)` Create a `JaasSecurityContext` with the supplied `application configuration name`.
    `JaasSecurityContext(String realmName, CallbackHandler callbackHandler)` Create a `JaasSecurityContext` with the supplied `application configuration name` and the given callback handler.
    `JaasSecurityContext(String realmName, String userId, char[] password)` Create a `JaasSecurityContext` with the supplied `application configuration name` and a `JAAS callback handler` to create a new `JAAS login context` with the given user ID and password.
    `JaasSecurityContext(String realmName, Subject subject)` Create a `JaasSecurityContext` with the supplied `application configuration name` and a `JAAS subject`.
    `JaasSecurityContext(Subject subject)` Creates a new JAAS security context based on the user name and roles from the given subject.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getUserName()` Returns the authenticated user's name
    `boolean` | `hasRole(String roleName)` Returns whether the authenticated user has the given role.
    `boolean` | `isAnonymous()` Return whether this security context is an anonymous context.
    `void` | `logout()` Logs the user out of the authentication mechanism.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JaasSecurityContext

          public JaasSecurityContext(String realmName)
                              throws LoginException

      Create a `JaasSecurityContext` with the supplied `application configuration name`.
      Parameters:
        `realmName` - the name of the `JAAS application configuration name` ; may not be null
      Throws:
        `IllegalArgumentException` - if the `name` is null
        `LoginException` - if there `name` is invalid (or there is no login context named "other"), or if the default callback handler JAAS property was not set or could not be loaded

    - #### JaasSecurityContext

          public JaasSecurityContext(String realmName,
                             Subject subject)
                              throws LoginException

      Create a `JaasSecurityContext` with the supplied `application configuration name` and a `JAAS subject`.
      Parameters:
        `realmName` - the name of the `JAAS application configuration name`
        `subject` - the subject to authenticate
      Throws:
        `LoginException` - if there `name` is invalid (or there is no login context named "other"), if the default callback handler JAAS property was not set or could not be loaded, or if the `subject` is null or unknown

    - #### JaasSecurityContext

          public JaasSecurityContext(String realmName,
                             String userId,
                             char[] password)
                              throws LoginException

      Create a `JaasSecurityContext` with the supplied `application configuration name` and a `JAAS callback handler` to create a new `JAAS login context` with the given user ID and password.
      Parameters:
        `realmName` - the name of the `JAAS application configuration name`
        `userId` - the user ID to use for authentication
        `password` - the password to use for authentication
      Throws:
        `LoginException` - if there `name` is invalid (or there is no login context named "other"), or if the `callbackHandler` is null

    - #### JaasSecurityContext

          public JaasSecurityContext(String realmName,
                             CallbackHandler callbackHandler)
                              throws LoginException

      Create a `JaasSecurityContext` with the supplied `application configuration name` and the given callback handler.
      Parameters:
        `realmName` - the name of the `JAAS application configuration name` ; may not be null
        `callbackHandler` - the callback handler to use during the login process; may not be null
      Throws:
        `LoginException` - if there `name` is invalid (or there is no login context named "other"), or if the `callbackHandler` is null

    - #### JaasSecurityContext

          public JaasSecurityContext(LoginContext loginContext)
                              throws LoginException

      Creates a new JAAS security context based on the given login context. If `login` has not already been invoked on the login context, this constructor will attempt to invoke it.
      Parameters:
        `loginContext` - the login context to use; may not be null
      Throws:
        `LoginException` - if the context has not already had `its login method` invoked and an error occurs attempting to invoke the login method.
      See Also:
        `LoginContext`

    - #### JaasSecurityContext

          public JaasSecurityContext(Subject subject)

      Creates a new JAAS security context based on the user name and roles from the given subject.
      Parameters:
        `subject` - the subject to use as the provider of the user name and roles for this security context; may not be null

  - ### Method Detail

    - #### isAnonymous

          public boolean isAnonymous()

      Description copied from interface: `SecurityContext`
      Return whether this security context is an anonymous context.
      Specified by:
        `isAnonymous` in interface `SecurityContext`
      Returns:
        true if this context represents an anonymous user, or false otherwise

    - #### getUserName

          public String getUserName()

      Description copied from interface: `SecurityContext`
      Returns the authenticated user's name
      Specified by:
        `getUserName` in interface `SecurityContext`
      Returns:
        the authenticated user's name

    - #### hasRole

          public boolean hasRole(String roleName)

      Description copied from interface: `SecurityContext`
      Returns whether the authenticated user has the given role.
      Specified by:
        `hasRole` in interface `SecurityContext`
      Parameters:
        `roleName` - the name of the role to check
      Returns:
        true if the user has the role and is logged in; false otherwise

    - #### logout

          public void logout()

      Description copied from interface: `SecurityContext`
      Logs the user out of the authentication mechanism.

      For some authentication mechanisms, this will be implemented as a no-op.

      Specified by:
        `logout` in interface `SecurityContext`

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.