use of org.lastaflute.web.servlet.request.RequestManager in project lastaflute by lastaflute.
the class TypicalFaicliApiFailureHook method doRecoverMessages.
protected Map<String, List<String>> doRecoverMessages(ApiFailureResource resource, RuntimeException cause, String messageKey) {
final RequestManager requestManager = resource.getRequestManager();
final String message = requestManager.getMessageManager().getMessage(requestManager.getUserLocale(), messageKey);
final Map<String, List<String>> map = DfCollectionUtil.newLinkedHashMap();
map.put(UserMessages.GLOBAL, DfCollectionUtil.newArrayList(message));
return Collections.unmodifiableMap(map);
}
use of org.lastaflute.web.servlet.request.RequestManager in project lastaflute by lastaflute.
the class TypicalFaihyApiFailureHook method doRecoverMessages.
protected Map<String, List<String>> doRecoverMessages(ApiFailureResource resource, RuntimeException cause, String messageKey) {
final RequestManager requestManager = resource.getRequestManager();
final String message = requestManager.getMessageManager().getMessage(requestManager.getUserLocale(), messageKey);
final Map<String, List<String>> map = DfCollectionUtil.newLinkedHashMap();
map.put(UserMessages.GLOBAL, DfCollectionUtil.newArrayList(message));
return Collections.unmodifiableMap(map);
}
use of org.lastaflute.web.servlet.request.RequestManager in project fess by codelibs.
the class RoleQueryHelper method build.
public Set<String> build(final SearchRequestType searchRequestType) {
final Set<String> roleSet = new HashSet<>();
final HttpServletRequest request = LaRequestUtil.getOptionalRequest().orElse(null);
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final boolean isApiRequest = !SearchRequestType.SEARCH.equals(searchRequestType) && !SearchRequestType.ADMIN_SEARCH.equals(searchRequestType);
if (request != null) {
@SuppressWarnings("unchecked") final Set<String> list = (Set<String>) request.getAttribute(USER_ROLES);
if (list != null) {
return list;
}
// request parameter
if (StringUtil.isNotBlank(parameterKey)) {
processParameter(request, roleSet);
}
// request header
if (StringUtil.isNotBlank(headerKey)) {
processHeader(request, roleSet);
}
// cookie
if (StringUtil.isNotBlank(cookieKey)) {
processCookie(request, roleSet);
}
// cookie mapping
if (cookieNameMap != null) {
buildByCookieNameMapping(request, roleSet);
}
final boolean hasAccessToken = processAccessToken(request, roleSet, isApiRequest);
final RequestManager requestManager = ComponentUtil.getRequestManager();
try {
requestManager.findUserBean(FessUserBean.class).ifPresent(fessUserBean -> stream(fessUserBean.getPermissions()).of(stream -> stream.forEach(roleSet::add))).orElse(() -> {
if (isApiRequest && ComponentUtil.getFessConfig().getApiAccessTokenRequiredAsBoolean()) {
throw new InvalidAccessTokenException("invalid_token", "Access token is requried.");
}
if (!hasAccessToken || roleSet.isEmpty()) {
roleSet.addAll(fessConfig.getSearchGuestPermissionList());
}
});
} catch (final RuntimeException e) {
try {
requestManager.findLoginManager(FessUserBean.class).ifPresent(LoginManager::logout);
} catch (final Exception e1) {
// ignore
}
throw e;
}
}
if (defaultRoleList != null) {
roleSet.addAll(defaultRoleList);
}
if (logger.isDebugEnabled()) {
logger.debug("roleSet: {}", roleSet);
}
if (request != null) {
request.setAttribute(USER_ROLES, roleSet);
}
return roleSet;
}
Aggregations