Package org.codice.ddf.security.impl
Class Security
java.lang.Object
org.codice.ddf.security.impl.Security
- All Implemented Interfaces:
org.codice.ddf.security.Security
Provides common security related utility functions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionddf.security.SubjectgetGuestSubject(String ipAddress) Gets the guestSubjectassociated with the specified IP.ddf.security.service.SecurityManagerGets a reference to theSecurityManager.ddf.security.SubjectgetSubject(String username, String password, String ip) Gets theSubjectgiven a user name and password.final ddf.security.SubjectGets theSubjectassociated with this system.final booleanDetermines if the current JavaSubjecthas the admin role.<T> TrunAsAdmin(PrivilegedAction<T> action) <T> TrunAsAdminWithException(PrivilegedExceptionAction<T> action) <T> TrunWithSubjectOrElevate(Callable<T> codeToRun) Runs theCallablein the current thread as the current security framework'sSubject.voidsetSecurityLogger(ddf.security.audit.SecurityLogger securityLogger)
-
Constructor Details
-
Security
public Security()
-
-
Method Details
-
getSubject
Gets theSubjectgiven a user name and password.- Specified by:
getSubjectin interfaceorg.codice.ddf.security.Security- Parameters:
username- usernamepassword- password- Returns:
Subjectassociated with the user name and password provided
-
javaSubjectHasAdminRole
public final boolean javaSubjectHasAdminRole()Determines if the current JavaSubjecthas the admin role.- Specified by:
javaSubjectHasAdminRolein interfaceorg.codice.ddf.security.Security- Returns:
trueif the JavaSubjectexists and has the admin role,falseotherwise- Throws:
SecurityException- if a security manager exists and theAuthPermission("getSubject")permission is not authorized
-
runWithSubjectOrElevate
public <T> T runWithSubjectOrElevate(Callable<T> codeToRun) throws ddf.security.service.SecurityServiceException, InvocationTargetException Runs theCallablein the current thread as the current security framework'sSubject. If the security framework'sSubjectis not currently set and the Java Subject contains the admin role, elevates and runs theCallableas the systemSubject.- Specified by:
runWithSubjectOrElevatein interfaceorg.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 codeSecurityException- if a security manager exists and theAuthPermission("getSystemSubject")orAuthPermission("getSubject")permissions are not authorizedInvocationTargetException- wraps any exception thrown byCallable.call().Callableexception can be retrieved using theInvocationTargetException.getCause().
-
getSystemSubject
@Nullable public final ddf.security.Subject getSystemSubject()Gets theSubjectassociated with this system. Uses a cached subject since the subject will not change between calls.- Specified by:
getSystemSubjectin interfaceorg.codice.ddf.security.Security- Returns:
- system's
Subjectornullif unable to get the system'sSubject - Throws:
SecurityException- if a security manager exists and theAuthPermission("getSystemSubject")orAuthPermission("getSubject")permissions are not authorized
-
getGuestSubject
Gets the guestSubjectassociated with the specified IP. Uses a cached subject when possible since the subject will not change between calls.- Specified by:
getGuestSubjectin interfaceorg.codice.ddf.security.Security- Returns:
- system's
Subject
-
getSecurityManager
@Nullable public ddf.security.service.SecurityManager getSecurityManager()Gets a reference to theSecurityManager.- Returns:
- reference to the
SecurityManagerornullif unable to get theSecurityManager
-
runAsAdmin
- Specified by:
runAsAdminin interfaceorg.codice.ddf.security.Security
-
runAsAdminWithException
public <T> T runAsAdminWithException(PrivilegedExceptionAction<T> action) throws PrivilegedActionException - Specified by:
runAsAdminWithExceptionin interfaceorg.codice.ddf.security.Security- Throws:
PrivilegedActionException
-
getSystemKeyStore
- Specified by:
getSystemKeyStorein interfaceorg.codice.ddf.security.Security
-
setSecurityLogger
public void setSecurityLogger(ddf.security.audit.SecurityLogger securityLogger)
-