Fix compile error
This commit is contained in:
parent
8049215d07
commit
2054b409ff
|
@ -431,7 +431,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
myLastRequest = theInvocation.asHttpRequest(getServerBase(), theParams, getEncoding(), myPrettyPrint);
|
||||
}
|
||||
|
||||
Z resp = invokexClient(myContext, theHandler, theInvocation, myParamEncoding, myPrettyPrint, myQueryLogRequestAndResponse || myLogRequestAndResponse, mySummaryMode, mySubsetElements, myCacheControlDirective, myCustomAcceptHeaderValue, myCustomHeaderValues);
|
||||
Z resp = invokeClient(myContext, theHandler, theInvocation, myParamEncoding, myPrettyPrint, myQueryLogRequestAndResponse || myLogRequestAndResponse, mySummaryMode, mySubsetElements, myCacheControlDirective, myCustomAcceptHeaderValue, myCustomHeaderValues);
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,11 @@ package ca.uhn.hapi.fhir.docs;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import ca.uhn.fhir.interceptor.api.Hook;
|
||||
import ca.uhn.fhir.interceptor.api.Interceptor;
|
||||
import ca.uhn.fhir.interceptor.api.Pointcut;
|
||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -30,56 +32,54 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
public class SecurityInterceptors {
|
||||
|
||||
// START SNIPPET: basicAuthInterceptor
|
||||
public class BasicSecurityInterceptor extends InterceptorAdapter
|
||||
{
|
||||
public void basicAuthInterceptorRealm() {
|
||||
//START SNIPPET: basicAuthInterceptorRealm
|
||||
AuthenticationException ex = new AuthenticationException();
|
||||
ex.addAuthenticateHeaderForRealm("myRealm");
|
||||
throw ex;
|
||||
//END SNIPPET: basicAuthInterceptorRealm
|
||||
}
|
||||
|
||||
/**
|
||||
* This interceptor implements HTTP Basic Auth, which specifies that
|
||||
* a username and password are provided in a header called Authorization.
|
||||
*/
|
||||
@Override
|
||||
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
|
||||
String authHeader = theRequest.getHeader("Authorization");
|
||||
|
||||
// The format of the header must be:
|
||||
// Authorization: Basic [base64 of username:password]
|
||||
if (authHeader == null || authHeader.startsWith("Basic ") == false) {
|
||||
throw new AuthenticationException("Missing or invalid Authorization header");
|
||||
}
|
||||
|
||||
String base64 = authHeader.substring("Basic ".length());
|
||||
String base64decoded = new String(Base64.decodeBase64(base64));
|
||||
String[] parts = base64decoded.split("\\:");
|
||||
|
||||
String username = parts[0];
|
||||
String password = parts[1];
|
||||
|
||||
/*
|
||||
* Here we test for a hardcoded username & password. This is
|
||||
* not typically how you would implement this in a production
|
||||
* system of course..
|
||||
*/
|
||||
if (!username.equals("someuser") || !password.equals("thepassword")) {
|
||||
throw new AuthenticationException("Invalid username or password");
|
||||
}
|
||||
|
||||
// Return true to allow the request to proceed
|
||||
return true;
|
||||
}
|
||||
// START SNIPPET: basicAuthInterceptor
|
||||
@Interceptor
|
||||
public class BasicSecurityInterceptor {
|
||||
|
||||
|
||||
}
|
||||
//END SNIPPET: basicAuthInterceptor
|
||||
|
||||
/**
|
||||
* This interceptor implements HTTP Basic Auth, which specifies that
|
||||
* a username and password are provided in a header called Authorization.
|
||||
*/
|
||||
@Hook(Pointcut.SERVER_INCOMING_REQUEST_POST_PROCESSED)
|
||||
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
|
||||
String authHeader = theRequest.getHeader("Authorization");
|
||||
|
||||
// The format of the header must be:
|
||||
// Authorization: Basic [base64 of username:password]
|
||||
if (authHeader == null || authHeader.startsWith("Basic ") == false) {
|
||||
throw new AuthenticationException("Missing or invalid Authorization header");
|
||||
}
|
||||
|
||||
String base64 = authHeader.substring("Basic ".length());
|
||||
String base64decoded = new String(Base64.decodeBase64(base64));
|
||||
String[] parts = base64decoded.split(":");
|
||||
|
||||
String username = parts[0];
|
||||
String password = parts[1];
|
||||
|
||||
/*
|
||||
* Here we test for a hardcoded username & password. This is
|
||||
* not typically how you would implement this in a production
|
||||
* system of course..
|
||||
*/
|
||||
if (!username.equals("someuser") || !password.equals("thepassword")) {
|
||||
throw new AuthenticationException("Invalid username or password");
|
||||
}
|
||||
|
||||
// Return true to allow the request to proceed
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void basicAuthInterceptorRealm() {
|
||||
//START SNIPPET: basicAuthInterceptorRealm
|
||||
AuthenticationException ex = new AuthenticationException();
|
||||
ex.addAuthenticateHeaderForRealm("myRealm");
|
||||
throw ex;
|
||||
//END SNIPPET: basicAuthInterceptorRealm
|
||||
}
|
||||
}
|
||||
//END SNIPPET: basicAuthInterceptor
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue