本文整理汇总了Java中org.glassfish.jersey.internal.util.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于org.glassfish.jersey.internal.util包,在下文中一共展示了Base64类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getRestAdapter
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
private RestAdapter getRestAdapter() {
return new RestAdapter.Builder()
.setEndpoint("http://localhost:8080")
.setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
if (!authenticatedUser.isPresent()) return;
String credentials = authenticatedUser.get().getEmail() + ":" + authenticatedUser.get().getPassword();
String base64EncodedCredentials = Base64.encodeAsString(credentials.getBytes());
request.addHeader("Authorization", "Basic " + base64EncodedCredentials);
}
})
.setClient(new LongTimeoutUrlConnectionClient())
.setConverter(new JacksonConverter())
.build();
}
开发者ID:AMOS-2015,项目名称:amos-ss15-proj2,代码行数:17,代码来源:ApiFactory.java
示例2: shouldReturnADtoWhenResponseIs_Match
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void shouldReturnADtoWhenResponseIs_Match() throws Exception {
final String requestId = "requestId";
final String msaStatusCode = SamlStatusCode.MATCH;
final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(SUCCESS).build()).build();
final SamlResponseDto samlResponseDto = new SamlResponseDto(Base64.encodeAsString(aValidMatchResponseFromMatchingService(requestId, status)));
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = clientResponse.readEntity(InboundResponseFromMatchingServiceDto.class);
assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(TEST_RP_MS);
assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(requestId);
assertThat(inboundResponseFromMatchingServiceDto.getStatus().name()).isEqualTo(MatchingServiceIdaStatus.MatchingServiceMatch.name());
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().isPresent()).isTrue();
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().get()).isEqualTo(LevelOfAssurance.LEVEL_2);
assertThat(inboundResponseFromMatchingServiceDto.getUnderlyingMatchingServiceAssertionBlob().isPresent()).isTrue();
}
开发者ID:alphagov,项目名称:verify-hub,代码行数:19,代码来源:MatchingServiceResponseTranslatorResourceTest.java
示例3: shouldReturnADtoWhenResponseIs_NoMatch
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void shouldReturnADtoWhenResponseIs_NoMatch() throws Exception {
final String requestId = "requestId";
final String msaStatusCode = SamlStatusCode.NO_MATCH;
final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(RESPONDER).build()).build();
final SamlResponseDto samlResponseDto = new SamlResponseDto(Base64.encodeAsString(aValidNoMatchResponseFromMatchingService(requestId, status, TEST_RP_MS)));
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = clientResponse.readEntity(InboundResponseFromMatchingServiceDto.class);
assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(TEST_RP_MS);
assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(requestId);
assertThat(inboundResponseFromMatchingServiceDto.getStatus().name()).isEqualTo(MatchingServiceIdaStatus.NoMatchingServiceMatchFromMatchingService.name());
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().isPresent()).isFalse();
assertThat(inboundResponseFromMatchingServiceDto.getUnderlyingMatchingServiceAssertionBlob().isPresent()).isFalse();
}
开发者ID:alphagov,项目名称:verify-hub,代码行数:18,代码来源:MatchingServiceResponseTranslatorResourceTest.java
示例4: shouldReturnADtoWhenResponseIs_RequesterError
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void shouldReturnADtoWhenResponseIs_RequesterError() throws Exception {
final String requestId = "requestId";
final String msaStatusCode = StatusCode.NO_AUTHN_CONTEXT;
final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(REQUESTER).build()).build();
final SamlResponseDto samlResponseDto = new SamlResponseDto(Base64.encodeAsString(aValidNoMatchResponseFromMatchingService(requestId, status, TEST_RP_MS)));
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = clientResponse.readEntity(InboundResponseFromMatchingServiceDto.class);
assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(TEST_RP_MS);
assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(requestId);
assertThat(inboundResponseFromMatchingServiceDto.getStatus().name()).isEqualTo(MatchingServiceIdaStatus.RequesterError.name());
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().isPresent()).isFalse();
assertThat(inboundResponseFromMatchingServiceDto.getUnderlyingMatchingServiceAssertionBlob().isPresent()).isFalse();
}
开发者ID:alphagov,项目名称:verify-hub,代码行数:18,代码来源:MatchingServiceResponseTranslatorResourceTest.java
示例5: shouldReturnADtoWhenResponseIs_Created
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void shouldReturnADtoWhenResponseIs_Created() throws Exception {
final String requestId = "requestId";
final String msaStatusCode = SamlStatusCode.CREATED;
final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(SUCCESS).build()).build();
final SamlResponseDto samlResponseDto = new SamlResponseDto(Base64.encodeAsString(aValidMatchResponseFromMatchingService(requestId, status)));
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = clientResponse.readEntity(InboundResponseFromMatchingServiceDto.class);
assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(TEST_RP_MS);
assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(requestId);
assertThat(inboundResponseFromMatchingServiceDto.getStatus().name()).isEqualTo(MatchingServiceIdaStatus.UserAccountCreated.name());
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().isPresent()).isTrue();
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().get()).isEqualTo(LevelOfAssurance.LEVEL_2);
assertThat(inboundResponseFromMatchingServiceDto.getUnderlyingMatchingServiceAssertionBlob().isPresent()).isTrue();
}
开发者ID:alphagov,项目名称:verify-hub,代码行数:19,代码来源:MatchingServiceResponseTranslatorResourceTest.java
示例6: handle_shouldBase64EncodeSamlToBeSentToSamlEngine
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void handle_shouldBase64EncodeSamlToBeSentToSamlEngine() throws Exception {
final String saml = "<samlsamlsamlsamlsamlsamlsamlsamlsaml/>";
MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto =
aMatchingServiceConfigEntityDataDto().build();
prepareForHealthyResponse(matchingServiceConfigEntityDataDto, Optional.<String>absent());
when(matchingServiceHealthCheckClient.sendHealthCheckRequest(any(),
eq(matchingServiceConfigEntityDataDto.getUri())
))
.thenReturn(new MatchingServiceHealthCheckResponseDto(Optional.of(saml), Optional.of("101010")));
matchingServiceHealthChecker.performHealthCheck(aMatchingServiceConfigEntityDataDto().build());
ArgumentCaptor<SamlMessageDto> argumentCaptor = ArgumentCaptor.forClass(SamlMessageDto.class);
verify(samlEngineProxy, times(1)).translateHealthcheckMatchingServiceResponse(argumentCaptor.capture());
assertThat(Base64.encodeAsString(saml)).isEqualTo(argumentCaptor.getValue().getSamlMessage());
}
开发者ID:alphagov,项目名称:verify-hub,代码行数:18,代码来源:MatchingServiceHealthCheckerTest.java
示例7: run_shouldSendResponse
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void run_shouldSendResponse() throws Exception {
final Element matchingServiceResponse = XmlUtils.convertToElement("<someResponse/>");
when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto))
.thenReturn(matchingServiceResponse);
attributeQueryRequestRunnable.run();
String stringifiedResponse = XmlUtils.writeToString(matchingServiceResponse);
verify(hubMatchingServiceResponseReceiverProxy).notifyHubOfAResponseFromMatchingService(
eq(sessionId),
eq(Base64.encodeAsString(stringifiedResponse))
);
verify(timeoutEvaluator, times(2)).hasAttributeQueryTimedOut(attributeQueryContainerDto);
}
开发者ID:alphagov,项目名称:verify-hub,代码行数:17,代码来源:AttributeQueryRequestRunnableTest.java
示例8: post
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
public JSONObject post(final String path, final byte[] data, final String contentType, final String username, final String password, final String protocolFlag) throws HttpException, JSONException{
if ((null != username && null != password)) {
WebTarget target = null;
Response response = null;
target = getTarget(path, username, password);
String encoding = Base64.encodeAsString(username+":"+password);
response = target.request().header("Authorization", "Basic " + encoding).post(Entity.entity(data, contentType));
return getResponseDataInJson(response);
} else {
throw new HttpException("Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty.");
}
}
开发者ID:att,项目名称:dmaap-framework,代码行数:18,代码来源:MRBaseClient.java
示例9: postWithResponse
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
public String postWithResponse(final String path, final byte[] data, final String contentType, final String username, final String password, final String protocolFlag) throws HttpException, JSONException{
String responseData = null;
if ((null != username && null != password)) {
WebTarget target = null;
Response response = null;
target = getTarget(path, username, password);
String encoding = Base64.encodeAsString(username+":"+password);
response = target.request().header("Authorization", "Basic " + encoding).post(Entity.entity(data, contentType));
responseData = response.readEntity(String.class);
return responseData;
} else {
throw new HttpException("Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty.");
}
}
开发者ID:att,项目名称:dmaap-framework,代码行数:20,代码来源:MRBaseClient.java
示例10: get
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
public JSONObject get(final String path, final String username, final String password, final String protocolFlag) throws HttpException, JSONException {
if (null != username && null != password) {
WebTarget target = null;
Response response = null;
if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
target=getTarget(path);
response = target.request()
.header(MR_AUTH_CONSTANT, username)
.header(MR_DATE_CONSTANT, password)
.get();
} else {
target = getTarget(path, username, password);
String encoding = Base64.encodeAsString(username+":"+password);
response = target.request().header("Authorization", "Basic " + encoding).get();
}
return getResponseDataInJson(response);
} else {
throw new HttpException("Authentication Failed: Username/password/AuthKey/Authdate parameter(s) cannot be null or empty.");
}
}
开发者ID:att,项目名称:dmaap-framework,代码行数:25,代码来源:MRBaseClient.java
示例11: testFieldToXmlElementsFieldBasicBinary
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void testFieldToXmlElementsFieldBasicBinary() throws IOException, DataGeneratorException {
Writer writer = Mockito.mock(Writer.class);
XmlCharDataGenerator generator = new XmlCharDataGenerator(writer, true, ImmutableList.of(SCHEMA), true);
Document document = generator.getDocumentBuilder().newDocument();
String name = "element";
Map<String, String> namespaces = ImmutableMap.of("", "", "ns", "NS");
Field field = Field.create(new byte[]{0, 1, 2});
List<Element> elements = generator.fieldToXmlElements(document, namespaces, name, field);
Assert.assertEquals(1, elements.size());
Element element = elements.get(0);
Assert.assertEquals("element", element.getNodeName());
Assert.assertEquals(null, element.getNamespaceURI());
Assert.assertEquals(1, element.getChildNodes().getLength());
Assert.assertEquals(Base64.encodeAsString(new byte[]{0, 1, 2}), element.getTextContent());
}
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:TestXmlCharDataGenerator.java
示例12: generateBasicAuthHeader
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
public static String generateBasicAuthHeader(String username, String password) {
if (username == null) {
username = "";
}
if (password == null) {
password = "";
}
final byte[] prefix = (username + ":").getBytes();
final byte[] passwordByte = password.getBytes();
final byte[] usernamePassword = new byte[prefix.length + passwordByte.length];
System.arraycopy(prefix, 0, usernamePassword, 0, prefix.length);
System.arraycopy(passwordByte, 0, usernamePassword, prefix.length, passwordByte.length);
return "Basic " + Base64.encodeAsString(usernamePassword);
}
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:WebSocketCommon.java
示例13: testBasicAuthentication
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void testBasicAuthentication() throws Exception {
final Context context = new Context()
.setBaseUrl(BASE_URL)
.setSecurityMode(SecurityMode.BASIC_AUTHENTICATION)
.setUsername("user1")
.setPassword("pswrd");
final Netlicensing res = NetLicensingService.getInstance().request(context, HttpMethod.GET, "get-auth-header",
null, null);
final String authHeader = res.getInfos().getInfo().iterator().next().getValue();
assertTrue(authHeader.startsWith("Basic "));
final String[] userAndPassword = Base64.decodeAsString(authHeader.substring(6)).split(":");
assertEquals("user1", userAndPassword[0]);
assertEquals("pswrd", userAndPassword[1]);
}
开发者ID:Labs64,项目名称:NetLicensingClient-java,代码行数:19,代码来源:SecurityTest.java
示例14: testApiKeyIdentification
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void testApiKeyIdentification() throws Exception {
final Context context = new Context()
.setBaseUrl(BASE_URL)
.setSecurityMode(SecurityMode.APIKEY_IDENTIFICATION)
.setApiKey("TEST_API_KEY");
final Netlicensing res = NetLicensingService.getInstance().request(context, HttpMethod.GET, "get-auth-header",
null, null);
final String authHeader = res.getInfos().getInfo().iterator().next().getValue();
assertTrue(authHeader.startsWith("Basic "));
final String[] headerArray = Base64.decodeAsString(authHeader.substring(6)).split(":");
assertEquals("apiKey", headerArray[0]);
assertEquals("TEST_API_KEY", headerArray[1]);
}
开发者ID:Labs64,项目名称:NetLicensingClient-java,代码行数:19,代码来源:SecurityTest.java
示例15: checkBasicAuthentication
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
/**
* Triggers authentication over HTTP
*
* @param request
* The incoming request for the servlet
* @param response
* The outgoing response of the servlet
* @return The user
* @throws IOException
*/
public User checkBasicAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Basic authentication for REST API
if (null != request.getHeader("Authorization")) {
String header = request.getHeader("Authorization");
if (header.substring(0, 6).equals("Basic ")) {
String[] credentials = Base64.decodeAsString(header.substring(6).getBytes()).split(":");
if (credentials.length > 1) {
String username = credentials[0];
String password = credentials[1];
String hashedPassword = Hash.sha256(password);
LoadCheckedUserService loadCheckedUserService = new LoadCheckedUserService(username, hashedPassword);
if (!loadCheckedUserService.hasErrors()) {
return loadCheckedUserService.getResult();
} else {
// TODO: log more than one error
LOGGER.error(StringUtils.join(loadCheckedUserService.getErrors()));
response.sendError(401);
}
}
}
}
LOGGER.info("Basic Authorization: Invalid credentials");
response.sendError(401);
return null;
}
开发者ID:CloudCycle2,项目名称:CSAR_Repository,代码行数:36,代码来源:AbstractServlet.java
示例16: extractBasicAuthCredentials
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
private String[] extractBasicAuthCredentials(String authorizationHeader) {
if (authorizationHeader == null) {
return null;
}
String[] schemeUserPass = new String[3];
String credentials;
final String[] headerParts = authorizationHeader.split(" ");
if (headerParts != null && headerParts.length == 2) {
schemeUserPass[0] = headerParts[0].equalsIgnoreCase("basic") ? SecurityContext.BASIC_AUTH : null;
credentials = Base64.decodeAsString(headerParts[1]);
final String[] userPass = credentials.split(":");
if (userPass != null && userPass.length == 2) {
schemeUserPass[1] = userPass[0].replaceAll("%40", "@");
schemeUserPass[2] = userPass[1];
}
return schemeUserPass;
}
return null;
}
开发者ID:graylog-labs,项目名称:jersey-netty,代码行数:20,代码来源:NettyContainer.java
示例17: getUsername
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
private static String getUsername(final HttpServletRequest request) {
// Extract authentication credentials
String authentication = request.getHeader(AUTHORIZATION);
if (authentication == null) {
return null;
}
if (!authentication.startsWith("Basic ")) {
return null;
}
authentication = authentication.substring("Basic ".length());
final String[] values = Base64.decodeAsString(authentication).split(":");
if (values.length < 2) {
throw new WebApplicationException(400);
// "Invalid syntax for username and password"
}
final String username = values[0];
final String password = values[1];
if ((username == null) || (password == null)) {
return null;
}
return username;
}
开发者ID:fcrepo4,项目名称:fcrepo4,代码行数:23,代码来源:TestAuthenticationRequestFilter.java
示例18: should_translateHealthcheckAttributeQueryResponse
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void should_translateHealthcheckAttributeQueryResponse() throws Exception {
final String msaStatusCode = SamlStatusCode.HEALTHY;
final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(StatusCode.SUCCESS).build()).build();
final String requestId = "requestId";
final String saml = aValidMatchResponseFromMatchingService(requestId, status, DateTime.now().plusHours(1));
Response response = postResponseForTranslation(new SamlMessageDto(Base64.encodeAsString(saml)));
MatchingServiceHealthCheckerResponseDto entity = response.readEntity(MatchingServiceHealthCheckerResponseDto.class);
assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
assertThat(entity.getStatus()).isEqualTo(MatchingServiceIdaStatus.Healthy);
assertThat(entity.getInResponseTo()).isEqualTo(requestId);
assertThat(entity.getIssuer()).isEqualTo(TEST_RP_MS);
}
开发者ID:alphagov,项目名称:verify-hub,代码行数:16,代码来源:MatchingServiceHealthcheckResponseTranslatorResourceTest.java
示例19: should_shouldReturnErrorStatusDtoWhenThereIsAProblem
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void should_shouldReturnErrorStatusDtoWhenThereIsAProblem() throws Exception {
Response response = postResponseForTranslation(new SamlMessageDto(Base64.encodeAsString("<saml/>")));
assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto entity = response.readEntity(ErrorStatusDto.class);
assertThat(entity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
开发者ID:alphagov,项目名称:verify-hub,代码行数:9,代码来源:MatchingServiceHealthcheckResponseTranslatorResourceTest.java
示例20: shouldNotReturnADtoResponse_WhenFieldsAreMissing_Match
import org.glassfish.jersey.internal.util.Base64; //导入依赖的package包/类
@Test
public void shouldNotReturnADtoResponse_WhenFieldsAreMissing_Match() throws Exception {
final String requestId = "requestId";
final String msaStatusCode = SamlStatusCode.MATCH;
final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(SUCCESS).build()).build();
final SamlResponseDto samlResponseDto = new SamlResponseDto(Base64.encodeAsString(aValidMatchResponseFromMatchingServiceWithMissingData(requestId, status, TEST_RP_MS)));
Response clientResponse = postToSamlEngine(samlResponseDto);
assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
开发者ID:alphagov,项目名称:verify-hub,代码行数:15,代码来源:MatchingServiceResponseTranslatorResourceTest.java
注:本文中的org.glassfish.jersey.internal.util.Base64类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论