org.glassfish.jersey.internal.util.Base64 Java Examples
The following examples show how to use
org.glassfish.jersey.internal.util.Base64.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestgridSSOAgentFilter.java From testgrid with Apache License 2.0 | 6 votes |
/** * Prepare HTMLPayload including the username and password values in the way IdP requests. */ private String prepareHtmlPayloadForAuthorization(String userName, String password) { String authorization = userName + ":" + password; // Base64 encoded username:password value. authorization = Arrays.toString(Base64.encode(authorization.getBytes(StandardCharsets.UTF_8))); return "<html>\n" + "<body>\n" + "<p>You are now redirected back to " + properties.getProperty("SAML2.IdPURL") + " \n" + "If the redirection fails, please click the post button.</p>\n" + "<form method='post' action='" + properties.getProperty("SAML2.IdPURL") + "'>\n" + "<input type='hidden' name='sectoken' value='" + authorization + "'/>\n" + "<p>\n" + "<!--$saml_params-->\n" + "<button type='submit'>POST</button>\n" + "</p>\n" + "</form>\n" + "<script type='text/javascript'>\n" + "document.forms[0].submit();\n" + "</script>\n" + "</body>\n" + "</html>"; }
Example #2
Source File: TestXmlCharDataGenerator.java From datacollector with Apache License 2.0 | 6 votes |
@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()); }
Example #3
Source File: WebSocketCommon.java From datacollector with Apache License 2.0 | 6 votes |
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); }
Example #4
Source File: DefaultDockerClientUnitTest.java From docker-client with Apache License 2.0 | 6 votes |
@Test public void testCreateConfig() throws Exception { final DefaultDockerClient dockerClient = new DefaultDockerClient(builder); enqueueServerApiVersion("1.30"); server.enqueue(new MockResponse() .setResponseCode(201) .addHeader("Content-Type", "application/json") .setBody( fixture("fixtures/1.30/inspectConfig.json") ) ); final ConfigSpec configSpec = ConfigSpec .builder() .data(Base64.encodeAsString("foobar")) .name("foo.yaml") .build(); final ConfigCreateResponse configCreateResponse = dockerClient.createConfig(configSpec); assertThat(configCreateResponse.id(), equalTo("ktnbjxoalbkvbvedmg1urrz8h")); }
Example #5
Source File: DefaultDockerClientUnitTest.java From docker-client with Apache License 2.0 | 6 votes |
@Test(expected = ConflictException.class) public void testCreateConfig_ConflictingName() throws Exception { final DefaultDockerClient dockerClient = new DefaultDockerClient(builder); enqueueServerApiVersion("1.30"); server.enqueue(new MockResponse() .setResponseCode(409) .addHeader("Content-Type", "application/json") ); final ConfigSpec configSpec = ConfigSpec .builder() .data(Base64.encodeAsString("foobar")) .name("foo.yaml") .build(); dockerClient.createConfig(configSpec); }
Example #6
Source File: DefaultDockerClientUnitTest.java From docker-client with Apache License 2.0 | 6 votes |
@Test(expected = NonSwarmNodeException.class) public void testCreateConfig_NonSwarmNode() throws Exception { final DefaultDockerClient dockerClient = new DefaultDockerClient(builder); enqueueServerApiVersion("1.30"); server.enqueue(new MockResponse() .setResponseCode(503) .addHeader("Content-Type", "application/json") ); final ConfigSpec configSpec = ConfigSpec .builder() .data(Base64.encodeAsString("foobar")) .name("foo.yaml") .build(); dockerClient.createConfig(configSpec); }
Example #7
Source File: DefaultDockerClientUnitTest.java From docker-client with Apache License 2.0 | 6 votes |
@Test(expected = NotFoundException.class) public void testUpdateConfig_NotFound() throws Exception { final DefaultDockerClient dockerClient = new DefaultDockerClient(builder); enqueueServerApiVersion("1.30"); server.enqueue(new MockResponse() .setResponseCode(404) .addHeader("Content-Type", "application/json") ); final ConfigSpec configSpec = ConfigSpec .builder() .data(Base64.encodeAsString("foobar")) .name("foo.yaml") .build(); dockerClient.updateConfig("ktnbjxoalbkvbvedmg1urrz8h", 11L, configSpec); }
Example #8
Source File: DefaultDockerClientUnitTest.java From docker-client with Apache License 2.0 | 6 votes |
@Test(expected = NonSwarmNodeException.class) public void testUpdateConfig_NonSwarmNode() throws Exception { final DefaultDockerClient dockerClient = new DefaultDockerClient(builder); enqueueServerApiVersion("1.30"); server.enqueue(new MockResponse() .setResponseCode(503) .addHeader("Content-Type", "application/json") ); final ConfigSpec configSpec = ConfigSpec .builder() .data(Base64.encodeAsString("foobar")) .name("foo.yaml") .build(); dockerClient.updateConfig("ktnbjxoalbkvbvedmg1urrz8h", 11L, configSpec); }
Example #9
Source File: RestClient.java From REST-API-Client with Apache License 2.0 | 5 votes |
/** * Authentication token. * * @param token * the token * @return the rest client builder */ public RestClientBuilder authenticationToken(AuthenticationToken token) { if (token.getAuthMode() == AuthenticationMode.SHARED_SECRET_KEY) { headers.add(HttpHeaders.AUTHORIZATION, token.getSharedSecretKey()); } else if (token.getAuthMode() == AuthenticationMode.BASIC_AUTH) { String base64 = Base64.encodeAsString(token.getUsername() + ":" + token.getPassword()); headers.add(HttpHeaders.AUTHORIZATION, "Basic " + base64); } this.token = token; return this; }
Example #10
Source File: RegistryAuth.java From docker-client with Apache License 2.0 | 5 votes |
/** Construct a Builder based upon the "auth" field of the docker client config file. */ public static Builder forAuth(final String auth) { // split with limit=2 to catch case where password contains a colon final String[] authParams = Base64.decodeAsString(auth).split(":", 2); if (authParams.length != 2) { return builder(); } return builder() .username(authParams[0].trim()) .password(authParams[1].trim()); }
Example #11
Source File: SystemTestHelpers.java From jobson with Apache License 2.0 | 4 votes |
public static void authenticate(Invocation.Builder builder, String username, String password) { builder.header("Authorization", "Basic " + Base64.encodeAsString(username + ":" + password)); }
Example #12
Source File: DefaultDockerClientUnitTest.java From docker-client with Apache License 2.0 | 4 votes |
@Test public void testCreateServiceWithConfig() throws Exception { final DefaultDockerClient dockerClient = new DefaultDockerClient(builder); // build() calls /version to check what format of header to send enqueueServerApiVersion("1.30"); enqueueServerApiResponse(201, "fixtures/1.30/configCreateResponse.json"); final ConfigSpec configSpec = ConfigSpec .builder() .data(Base64.encodeAsString("foobar")) .name("foo.yaml") .build(); final ConfigCreateResponse configCreateResponse = dockerClient.createConfig(configSpec); assertThat(configCreateResponse.id(), equalTo("ktnbjxoalbkvbvedmg1urrz8h")); final ConfigBind configBind = ConfigBind.builder() .configName(configSpec.name()) .configId(configCreateResponse.id()) .file(ConfigFile.builder() .gid("1000") .uid("1000") .mode(600L) .name(configSpec.name()) .build() ).build(); final TaskSpec taskSpec = TaskSpec.builder() .containerSpec(ContainerSpec.builder() .image("this_image_is_found_in_the_registry") .configs(ImmutableList.of(configBind)) .build()) .build(); final ServiceSpec spec = ServiceSpec.builder() .name("test") .taskTemplate(taskSpec) .build(); enqueueServerApiVersion("1.30"); enqueueServerApiResponse(201, "fixtures/1.30/createServiceResponse.json"); final ServiceCreateResponse response = dockerClient.createService(spec); assertThat(response.id(), equalTo("ak7w3gjqoa3kuz8xcpnyy0pvl")); }