Package io.goobi.viewer.model.security
Class AccessConditionUtils
java.lang.Object
io.goobi.viewer.model.security.AccessConditionUtils
AccessConditionUtils class.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
addDownloadTicketToSession
(String pi, javax.servlet.http.HttpSession session) static boolean
addSessionPermission
(String attributeName, Object attributeValue, javax.servlet.http.HttpServletRequest request) static AccessPermission
checkAccess
(javax.servlet.http.HttpServletRequest request, String action, String pi, String contentFileName, boolean isThumbnail) checkAccess.static AccessPermission
checkAccessPermission
(List<LicenseType> allLicenseTypes, Set<String> requiredAccessConditions, String privilegeName, User user, String remoteAddress, Optional<ClientApplication> client, String query) Base method for checking access permissions of various types.static AccessPermission
checkAccessPermission
(Set<String> requiredAccessConditions, String privilegeName, String query, javax.servlet.http.HttpServletRequest request) checkAccessPermission.static Map<String,
AccessPermission> checkAccessPermissionByIdentiferForAllLogids
(String identifier, String privilegeName, javax.servlet.http.HttpServletRequest request) Checks whether the current users has the given access permissions each element of the record with the given identifier.static AccessPermission
checkAccessPermissionByIdentifierAndFileNameWithSessionMap
(javax.servlet.http.HttpServletRequest request, String pi, String contentFileName, String privilegeType) Checks access permission of the given privilege type for the given image and puts the permission status into the corresponding session map.static AccessPermission
checkAccessPermissionByIdentifierAndFilePathWithSessionMap
(javax.servlet.http.HttpServletRequest request, String filePath, String privilegeType) checkAccessPermissionByIdentifierAndFilePathWithSessionMap.static AccessPermission
checkAccessPermissionByIdentifierAndLogId
(String identifier, String logId, String privilegeName, javax.servlet.http.HttpServletRequest request) Checks whether the current users has the given access permissions to the element with the given identifier and LOGID.static AccessPermission
checkAccessPermissionByImageUrn
(String imageUrn, String privilegeName, javax.servlet.http.HttpServletRequest request) Checks whether the client may access an image (by image URN).static AccessPermission
checkAccessPermissionBySolrDoc
(org.apache.solr.common.SolrDocument doc, String originalQuery, String privilegeName, javax.servlet.http.HttpServletRequest request) static AccessPermission
checkAccessPermissionForImage
(javax.servlet.http.HttpServletRequest request, String pi, String contentFileName) Checks access permission for the given image and puts the permission status into the corresponding session map.static AccessPermission
checkAccessPermissionForPagePdf
(javax.servlet.http.HttpServletRequest request, PhysicalElement page) Checks access permission for the given image and puts the permission status into the corresponding session map.static AccessPermission
checkAccessPermissionForThumbnail
(javax.servlet.http.HttpServletRequest request, String pi, String contentFileName) Checks access permission for the given thumbnail and puts the permission status into the corresponding session map.static AccessPermission
checkContentFileAccessPermission
(String identifier, javax.servlet.http.HttpServletRequest request) Checks if the record with the given identifier should allow access to the given requeststatic int
clearSessionPermissions
(javax.servlet.http.HttpSession session) Removes privileges saved in the user session.getApplyingLicenses
(Optional<User> user, String ipAddress, LicenseType type, IDAO dao) List all licenses ("rights") that the given user and ipAddress is entitled to, either because they are directly given to the user, a group the user belongs to or to the given ipAddress, whether or not the given user existsstatic int
static Object
getSessionPermission
(String attributeName, javax.servlet.http.HttpServletRequest request) static boolean
isConcurrentViewsLimitEnabledForAnyAccessCondition
(List<String> accessConditions) static boolean
isFreeOpenAccess
(Set<String> requiredAccessConditions, Collection<LicenseType> allLicenseTypes) Check whether the requiredAccessConditions consist only of theOPENACCESS
condition and OPENACCESS is not contained in allLicenseTypes.static boolean
isHasDownloadTicket
(String pi, javax.servlet.http.HttpSession session) static boolean
isPrivilegeGrantedForDoc
(org.apache.solr.common.SolrDocument doc, String privilegeName, javax.servlet.http.HttpServletRequest request)
-
Method Details
-
checkAccess
public static AccessPermission checkAccess(javax.servlet.http.HttpServletRequest request, String action, String pi, String contentFileName, boolean isThumbnail) throws IndexUnreachableException, DAOException checkAccess.
- Parameters:
request
- aHttpServletRequest
object.action
- aString
object.pi
- aString
object.contentFileName
- aString
object.isThumbnail
- a boolean.- Returns:
AccessPermission
- Throws:
IndexUnreachableException
- if any.DAOException
- if any.
-
checkAccessPermissionByIdentifierAndLogId
public static AccessPermission checkAccessPermissionByIdentifierAndLogId(String identifier, String logId, String privilegeName, javax.servlet.http.HttpServletRequest request) throws IndexUnreachableException, DAOException, RecordNotFoundException Checks whether the current users has the given access permissions to the element with the given identifier and LOGID.- Parameters:
identifier
- The PI to check.logId
- The LOGID to check (optional).privilegeName
- Particular privilege for which to check the permission.request
- aHttpServletRequest
object.- Returns:
AccessPermission
- Throws:
IndexUnreachableException
- if any.DAOException
- if any.RecordNotFoundException
-
checkAccessPermissionBySolrDoc
public static AccessPermission checkAccessPermissionBySolrDoc(org.apache.solr.common.SolrDocument doc, String originalQuery, String privilegeName, javax.servlet.http.HttpServletRequest request) throws IndexUnreachableException, DAOException - Parameters:
doc
-originalQuery
-privilegeName
-request
-- Returns:
AccessPermission
- Throws:
IndexUnreachableException
DAOException
-
checkAccessPermissionByIdentiferForAllLogids
public static Map<String,AccessPermission> checkAccessPermissionByIdentiferForAllLogids(String identifier, String privilegeName, javax.servlet.http.HttpServletRequest request) throws IndexUnreachableException, DAOException Checks whether the current users has the given access permissions each element of the record with the given identifier.- Parameters:
identifier
- aString
object.privilegeName
- aString
object.request
- aHttpServletRequest
object.- Returns:
- Map with true/false for each LOGID
- Throws:
IndexUnreachableException
- if any.DAOException
- if any.
-
checkContentFileAccessPermission
public static AccessPermission checkContentFileAccessPermission(String identifier, javax.servlet.http.HttpServletRequest request) throws IndexUnreachableException, DAOException Checks if the record with the given identifier should allow access to the given request- Parameters:
identifier
- The PI of the work to checkrequest
- The HttpRequest which may provide aHttpSession
to store the access map- Returns:
AccessPermission
- Throws:
IndexUnreachableException
- if any.DAOException
- if any.
-
checkAccessPermissionByImageUrn
public static AccessPermission checkAccessPermissionByImageUrn(String imageUrn, String privilegeName, javax.servlet.http.HttpServletRequest request) throws IndexUnreachableException, DAOException Checks whether the client may access an image (by image URN).- Parameters:
imageUrn
- Image URN.request
- Calling HttpServiceRequest.privilegeName
- aString
object.- Returns:
AccessPermission
- Throws:
IndexUnreachableException
- if any.DAOException
- if any.
-
checkAccessPermission
public static AccessPermission checkAccessPermission(Set<String> requiredAccessConditions, String privilegeName, String query, javax.servlet.http.HttpServletRequest request) throws IndexUnreachableException, PresentationException, DAOException checkAccessPermission.
- Parameters:
requiredAccessConditions
- aSet
object.privilegeName
- aString
object.request
- aHttpServletRequest
object.query
- aString
object.- Returns:
AccessPermission
- Throws:
IndexUnreachableException
- if any.PresentationException
- if any.DAOException
- if any.
-
checkAccessPermissionForImage
public static AccessPermission checkAccessPermissionForImage(javax.servlet.http.HttpServletRequest request, String pi, String contentFileName) throws IndexUnreachableException, DAOException Checks access permission for the given image and puts the permission status into the corresponding session map.- Parameters:
request
- aHttpServletRequest
object.pi
- aString
object.contentFileName
- aString
object.- Returns:
AccessPermission
- Throws:
IndexUnreachableException
- if any.DAOException
- if any.
-
checkAccessPermissionForThumbnail
public static AccessPermission checkAccessPermissionForThumbnail(javax.servlet.http.HttpServletRequest request, String pi, String contentFileName) throws IndexUnreachableException, DAOException Checks access permission for the given thumbnail and puts the permission status into the corresponding session map.- Parameters:
request
- aHttpServletRequest
object.pi
- aString
object.contentFileName
- aString
object.- Returns:
AccessPermission
- Throws:
IndexUnreachableException
- if any.DAOException
- if any.
-
checkAccessPermissionForPagePdf
public static AccessPermission checkAccessPermissionForPagePdf(javax.servlet.http.HttpServletRequest request, PhysicalElement page) throws IndexUnreachableException, DAOException Checks access permission for the given image and puts the permission status into the corresponding session map.- Parameters:
request
- aHttpServletRequest
object.page
- aPhysicalElement
object.- Returns:
AccessPermission
- Throws:
IndexUnreachableException
- if any.DAOException
- if any.
-
checkAccessPermissionByIdentifierAndFilePathWithSessionMap
public static AccessPermission checkAccessPermissionByIdentifierAndFilePathWithSessionMap(javax.servlet.http.HttpServletRequest request, String filePath, String privilegeType) throws IndexUnreachableException, DAOException checkAccessPermissionByIdentifierAndFilePathWithSessionMap.
- Parameters:
request
- aHttpServletRequest
object.filePath
- FILENAME_ALTO or FILENAME_FULLTEXT valueprivilegeType
- aString
object.- Returns:
AccessPermission
- Throws:
IndexUnreachableException
- if any.DAOException
- if any.
-
checkAccessPermissionByIdentifierAndFileNameWithSessionMap
public static AccessPermission checkAccessPermissionByIdentifierAndFileNameWithSessionMap(javax.servlet.http.HttpServletRequest request, String pi, String contentFileName, String privilegeType) throws IndexUnreachableException, DAOException Checks access permission of the given privilege type for the given image and puts the permission status into the corresponding session map.- Parameters:
request
- aHttpServletRequest
object.pi
- aString
object.contentFileName
- aString
object.privilegeType
- aString
object.- Returns:
AccessPermission
- Throws:
IndexUnreachableException
- if any.DAOException
- if any.
-
checkAccessPermission
public static AccessPermission checkAccessPermission(List<LicenseType> allLicenseTypes, Set<String> requiredAccessConditions, String privilegeName, User user, String remoteAddress, Optional<ClientApplication> client, String query) throws IndexUnreachableException, PresentationException, DAOException Base method for checking access permissions of various types.
- Parameters:
allLicenseTypes
- aList
object.requiredAccessConditions
- Set of access condition names to satisfy (one suffices).privilegeName
- The particular privilege to check.user
- Logged in user.remoteAddress
- aString
object.client
-query
- Solr query describing the resource in question.- Returns:
- Map<String, AccessPermission>
- Throws:
IndexUnreachableException
- if any.PresentationException
- if any.DAOException
- if any.
-
isFreeOpenAccess
public static boolean isFreeOpenAccess(Set<String> requiredAccessConditions, Collection<LicenseType> allLicenseTypes) throws DAOException Check whether the requiredAccessConditions consist only of theOPENACCESS
condition and OPENACCESS is not contained in allLicenseTypes. In this and only this case can we savely assume that everything is permitted. If OPENACCESS is in the database then it likely contains some access restrictions which need to be checked- Parameters:
requiredAccessConditions
- aSet
object.allLicenseTypes
- all license types relevant for access. If null, the DAO is checked if it contains the OPENACCESS condition- Returns:
- true if we can savely assume that we have entirely open access
- Throws:
DAOException
- if any.
-
getPdfDownloadQuotaForRecord
public static int getPdfDownloadQuotaForRecord(String pi) throws PresentationException, IndexUnreachableException, DAOException, RecordNotFoundException - Parameters:
pi
-- Returns:
- Number of allowed downloads for given pi; 100 of no value set
- Throws:
PresentationException
IndexUnreachableException
DAOException
RecordNotFoundException
-
isConcurrentViewsLimitEnabledForAnyAccessCondition
public static boolean isConcurrentViewsLimitEnabledForAnyAccessCondition(List<String> accessConditions) throws DAOException - Parameters:
accessConditions
-- Returns:
- true if any license type for the given list of access conditions has concurrent views limit enabled; false otherwise
- Throws:
DAOException
-
isPrivilegeGrantedForDoc
public static boolean isPrivilegeGrantedForDoc(org.apache.solr.common.SolrDocument doc, String privilegeName, javax.servlet.http.HttpServletRequest request) - Parameters:
doc
- The document containing access condition metadataprivilegeName
- The privilege to checkrequest
- The request trying to access the resource- Returns:
- true if granted; false otherwise
-
getApplyingLicenses
public static List<License> getApplyingLicenses(Optional<User> user, String ipAddress, LicenseType type, IDAO dao) throws DAOException List all licenses ("rights") that the given user and ipAddress is entitled to, either because they are directly given to the user, a group the user belongs to or to the given ipAddress, whether or not the given user exists- Parameters:
user
-ipAddress
-type
-dao
-- Returns:
- List
- Throws:
DAOException
-
isHasDownloadTicket
- Parameters:
pi
- Record identifiersession
-HttpSession
that contains permission attributes- Returns:
- true if given
session
contains permission forpi
; false otherwise
-
addDownloadTicketToSession
-
getSessionPermission
public static Object getSessionPermission(String attributeName, javax.servlet.http.HttpServletRequest request) - Parameters:
attributeName
-request
-- Returns:
- Object found in session; null otherwise
-
addSessionPermission
public static boolean addSessionPermission(String attributeName, Object attributeValue, javax.servlet.http.HttpServletRequest request) - Parameters:
attributeName
-attributeValue
-request
-- Returns:
- true if successful; false otherwise
-
clearSessionPermissions
public static int clearSessionPermissions(javax.servlet.http.HttpSession session) Removes privileges saved in the user session.- Parameters:
session
-- Returns:
- Number of removed session attributes
-