本文整理汇总了Java中org.glassfish.jersey.internal.util.Base64.encodeAsString方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.encodeAsString方法的具体用法?Java Base64.encodeAsString怎么用?Java Base64.encodeAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.jersey.internal.util.Base64
的用法示例。
在下文中一共展示了Base64.encodeAsString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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();
}
示例4: 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();
}
示例5: 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.");
}
}
示例6: 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.");
}
}
示例7: 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.");
}
}
示例8: 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);
}
示例9: 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);
}
示例10: shouldNotReturnADtoResponse_WhenBadlySigned_NoMatch
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
@Test
public void shouldNotReturnADtoResponse_WhenBadlySigned_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(aValidNoMatchResponseFromMatchingServiceisBadlySigned(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);
}
示例11: shouldNotReturnADtoWhenResponseIs_bad
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
@Test
public void shouldNotReturnADtoWhenResponseIs_bad() throws Exception {
final String requestId = "requestId";
final SamlResponseDto samlResponseDto = new SamlResponseDto(Base64.encodeAsString(anInvalidAMatchingServiceSamlResponse(requestId)));
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);
}
示例12: shouldReturnADtoWhenResponseIs_TooOld
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
@Test
public void shouldReturnADtoWhenResponseIs_TooOld() 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, DateTime.now().minusDays(1))));
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);
}
示例13: should_redirect_to_user_detail_with_good_authorization_header
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
@Test
@Ignore // missing MVC template injection
public void should_redirect_to_user_detail_with_good_authorization_header() {
h.createUserWithPassword("tclavier", "motdepasse", "graindesel");
String authorization = "Basic " + Base64.encodeAsString("tclavier:motdepasse");
Response response = target(path).request().header(AUTHORIZATION, authorization).get();
int status = response.getStatus();
assertEquals(TEMPORARY_REDIRECT.getStatusCode(), status);
}
示例14: should_set_cookie_with_user_with_good_authorization_header
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
@Test
@Ignore // missing MVC template injection
public void should_set_cookie_with_user_with_good_authorization_header() {
h.createUserWithPassword("tclavier", "motdepasse", "graindesel");
String authorization = "Basic " + Base64.encodeAsString("tclavier:motdepasse");
Response response = target(path).request().header(AUTHORIZATION, authorization).get();
assertEquals(1, response.getCookies().size());
}
示例15: should_return_unauthorized_headers_with_authorization_header_on_same_user
import org.glassfish.jersey.internal.util.Base64; //导入方法依赖的package包/类
@Test
@Ignore // missing MVC template injection
public void should_return_unauthorized_headers_with_authorization_header_on_same_user() {
// Double user check in BDD insert (unique alias) so we dont need this test
h.createUserWithPassword("tclavier", "motdepasse", "graindesel");
String authorization = "Basic " + Base64.encodeAsString("tclavier:motdepasse");
Response response = target(path).queryParam("user", "tclavier").request().header(AUTHORIZATION, authorization).get();
int status = response.getStatus();
String wwwHeader = response.getHeaderString(HttpHeaders.WWW_AUTHENTICATE);
assertEquals(UNAUTHORIZED.getStatusCode(), status);
assertEquals("Basic realm=\"Mon application\"", wwwHeader);
}