Search in sources :

Example 1 with RequestManager

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);
}
Also used : RequestManager(org.lastaflute.web.servlet.request.RequestManager) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with RequestManager

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);
}
Also used : RequestManager(org.lastaflute.web.servlet.request.RequestManager) List(java.util.List)

Example 3 with RequestManager

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;
}
Also used : StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) AccessTokenService(org.codelibs.fess.app.service.AccessTokenService) StringUtil(org.codelibs.core.lang.StringUtil) Set(java.util.Set) HashMap(java.util.HashMap) InvalidAccessTokenException(org.codelibs.fess.exception.InvalidAccessTokenException) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FessUserBean(org.codelibs.fess.mylasta.action.FessUserBean) List(java.util.List) HttpServletRequest(javax.servlet.http.HttpServletRequest) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) RequestManager(org.lastaflute.web.servlet.request.RequestManager) ComponentUtil(org.codelibs.fess.util.ComponentUtil) CachedCipher(org.codelibs.core.crypto.CachedCipher) LoginManager(org.lastaflute.web.login.LoginManager) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct) Cookie(javax.servlet.http.Cookie) LogManager(org.apache.logging.log4j.LogManager) Set(java.util.Set) HashSet(java.util.HashSet) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) InvalidAccessTokenException(org.codelibs.fess.exception.InvalidAccessTokenException) HttpServletRequest(javax.servlet.http.HttpServletRequest) InvalidAccessTokenException(org.codelibs.fess.exception.InvalidAccessTokenException) RequestManager(org.lastaflute.web.servlet.request.RequestManager) HashSet(java.util.HashSet)

Aggregations

List (java.util.List)3 RequestManager (org.lastaflute.web.servlet.request.RequestManager)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 PostConstruct (javax.annotation.PostConstruct)1 Cookie (javax.servlet.http.Cookie)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 CachedCipher (org.codelibs.core.crypto.CachedCipher)1 StringUtil (org.codelibs.core.lang.StringUtil)1 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)1 AccessTokenService (org.codelibs.fess.app.service.AccessTokenService)1 SearchRequestType (org.codelibs.fess.entity.SearchRequestParams.SearchRequestType)1 InvalidAccessTokenException (org.codelibs.fess.exception.InvalidAccessTokenException)1 FessUserBean (org.codelibs.fess.mylasta.action.FessUserBean)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1