Class Security

java.lang.Object
org.codice.ddf.security.impl.Security
All Implemented Interfaces:
org.codice.ddf.security.Security

public class Security extends Object implements org.codice.ddf.security.Security
Provides common security related utility functions.
  • Constructor Details

    • Security

      public Security()
  • Method Details

    • getSubject

      public ddf.security.Subject getSubject(String username, String password, String ip)
      Gets the Subject given a user name and password.
      Specified by:
      getSubject in interface org.codice.ddf.security.Security
      Parameters:
      username - username
      password - password
      Returns:
      Subject associated with the user name and password provided
    • javaSubjectHasAdminRole

      public final boolean javaSubjectHasAdminRole()
      Determines if the current Java Subject has the admin role.
      Specified by:
      javaSubjectHasAdminRole in interface org.codice.ddf.security.Security
      Returns:
      true if the Java Subject exists and has the admin role, false otherwise
      Throws:
      SecurityException - if a security manager exists and the AuthPermission("getSubject") permission is not authorized
    • runWithSubjectOrElevate

      public <T> T runWithSubjectOrElevate(Callable<T> codeToRun) throws ddf.security.service.SecurityServiceException, InvocationTargetException
      Runs the Callable in the current thread as the current security framework's Subject. If the security framework's Subject is not currently set and the Java Subject contains the admin role, elevates and runs the Callable as the system Subject.
      Specified by:
      runWithSubjectOrElevate in interface org.codice.ddf.security.Security
      Type Parameters:
      T - type of the returned value
      Parameters:
      codeToRun - code to run
      Returns:
      value returned by the Callable
      Throws:
      ddf.security.service.SecurityServiceException - if the current subject didn' have enough permissions to run the code
      SecurityException - if a security manager exists and the AuthPermission("getSystemSubject") or AuthPermission("getSubject") permissions are not authorized
      InvocationTargetException - wraps any exception thrown by Callable.call(). Callable exception can be retrieved using the InvocationTargetException.getCause().
    • getSystemSubject

      @Nullable public final ddf.security.Subject getSystemSubject()
      Gets the Subject associated with this system. Uses a cached subject since the subject will not change between calls.
      Specified by:
      getSystemSubject in interface org.codice.ddf.security.Security
      Returns:
      system's Subject or null if unable to get the system's Subject
      Throws:
      SecurityException - if a security manager exists and the AuthPermission("getSystemSubject") or AuthPermission("getSubject") permissions are not authorized
    • getGuestSubject

      public ddf.security.Subject getGuestSubject(String ipAddress)
      Gets the guest Subject associated with the specified IP. Uses a cached subject when possible since the subject will not change between calls.
      Specified by:
      getGuestSubject in interface org.codice.ddf.security.Security
      Returns:
      system's Subject
    • getSecurityManager

      @Nullable public ddf.security.service.SecurityManager getSecurityManager()
      Gets a reference to the SecurityManager.
      Returns:
      reference to the SecurityManager or null if unable to get the SecurityManager
    • runAsAdmin

      public <T> T runAsAdmin(PrivilegedAction<T> action)
      Specified by:
      runAsAdmin in interface org.codice.ddf.security.Security
    • runAsAdminWithException

      public <T> T runAsAdminWithException(PrivilegedExceptionAction<T> action) throws PrivilegedActionException
      Specified by:
      runAsAdminWithException in interface org.codice.ddf.security.Security
      Throws:
      PrivilegedActionException
    • getSystemKeyStore

      public KeyStore getSystemKeyStore()
      Specified by:
      getSystemKeyStore in interface org.codice.ddf.security.Security
    • setSecurityLogger

      public void setSecurityLogger(ddf.security.audit.SecurityLogger securityLogger)