Java Code Examples for org.apache.solr.request.SolrRequestInfo#getUserPrincipal()
The following examples show how to use
org.apache.solr.request.SolrRequestInfo#getUserPrincipal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpParamDelegationTokenPlugin.java From lucene-solr with Apache License 2.0 | 6 votes |
private Optional<String> getPrincipal() { SolrRequestInfo reqInfo = SolrRequestInfo.getRequestInfo(); String usr; if (reqInfo != null) { Principal principal = reqInfo.getUserPrincipal(); if (principal == null) { //this had a request but not authenticated //so we don't not need to set a principal return Optional.empty(); } else { usr = principal.getName(); } } else { if (!isSolrThread()) { //if this is not running inside a Solr threadpool (as in testcases) // then no need to add any header return Optional.empty(); } //this request seems to be originated from Solr itself usr = "$"; //special name to denote the user is the node itself } return Optional.of(usr); }
Example 2
Source File: PKIAuthenticationPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
@SuppressForbidden(reason = "Needs currentTimeMillis to set current time in header") private Optional<String> generateToken() { SolrRequestInfo reqInfo = getRequestInfo(); String usr; if (reqInfo != null) { Principal principal = reqInfo.getUserPrincipal(); if (principal == null) { log.debug("generateToken: principal is null"); //this had a request but not authenticated //so we don't not need to set a principal return Optional.empty(); } else { usr = principal.getName(); } } else { if (!isSolrThread()) { //if this is not running inside a Solr threadpool (as in testcases) // then no need to add any header log.debug("generateToken: not a solr (server) thread"); return Optional.empty(); } //this request seems to be originated from Solr itself usr = "$"; //special name to denote the user is the node itself } String s = usr + " " + System.currentTimeMillis(); byte[] payload = s.getBytes(UTF_8); byte[] payloadCipher = publicKeyHandler.keyPair.encrypt(ByteBuffer.wrap(payload)); String base64Cipher = Base64.byteArrayToBase64(payloadCipher); log.trace("generateToken: usr={} token={}", usr, base64Cipher); return Optional.of(base64Cipher); }
Example 3
Source File: KerberosPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected boolean interceptInternodeRequest(HttpRequest httpRequest, HttpContext httpContext) { SolrRequestInfo info = SolrRequestInfo.getRequestInfo(); if (info != null && (info.getAction() == SolrDispatchFilter.Action.FORWARD || info.getAction() == SolrDispatchFilter.Action.REMOTEQUERY)) { if (info.getUserPrincipal() != null) { if (log.isInfoEnabled()) { log.info("Setting original user principal: {}", info.getUserPrincipal().getName()); } httpRequest.setHeader(ORIGINAL_USER_PRINCIPAL_HEADER, info.getUserPrincipal().getName()); return true; } } return false; }
Example 4
Source File: KerberosPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected boolean interceptInternodeRequest(Request request) { SolrRequestInfo info = SolrRequestInfo.getRequestInfo(); if (info != null && (info.getAction() == SolrDispatchFilter.Action.FORWARD || info.getAction() == SolrDispatchFilter.Action.REMOTEQUERY)) { if (info.getUserPrincipal() != null) { if (log.isInfoEnabled()) { log.info("Setting original user principal: {}", info.getUserPrincipal().getName()); } request.header(ORIGINAL_USER_PRINCIPAL_HEADER, info.getUserPrincipal().getName()); return true; } } return false; }