当前位置: 首页>>代码示例>>Java>>正文


Java AuthenticationException类代码示例

本文整理汇总了Java中ca.uhn.fhir.rest.server.exceptions.AuthenticationException的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationException类的具体用法?Java AuthenticationException怎么用?Java AuthenticationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthenticationException类属于ca.uhn.fhir.rest.server.exceptions包,在下文中一共展示了AuthenticationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAuthorize

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Test
public void testAuthorize() throws Exception {
	
	OperationOutcome operationOutcome = new OperationOutcome();
	operationOutcome.addIssue().setCode(IssueType.BUSINESSRULE);
	
	ourException = new AuthenticationException().addAuthenticateHeaderForRealm("REALM");
	
	HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient");
	CloseableHttpResponse status = ourClient.execute(httpGet);
	try {
		String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
		ourLog.info(status.getStatusLine().toString());
		ourLog.info(responseContent);
		
		assertEquals(401, status.getStatusLine().getStatusCode());
		assertEquals("Basic realm=\"REALM\"", status.getFirstHeader("WWW-Authenticate").getValue());
	} finally {
		IOUtils.closeQuietly(status.getEntity().getContent());
	}

}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:23,代码来源:ServerExceptionDstu3Test.java

示例2: testAuthorizationFailureInPreProcessInterceptor

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Test
public void testAuthorizationFailureInPreProcessInterceptor() throws Exception {
	IServerInterceptor interceptor = new InterceptorAdapter() {
		@Override
		public boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse) {
			throw new AuthenticationException();
		}
	};

	servlet.registerInterceptor(interceptor);
	try {
		HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?throwInternalError=aaa");
		HttpResponse status = ourClient.execute(httpGet);
		String responseContent = IOUtils.toString(status.getEntity().getContent());
		IOUtils.closeQuietly(status.getEntity().getContent());
		ourLog.info(responseContent);
		assertEquals(AuthenticationException.STATUS_CODE, status.getStatusLine().getStatusCode());
		assertThat(responseContent, StringContains.containsString("Client unauthorized"));
	} finally {
		servlet.unregisterInterceptor(interceptor);
	}
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:23,代码来源:ExceptionTest.java

示例3: incomingRequestPostProcessed

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Override
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
	
	StringBuilder b = new StringBuilder("Incoming request: ");
	b.append(theRequest.getMethod());
	b.append(" ");
	b.append(theRequest.getRequestURL());
	b.append("\n");
	
	for (Enumeration<String> headerEnumeration = theRequest.getHeaderNames(); headerEnumeration.hasMoreElements(); ) {
		String nextName = headerEnumeration.nextElement();
		for (Enumeration<String> valueEnumeration = theRequest.getHeaders(nextName); valueEnumeration.hasMoreElements(); ) {
			b.append(" * ").append(nextName).append(": ").append(valueEnumeration.nextElement()).append("\n");
		}
	}
	
	ourLog.info(b.toString());
	return true;
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:20,代码来源:VerboseLoggingInterceptor.java

示例4: incomingRequestPostProcessed

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Override
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
	EncodingEnum encoding = RestfulServerUtils.determineRequestEncodingNoDefault(theRequestDetails);
	if (encoding == null) {
		ourLog.trace("Incoming request does not appear to be FHIR, not going to validate");
		return true;
	}

	Charset charset = ResourceParameter.determineRequestCharset(theRequestDetails);
	String requestText = new String(theRequestDetails.loadRequestContents(), charset);

	if (isBlank(requestText)) {
		ourLog.trace("Incoming request does not have a body");
		return true;
	}

	ValidationResult validationResult = validate(requestText, theRequestDetails);

	// The JPA server will use this
	theRequestDetails.getUserData().put(REQUEST_VALIDATION_RESULT, validationResult);

	return true;
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:24,代码来源:RequestValidatingInterceptor.java

示例5: testServerReturnsAnHttp401

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Test
public void testServerReturnsAnHttp401() throws Exception {
	ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);

	when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 401, "Unauthorized"));
	when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT));
	when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<InputStream>() {
		@Override
		public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
			return new ReaderInputStream(new StringReader("Unauthorized"), Charset.forName("UTF-8"));
		}
	});
	when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);

	IGenericClient client = myCtx.newRestfulGenericClient("http://foo");
	try {
		client.read().resource(Patient.class).withId("123").execute();
		fail();
	} catch (AuthenticationException e) {
		// good
	}
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:23,代码来源:ClientServerValidationDstu2Test.java

示例6: incomingRequestPreProcessed

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Override
public boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse) {

    String resourcePath = theRequest.getPathInfo();
    logger.info("Accessing Resource" + resourcePath);
    if (excludedPaths.contains(resourcePath)){
        logger.info("Accessing unprotected resource" + resourcePath);
        return true;
    }

    String authorizationHeader = theRequest.getHeader(HttpHeaders.AUTHORIZATION);
    if (authorizationHeader == null){
        logger.warn("OAuth2 Authentication failure.  No OAuth Token supplied in Authorization Header on Request.");
        throw new AuthenticationException("Unauthorised access to protected resource");
    }
    OAuthToken oAuthToken = OAuthTokenUtil.parseOAuthToken(authorizationHeader);

    // Check that the OAuth Token has not expired
    if (oAuthToken.isExpired()){
        logger.warn("OAuth2 Authentication failure due to expired token");
        throw new AuthenticationException("OAuth2 Authentication Token has expired.");
    }

    // Check that the Scopes on the Token allow access to the specified resource
    String resourceName = extractResourceName(resourcePath);
    if (!allowedAccess(resourceName, theRequest.getMethod(), oAuthToken)){
        logger.warn("OAuth2 Authentication failed due to insufficient access rights: ");
        throw new ForbiddenOperationException(String.format("Insufficient Access Rights to access %s.", resourceName));
    }

    logger.debug("Authenticated Access to " + resourcePath);
    return true;
}
 
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:34,代码来源:OAuth2Interceptor.java

示例7: extractTokenFromHeader

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
public static String extractTokenFromHeader(String authHeader) {
    if (authHeader.toLowerCase().startsWith(TOKEN_PREFIX)) {
        return authHeader.substring(TOKEN_PREFIX.length());
    } else {
        throw new AuthenticationException("Invalid OAuth Header.  Missing Bearer prefix");
    }
}
 
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:8,代码来源:OAuthTokenUtil.java

示例8: incomingRequestPostProcessed

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Override
public boolean incomingRequestPostProcessed(final RequestDetails theRequestDetails, final HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {

	// Perform any string substitutions from the message format
	StrLookup<?> lookup = new MyLookup(theRequest, theRequestDetails);
	StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');

	// Actuall log the line
	String line = subs.replace(myMessageFormat);
	myLogger.info(line);

	return true;
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:14,代码来源:LoggingInterceptor.java

示例9: incomingRequestPostProcessed

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Override
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
	if (theRequestDetails.getOtherOperationType() == OtherOperationTypeEnum.METADATA) {
		return true;
	}
	
	authenticate(theRequest);
	
	return true;
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:11,代码来源:OpenIdConnectBearerTokenServerInterceptor.java

示例10: testModifyResponse

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Test
public void testModifyResponse() throws IOException {
	InterceptorAdapter interceptor = new InterceptorAdapter() {
		@Override
		public boolean outgoingResponse(RequestDetails theRequestDetails, ResponseDetails theResponseDetails, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException {
			Patient retVal = new Patient();
			retVal.setId(theResponseDetails.getResponseResource().getIdElement());
			retVal.addName().setFamily("NAME1");
			theResponseDetails.setResponseResource(retVal);
			theResponseDetails.setResponseCode(202);
			return true;
		}
	};
	ourServlet.registerInterceptor(interceptor);
	try {

		HttpGet get = new HttpGet("http://localhost:" + ourPort + "/Patient/1");
		try (CloseableHttpResponse status = ourClient.execute(get)) {
			String response = IOUtils.toString(status.getEntity().getContent(), Constants.CHARSET_UTF8);
			assertThat(response, containsString("NAME1"));
			assertEquals(202, status.getStatusLine().getStatusCode());
			assertEquals("Accepted", status.getStatusLine().getReasonPhrase());
		}

	} finally {
		ourServlet.unregisterInterceptor(interceptor);
	}
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:29,代码来源:InterceptorDstu3Test.java

示例11: incomingRequestPostProcessed

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:34,代码来源:SecurityInterceptors.java

示例12: basicAuthInterceptorRealm

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
public void basicAuthInterceptorRealm() {
   //START SNIPPET: basicAuthInterceptorRealm
   AuthenticationException ex = new AuthenticationException();
   ex.addAuthenticateHeaderForRealm("myRealm");
   throw ex;
   //END SNIPPET: basicAuthInterceptorRealm
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:8,代码来源:SecurityInterceptors.java

示例13: parseJwtToken

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
private static OAuthToken parseJwtToken(String jwtToken) {
    try {
        Jwt jwt = JwtHelper.decode(jwtToken);
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(jwt.getClaims().getBytes(), OAuthToken.class);
    } catch (IOException e) {
        throw new AuthenticationException("Invalid OAuth2 Token", e);
    }
}
 
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:10,代码来源:OAuthTokenUtil.java

示例14: parseOauth2TokenWithoutPrefixTest

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Test
public void parseOauth2TokenWithoutPrefixTest(){
    thrown.expectMessage("Invalid OAuth Token.  Missing Bearer prefix");
    thrown.expect(AuthenticationException.class);
    OAuthTokenUtil.parseOAuthToken(JWT_TOKEN);
}
 
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:7,代码来源:OAuthTokenUtilTest.java

示例15: outgoingResponse

import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; //导入依赖的package包/类
@Override
public boolean outgoingResponse(RequestDetails theRequestDetails, TagList theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException {
	return true;
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:5,代码来源:ResponseValidatingInterceptor.java


注:本文中的ca.uhn.fhir.rest.server.exceptions.AuthenticationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。