Changeset 7265
- Timestamp:
- 01/05/22 22:26:06 (2 years ago)
- Location:
- SRUServer/trunk/src/main/java/eu/clarin/sru/server
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRURequest.java
r6934 r7265 28 28 */ 29 29 public interface SRURequest { 30 /** 31 * Get the authentication information that was extracted from the the 32 * request. 33 * 34 * @return the request authentication or <code>null</code> 35 */ 36 public SRUAuthenticationInfo getAuthentication(); 37 38 39 /** 40 * Get the subject of the request. 41 * 42 * @return the subject of the request or <code>null</code> 43 */ 44 public String getAuthenticationSubject(); 45 30 46 31 47 /** -
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRURequestImpl.java
r6934 r7265 80 80 private final SRUServerConfig config; 81 81 private final SRUQueryParserRegistry queryParsers; 82 private final SRUAuthenticationInfoProvider authenticationInfoProvider; 82 83 private final HttpServletRequest request; 84 private SRUAuthenticationInfo authenticationInfo; 83 85 private List<SRUDiagnostic> diagnostics; 84 86 private SRUOperation operation; … … 249 251 SRURequestImpl(SRUServerConfig config, 250 252 SRUQueryParserRegistry queryParsers, 253 SRUAuthenticationInfoProvider authenticationInfoProvider, 251 254 HttpServletRequest request) { 252 this.config 255 this.config = config; 253 256 this.queryParsers = queryParsers; 254 this.request = request; 257 this.authenticationInfoProvider = authenticationInfoProvider; 258 this.request = request; 255 259 } 256 260 … … 676 680 } 677 681 678 679 682 /* 680 683 * check if any parameters where not consumed and … … 694 697 695 698 /* 699 * extract authentication information from, if an authentication provider is set 700 */ 701 if (authenticationInfoProvider != null) { 702 try { 703 authenticationInfo = authenticationInfoProvider.getAuthenticationInfo(request); 704 } catch (SRUException e) { 705 addDiagnostic(e.getDiagnostic()); 706 } 707 } 708 709 /* 696 710 * diagnostics == null -> consider as success 697 * FIXME: this should ne done nicer!711 * FIXME: this should be done nicer! 698 712 */ 699 713 return (diagnostics == null); … … 773 787 774 788 @Override 789 public SRUAuthenticationInfo getAuthentication() { 790 return authenticationInfo; 791 } 792 793 794 @Override 795 public String getAuthenticationSubject() { 796 if (authenticationInfo != null) { 797 return authenticationInfo.getSubject(); 798 } else { 799 return null; 800 } 801 } 802 803 804 @Override 775 805 public SRUOperation getOperation() { 776 806 return operation; … … 1014 1044 @Override 1015 1045 public void addDiagnostic(String uri, String details, String message) { 1016 final SRUDiagnostic diagnostic = 1017 new SRUDiagnostic(uri, details, message); 1046 final SRUDiagnostic diagnostic = new SRUDiagnostic(uri, details, 1047 message); 1048 addDiagnostic(diagnostic); 1049 } 1050 1051 1052 private void addDiagnostic(SRUDiagnostic diagnostic) { 1018 1053 if (diagnostics == null) { 1019 1054 diagnostics = new ArrayList<SRUDiagnostic>(); … … 1021 1056 diagnostics.add(diagnostic); 1022 1057 } 1023 1024 1058 1059 1025 1060 private List<String> getParameterNames() { 1026 1061 List<String> list = new ArrayList<String>(); -
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUServer.java
r6934 r7265 59 59 private final SRUServerConfig config; 60 60 private final SRUQueryParserRegistry queryParsers; 61 private final SRUAuthenticationInfoProvider authenticationInfoProvider; 61 62 private final SRUSearchEngine searchEngine; 62 63 private final XMLOutputFactory writerFactory; … … 70 71 * @param queryParsers 71 72 * a {@link SRUQueryParserRegistry} object 73 * @param authenticationInfoProvider 74 * a {@link SRUAuthenticationInfoProvider} or <code>null</code> 72 75 * @param searchEngine 73 76 * an object implementing the {@link SRUSearchEngine} interface … … 75 78 * if config, queryParserRegistry or searchEngine is 76 79 * <code>null</code> 77 * @throws SRU Exception78 * if an error occurred 80 * @throws SRUConfigException 81 * if an error occurred with configuration or initialization of the server 79 82 */ 80 83 public SRUServer(SRUServerConfig config, 81 84 SRUQueryParserRegistry queryParsers, 82 SRUSearchEngine searchEngine) throws SRUException { 85 SRUAuthenticationInfoProvider authenticationInfoProvider, 86 SRUSearchEngine searchEngine) throws SRUConfigException { 83 87 if (config == null) { 84 88 throw new NullPointerException("config == null"); … … 95 99 } 96 100 this.searchEngine = searchEngine; 101 102 this.authenticationInfoProvider = authenticationInfoProvider; 97 103 98 104 this.writerFactory = XMLOutputFactory.newInstance(); … … 111 117 HttpServletResponse response) { 112 118 final SRURequestImpl req = 113 new SRURequestImpl(config, queryParsers, request);119 new SRURequestImpl(config, queryParsers, authenticationInfoProvider, request); 114 120 try { 115 121 // set response properties -
SRUServer/trunk/src/main/java/eu/clarin/sru/server/utils/SRUServerServlet.java
r6934 r7265 22 22 import java.net.MalformedURLException; 23 23 import java.net.URL; 24 import java.util.Collections; 24 25 import java.util.Enumeration; 25 26 import java.util.HashMap; … … 36 37 import org.slf4j.LoggerFactory; 37 38 39 import eu.clarin.sru.server.SRUAuthenticationInfoProvider; 38 40 import eu.clarin.sru.server.SRUConfigException; 39 import eu.clarin.sru.server.SRUException;40 41 import eu.clarin.sru.server.SRUQueryParserRegistry; 41 42 import eu.clarin.sru.server.SRUServer; … … 145 146 * get init-parameters from ServletConfig ... 146 147 */ 147 final HashMap<String, String> params = new HashMap<String, String>();148 Map<String, String> params = new HashMap<>(); 148 149 for (Enumeration<?> i = cfg.getInitParameterNames(); 149 150 i.hasMoreElements();) { … … 204 205 contextPath); 205 206 } 206 207 // parse configuration 208 SRUServerConfig sruServerConfig; 209 try { 210 sruServerConfig = 211 SRUServerConfig.parse(params, sruServerConfigFile); 212 } catch (SRUConfigException e) { 213 throw new ServletException("sru server configuration is invalid", e); 214 } 207 // seal parameters against tampering ... 208 params = Collections.unmodifiableMap(params); 215 209 216 210 /* 217 * create an instance of the search engine...211 * now go ahead and setup everything ... 218 212 */ 219 213 try { 220 logger.debug("creating new search engine from class {}", 221 sruServerSearchEngineClass); 222 @SuppressWarnings("unchecked") 223 Class<SRUSearchEngineBase> clazz = (Class<SRUSearchEngineBase>) 224 Class.forName(sruServerSearchEngineClass); 225 Constructor<SRUSearchEngineBase> constructor = 226 clazz.getConstructor(); 227 searchEngine = constructor.newInstance(); 228 } catch (ClassNotFoundException e) { 229 throw new ServletException("error initializing sru server", e); 230 } catch (ClassCastException e) { 231 throw new ServletException("error initializing sru server", e); 232 } catch (NoSuchMethodException e) { 233 throw new ServletException("error initializing sru server", e); 234 } catch (SecurityException e) { 235 throw new ServletException("error initializing sru server", e); 236 } catch (InstantiationException e) { 237 throw new ServletException("error initializing sru server", e); 238 } catch (IllegalAccessException e) { 239 throw new ServletException("error initializing sru server", e); 240 } catch (IllegalArgumentException e) { 241 throw new ServletException("error initializing sru server", e); 242 } catch (InvocationTargetException e) { 243 throw new ServletException("error initializing sru server", e); 244 } 245 246 /* 247 * finally initialize the SRU server ... 248 */ 249 try { 214 /* 215 * parse SRU server configuration 216 */ 217 SRUServerConfig sruServerConfig = 218 SRUServerConfig.parse(params, sruServerConfigFile); 219 220 /* 221 * create an instance of the search engine ... 222 */ 223 try { 224 logger.debug("creating new search engine from class {}", 225 sruServerSearchEngineClass); 226 @SuppressWarnings("unchecked") 227 Class<SRUSearchEngineBase> clazz = (Class<SRUSearchEngineBase>) 228 Class.forName(sruServerSearchEngineClass); 229 Constructor<SRUSearchEngineBase> constructor = 230 clazz.getConstructor(); 231 searchEngine = constructor.newInstance(); 232 } catch (ClassNotFoundException | 233 NoSuchMethodException | 234 SecurityException | 235 InstantiationException | 236 IllegalAccessException | 237 IllegalArgumentException | 238 InvocationTargetException e) { 239 throw new SRUConfigException("error creating search engine", e); 240 } 241 242 /* 243 * initialize search engine ... 244 */ 250 245 final SRUQueryParserRegistry.Builder builder = 251 246 new SRUQueryParserRegistry.Builder(); 252 247 searchEngine.init(ctx, sruServerConfig, builder, params); 253 final SRUQueryParserRegistry parsers = builder.build(); 254 sruServer = new SRUServer(sruServerConfig, parsers, searchEngine); 248 249 /* 250 * create authentication provider 251 */ 252 SRUAuthenticationInfoProvider authenticationProvider = null; 253 if (SRUAuthenticationInfoProviderFactory.class.isInstance(searchEngine)) { 254 logger.debug("creating new authentication info provider"); 255 256 authenticationProvider = ((SRUAuthenticationInfoProviderFactory) searchEngine) 257 .createAuthenticationInfoProvider(ctx, params); 258 } 259 260 /* 261 * finally create the sru server ... 262 */ 263 sruServer = new SRUServer(sruServerConfig, 264 builder.build(), 265 authenticationProvider, 266 searchEngine); 255 267 } catch (SRUConfigException e) { 256 throw new ServletException("error initializing sru server", e); 257 } catch (SRUException e) { 258 throw new ServletException("error initializing sru server", e); 268 String msg = (e.getMessage() != null) 269 ? "error configuring or inializing the server: " + e.getMessage() 270 : "error configuring or inializing the server"; 271 throw new ServletException(msg, e); 259 272 } 260 273 }
Note: See TracChangeset
for help on using the changeset viewer.