use of org.codelibs.fess.mylasta.action.FessUserBean 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;
}
use of org.codelibs.fess.mylasta.action.FessUserBean in project fess by codelibs.
the class LdapUser method getPermissions.
@Override
public String[] getPermissions() {
if (permissions == null) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String baseDn = fessConfig.getLdapBaseDn();
final String accountFilter = fessConfig.getLdapAccountFilter();
final String groupFilter = fessConfig.getLdapGroupFilter();
if (StringUtil.isNotBlank(baseDn) && StringUtil.isNotBlank(accountFilter)) {
final LdapManager ldapManager = ComponentUtil.getLdapManager();
permissions = distinct(ArrayUtils.addAll(ldapManager.getRoles(this, baseDn, accountFilter, groupFilter, roles -> {
permissions = distinct(roles);
ComponentUtil.getActivityHelper().permissionChanged(OptionalThing.of(new FessUserBean(this)));
}), fessConfig.getRoleSearchUserPrefix() + ldapManager.normalizePermissionName(getName())));
} else {
permissions = StringUtil.EMPTY_STRINGS;
}
}
return permissions;
}
Aggregations