/** * Retrieves the handles of the user. * * @param ctx The evaluation context, which will be used as key for the cache. * @param userAccountId The id of the user account to get the handles for. * @param attributeIdValue The value of the attribute id that is currently resolved. * @return Returns the eSciDoc user handle of the subject (current user). * @throws WebserverSystemException Thrown in case of an internal error. * @throws UserAccountNotFoundException Thrown if no user account with provided id is found. */ private Set retrieveUserHandle( final EvaluationCtx ctx, final String userAccountId, final String attributeIdValue) throws WebserverSystemException, UserAccountNotFoundException { Set<AttributeValue> result = (Set<AttributeValue>) getFromCache(XmlUtility.NAME_HANDLE, null, null, userAccountId, ctx); if (result == null) { final List userHandles; try { userHandles = getUserAccountDao().retrieveUserLoginDataByUserId(userAccountId); if (userHandles == null || userHandles.isEmpty()) { assertUserAccount( userAccountId, getUserAccountDao().retrieveUserAccountById(userAccountId)); } } catch (final UserAccountNotFoundException e) { throw e; } catch (final Exception e) { final String errorMsg = StringUtility.format("Retrieving of attribute failed", attributeIdValue); throw new WebserverSystemException(errorMsg, e); } result = new HashSet<AttributeValue>(); if (userHandles != null && !userHandles.isEmpty()) { for (final Object userHandle : userHandles) { final UserLoginData userLoginData = (UserLoginData) userHandle; result.add(new StringAttribute(userLoginData.getHandle())); } } putInCache(XmlUtility.NAME_HANDLE, null, null, userAccountId, ctx, result); } return result; }
/** * Removes UserDetails of user with given id from UserDetails-Cache. * * @param userId The user Id. * @throws SqlDatabaseSystemException Thrown in case of an internal database access error. */ private void clearUserDetailsCache(final String userId) throws SqlDatabaseSystemException { final UserAccount userAccount = retrieveUserAccountById(userId); if (userAccount != null && userAccount.getUserLoginDatas() != null && !userAccount.getUserLoginDatas().isEmpty()) { for (final UserLoginData userLoginData : userAccount.getUserLoginDatas()) { securityHelper.clearUserDetails(userLoginData.getHandle()); } } }
/** * Checks if the provided {@link UserLoginData} object is expired. * * @param data The {@link UserLoginData} object to check. * @return Returns {@code true} if the provided object is expired. */ private static boolean isExpired(final UserLoginData data) { boolean result = false; if (data.getExpiryts() - System.currentTimeMillis() <= 0L) { result = true; } return result; }
/** * Checks if the provided {@link UserLoginData} object for is expired. If this is the case, the * object is deleted from the storage. And object is removed from Cache. * * @param data The {@link UserLoginData} object to check. * @return Returns the provided {@link UserLoginData} object or {@code null} if it is expired. * @throws SqlDatabaseSystemException Thrown in case of an internal database access error. */ private UserLoginData checkUserLoginData(final UserLoginData data) throws SqlDatabaseSystemException { UserLoginData result = data; if (result != null && isExpired(result)) { delete(result); securityHelper.clearUserDetails(data.getHandle()); result = null; } return result; }
/** * See Interface for functional description. * * @see UserAccountDaoInterface #delete(de.escidoc.core.aa.business.persistence.UserLoginData) */ @Override public void delete(final UserLoginData data) throws SqlDatabaseSystemException { // remove UserData from Cache securityHelper.clearUserDetails(data.getHandle()); super.delete(data); }