001/* 002 * Copyright 2026 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.ai; 017 018import org.apache.cocoon.environment.Request; 019import org.apache.commons.lang3.Strings; 020 021import org.ametys.plugins.site.token.DefaultRequestToken; 022 023/** 024 * Manage token for search API 025 */ 026public class SearchAPIToken extends DefaultRequestToken 027{ 028 029 private static final String __PATH_PREFIX = "_ai/search"; 030 031 @Override 032 public String getToken(Request request) 033 { 034 String pathInSite = (String) request.getAttribute("path"); 035 if (Strings.CS.startsWith(pathInSite, __PATH_PREFIX)) 036 { 037 return super.getToken(request); 038 } 039 return null; 040 } 041 042 @Override 043 public String getTokenContext(Request request) 044 { 045 String pathInSite = (String) request.getAttribute("path"); 046 if (Strings.CS.startsWith(pathInSite, __PATH_PREFIX)) 047 { 048 return "api/search"; 049 } 050 return null; 051 } 052 053}