本文整理汇总了Java中com.sun.jersey.core.util.Base64.decode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.decode方法的具体用法?Java Base64.decode怎么用?Java Base64.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jersey.core.util.Base64
的用法示例。
在下文中一共展示了Base64.decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
@BeforeClass
public static void init() throws Exception {
// setup server 1, will use first keystore/truststore with client auth
TEST_PORT = new Random().nextInt(1000) + 4000;
TEST_SERVICE_URI = "https://127.0.0.1:" + TEST_PORT + "/";
// jks format
byte[] sampleTruststore1 = Base64.decode(SecureGetTest.TEST_TS1);
byte[] sampleKeystore1 = Base64.decode(SecureGetTest.TEST_KS1);
TEST_FILE_KS = File.createTempFile("SecureAcceptAllGetTest", ".keystore");
TEST_FILE_TS = File.createTempFile("SecureAcceptAllGetTest", ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(TEST_FILE_KS);
try {
keystoreFileOut.write(sampleKeystore1);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(TEST_FILE_TS);
try {
truststoreFileOut.write(sampleTruststore1);
} finally {
truststoreFileOut.close();
}
try{
TEST_SERVER = new SimpleSSLTestServer(TEST_FILE_TS, SecureGetTest.PASSWORD, TEST_FILE_KS, SecureGetTest.PASSWORD, TEST_PORT, false);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例2: filter
import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
String username = request.getHeaderValue(AuthConstants.USERNAME_HEADER);
String token = request.getHeaderValue(AuthConstants.TOKEN_HEADER);
String auth = request.getHeaderValue(HttpHeaders.AUTHORIZATION);
if (username == null) {
if (auth != null) {
if (!auth.startsWith("Basic ")) {
throw new WebApplicationException(Status.BAD_REQUEST);
}
String decoded = new String(Base64.decode(auth
.replaceFirst("Basic ", "")));
int sep = decoded.indexOf(':');
if (sep >= 0) {
username = decoded.substring(0, sep);
token = decoded.substring(sep + 1);
} else {
throw new WebApplicationException(Status.BAD_REQUEST);
}
}
}
if (username != null) {
if (username.isEmpty() || token == null || token.isEmpty()) {
throw new WebApplicationException(Status.BAD_REQUEST);
}
try {
User user = service.getUser(username);
if (passwordEncoder.verify(token, user.getToken())) {
request.setSecurityContext(
new SecurityContextImpl(user, request.isSecure()));
} else {
throw new WebApplicationException(Status.FORBIDDEN);
}
} catch (UserNotFoundException ex) {
throw new WebApplicationException(ex, Status.FORBIDDEN);
}
}
return request;
}
示例3: testGetKeystoreWithClientAuth
import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
@Test
public void testGetKeystoreWithClientAuth() throws Exception{
// jks format
byte[] dummyTruststore = Base64.decode(SecureGetTest.TEST_TS1);
byte[] dummyKeystore = Base64.decode(SecureGetTest.TEST_KS1);
File tempKeystore = File.createTempFile(this.getClass().getName(), ".keystore");
File tempTruststore = File.createTempFile(this.getClass().getName(), ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(tempKeystore);
try {
keystoreFileOut.write(dummyKeystore);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(tempTruststore);
try {
truststoreFileOut.write(dummyTruststore);
} finally {
truststoreFileOut.close();
}
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = this.getClass().getName() + ".test1";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsClientAuthRequired, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, tempKeystore.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, "changeit");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, tempTruststore.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, "changeit");
RestClient client = (RestClient) ClientFactory.getNamedClient(name);
KeyStore keyStore = client.getKeyStore();
Certificate cert = keyStore.getCertificate("ribbon_key");
assertNotNull(cert);
}
示例4: testGetKeystoreWithNoClientAuth
import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
@Test
public void testGetKeystoreWithNoClientAuth() throws Exception{
// jks format
byte[] dummyTruststore = Base64.decode(SecureGetTest.TEST_TS1);
byte[] dummyKeystore = Base64.decode(SecureGetTest.TEST_KS1);
File tempKeystore = File.createTempFile(this.getClass().getName(), ".keystore");
File tempTruststore = File.createTempFile(this.getClass().getName(), ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(tempKeystore);
try {
keystoreFileOut.write(dummyKeystore);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(tempTruststore);
try {
truststoreFileOut.write(dummyTruststore);
} finally {
truststoreFileOut.close();
}
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = this.getClass().getName() + ".test2";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, tempKeystore.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, "changeit");
RestClient client = (RestClient) ClientFactory.getNamedClient(name);
KeyStore keyStore = client.getKeyStore();
Certificate cert = keyStore.getCertificate("ribbon_key");
assertNotNull(cert);
}
示例5: before
import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
public void before(final Description description) throws Exception {
this.service = Executors.newFixedThreadPool(
threadCount,
new ThreadFactoryBuilder().setDaemon(true).setNameFormat("TestHttpServer-%d").build());
InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 0);
if (hasSsl) {
byte[] sampleTruststore1 = Base64.decode(TEST_TS1);
byte[] sampleKeystore1 = Base64.decode(TEST_KS1);
keystore = File.createTempFile("SecureAcceptAllGetTest", ".keystore");
truststore = File.createTempFile("SecureAcceptAllGetTest", ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(keystore);
try {
keystoreFileOut.write(sampleKeystore1);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(truststore);
try {
truststoreFileOut.write(sampleTruststore1);
} finally {
truststoreFileOut.close();
}
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(keystore), PASSWORD.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, PASSWORD.toCharArray());
KeyStore ts = KeyStore.getInstance("JKS");
ts.load(new FileInputStream(truststore), PASSWORD.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ts);
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
HttpsServer secureServer = HttpsServer.create(inetSocketAddress, 0);
secureServer.setHttpsConfigurator(new HttpsConfigurator(sc) {
public void configure (HttpsParameters params) {
SSLContext c = getSSLContext();
SSLParameters sslparams = c.getDefaultSSLParameters();
params.setSSLParameters(sslparams);
}
});
server = secureServer;
}
else {
server = HttpServer.create(inetSocketAddress, 0);
}
server.setExecutor(service);
for (Entry<String, HttpHandler> handler : handlers.entrySet()) {
server.createContext(handler.getKey(), handler.getValue());
}
server.start();
localHttpServerPort = server.getAddress().getPort();
System.out.println(description.getClassName() + " TestServer is started: " + getServerUrl());
}
示例6: string_base64_decode_apache
import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
@Test
public void string_base64_decode_apache() throws UnsupportedEncodingException {
String encodedPhrase = "TGVhcm4uIEVhdC4gQ29kZS4=";
byte[] decodedPhraseAsBytes = Base64.decode(encodedPhrase);
String phraseDecodedToString = new String(decodedPhraseAsBytes, "utf-8");
assertEquals("Learn. Eat. Code.", phraseDecodedToString);
}
示例7: decompressString
import com.sun.jersey.core.util.Base64; //导入方法依赖的package包/类
/**
* Decompresses the given byte array and decodes with Base64 decoding
*
* @param compressed byte array input
* @return decompressed data in string format
* @throws IOException
*/
public static String decompressString(byte[] compressed) throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(compressed);
InputStream gis = new GZIPInputStream(is);
return new String(Base64.decode(IOUtils.toByteArray(gis)), StandardCharsets.UTF_8);
}