本文整理汇总了Java中org.glassfish.jersey.internal.util.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于org.glassfish.jersey.internal.util包,在下文中一共展示了Base64类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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());
}
示例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);
}
示例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.");
}
}
示例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.");
}
}
示例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.");
}
}
示例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());
}
示例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);
}
示例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]);
}
示例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]);
}
示例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;
}