• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Base64类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jboss.resteasy.util.Base64的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Base64类属于org.jboss.resteasy.util包,在下文中一共展示了Base64类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: generateToken

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public static String generateToken(String secret)
{
   long minutes = System.currentTimeMillis() / 1000 / 60;
   String concat = secret + minutes;
   MessageDigest digest = null;
   try
   {
      digest = MessageDigest.getInstance("MD5");
   }
   catch (NoSuchAlgorithmException e)
   {
      throw new IllegalArgumentException(e);
   }
   byte[] hash = digest.digest(concat.getBytes(Charset.forName("UTF-8")));
   return Base64.encodeBytes(hash);
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:17,代码来源:OTP.java


示例2: registerMessagingServiceCallback

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public void registerMessagingServiceCallback(String consumerKey, String callback)
{
   WebTarget target = ClientBuilder.newClient().target(MessagingServiceCallbackRegistrationURL);
   Invocation.Builder builder = target.request();
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   builder.header("Authorization", "Basic " + base64Credentials);
   Form form = new Form("consumer_id", consumerKey);
   form.param("callback_uri", callback);
   Response response = null;
   try {
      response = builder.post(Entity.form(form));
      if (HttpResponseCodes.SC_OK != response.getStatus()) {
         throw new RuntimeException("Callback Registration failed");
      }
   }
   catch (Exception ex) {
      throw new RuntimeException("Callback Registration failed");
   }
   finally {
      response.close();
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:23,代码来源:SubscriberReceiver.java


示例3: produceMessages

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public void produceMessages()
{
  WebTarget target = ClientBuilder.newClient().target(MessagingServiceMessagesURL);
  Invocation.Builder builder = target.request();
  String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
  builder.header("Authorization", "Basic " + base64Credentials);
  Response response = null;
  try {
     response = builder.post(Entity.entity("Hello2 !", MediaType.TEXT_PLAIN_TYPE));
     if (HttpResponseCodes.SC_OK != response.getStatus()) {
        throw new RuntimeException("Messages can not be sent");
     }
  }
  catch (Exception ex) {
     throw new RuntimeException("Messages can not be sent");
  }
  finally {
     response.close();
  }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:21,代码来源:SubscriberReceiver.java


示例4: registerMessagingService

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public String registerMessagingService(String consumerKey) throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(ConsumerRegistrationURL);
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   Invocation.Builder builder = target.request();
   builder.header("Authorization", "Basic " + base64Credentials);
   
   Entity<Form> formEntity = Entity.form(new Form(OAuth.OAUTH_CONSUMER_KEY, consumerKey));
   Response response = null;
   try {
      response = builder.post(formEntity);
      if (HttpResponseCodes.SC_OK != response.getStatus()) {
         throw new RuntimeException("Registration failed");
      }
      // check that we got all tokens
      Map<String, String> tokens = OAuth.newMap(OAuth.decodeForm(response.readEntity(String.class)));
      String secret = tokens.get("xoauth_consumer_secret");
      if (secret == null) {
          throw new RuntimeException("No secret available");
      }
      return secret;
   } finally {
      response.close();
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:26,代码来源:Subscriber.java


示例5: registerMessagingServiceScopes

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public void registerMessagingServiceScopes(String consumerKey, String scope) throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(ConsumerScopesRegistrationURL);
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   Invocation.Builder builder = target.request();
   builder.header("Authorization", "Basic " + base64Credentials);
   Form form = new Form(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
   form.param("xoauth_scope", scope);
   form.param("xoauth_permission", "sendMessages");
   Response response = null;
   try {
      response = builder.post(Entity.form(form));
      if (HttpResponseCodes.SC_OK != response.getStatus()) {
         throw new RuntimeException("Scopes can not be registered");
      }
   } finally {
      response.close();
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:20,代码来源:Subscriber.java


示例6: registerMessagingServiceCallback

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public void registerMessagingServiceCallback(String consumerKey, String consumerSecret, String callback) 
    throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(MessagingServiceCallbackRegistrationURL);
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   Invocation.Builder builder = target.request();
   builder.header("Authorization", "Basic " + base64Credentials);
   Form form = new Form("consumer_id", consumerKey);
   form.param("consumer_secret", consumerSecret);
   form.param("callback_uri", callback);
   Response response = null;
   try {
      response = builder.post(Entity.form(form));
      if (HttpResponseCodes.SC_OK != response.getStatus()) {
         throw new RuntimeException("Callback Registration failed");
     }
   } finally {
      response.close();
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:21,代码来源:Subscriber.java


示例7: produceMessages

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public void produceMessages() 
   throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(MessagingServiceMessagesURL);
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   Invocation.Builder builder = target.request();
   builder.header("Authorization", "Basic " + base64Credentials);
   Response response = null;
   try {
      response = builder.post(Entity.entity("Hello", MediaType.TEXT_PLAIN_TYPE));
      if (HttpResponseCodes.SC_OK != response.getStatus()) {
         throw new RuntimeException("Messages can not be sent");
      }
   } finally {
      response.close();
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:18,代码来源:Subscriber.java


示例8: getMessages

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public void getMessages() 
    throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(MessageReceiverGetURL);
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   Invocation.Builder builder = target.request();
   builder.header("Authorization", "Basic " + base64Credentials);
   Response response = null;
   try {
      response = builder.get();
      if (HttpResponseCodes.SC_OK != response.getStatus()) {
         throw new RuntimeException("Messages can not be received");
      }
      String message = response.readEntity(String.class);
      if (!"Hello !".equals(message))
      {
         throw new RuntimeException("Wrong Message");
      }
      System.out.println("Success : " + message);
   } finally {
      response.close();
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:24,代码来源:Subscriber.java


示例9: getMessagesFromSubscriberReceiver

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public void getMessagesFromSubscriberReceiver() throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(MessageReceiverSubscriberGetURL);
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   Invocation.Builder builder = target.request();
   builder.header("Authorization", "Basic " + base64Credentials);
   Response response = null;
   try {
      response = builder.get();
      if (HttpResponseCodes.SC_OK != response.getStatus()) {
         throw new RuntimeException("Messages can not be received");
      }
      String message = response.readEntity(String.class);
      if (!"Hello2 !".equals(message))
      {
         throw new RuntimeException("Wrong Message");
      }
      System.out.println("Message from the subscriber-receiver : " + message);
   } finally {
      response.close();
   }
 }
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:23,代码来源:Subscriber.java


示例10: accessEndUserResource

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
private static void accessEndUserResource(String relativeURI) throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(EndUserResourceURL + relativeURI);
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   target.request().header("Authorization", "Basic " + base64Credentials);
   Response response = null;
   try
   {
      response = target.request().get();
      if ("/invisible".equals(relativeURI)) {
         if (response.getStatus() != 401) {
            throw new RuntimeException("End user can access the invisible resource");
         } else {
            return;
         }
      }
      if (HttpResponseCodes.SC_OK != response.getStatus()) {
         throw new RuntimeException("End user can not access its own resources");
     }
     System.out.println("End user resource : " + response.getEntity());
   }
   finally
   {
      response.close();
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:27,代码来源:EndUser.java


示例11: confirmAuthorization

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public String confirmAuthorization(String url) throws Exception
{
   WebTarget target = ClientBuilder.newClient().target(url);
   String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
   Invocation.Builder builder = target.request();
   builder.header("Authorization", "Basic " + base64Credentials);
   Response response = null;
   try {
      response = builder.post(null);
      if (302 != response.getStatus()) {
         throw new RuntimeException("Initiation failed");
      }
      // check that we got all tokens
      String callbackURI = response.getStringHeaders().getFirst("Location");
      if (callbackURI == null) {
          throw new RuntimeException("Callback failed");
      }
      return callbackURI;
   }
   finally {
      response.close();
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:24,代码来源:EndUser.java


示例12: getBasicAuthorizationCredentials

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public static String[] getBasicAuthorizationCredentials(HttpServletRequest request) {
    try {
        if (request != null) {
            String header = request.getHeader(HttpHeaders.AUTHORIZATION);
            String[] tokens = header.split("\\s+", 2);
            String decoded = new String(Base64.decode(tokens[1]));
            String[] credentials = decoded.split(":", 2);
            return credentials;
        } else {
            return null;
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, ex.getMessage(), ex);
        throw new RuntimeException(ex);
    }
}
 
开发者ID:hybridbpm,项目名称:hybridbpm,代码行数:17,代码来源:HybridbpmRestUtil.java


示例13: parseCredentials

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
private String parseCredentials()
  {	
  	String authHeader = _httpRequest.getHeader("Authorization");
  	if (null == authHeader) {
  		return "anonymous";
  	}

  	String encodedAuthInfo = authHeader.substring(basicAuthPrefix.length());
      String decodedAuthInfo;
try {
	decodedAuthInfo = new String(Base64.decode(encodedAuthInfo));
} catch (IOException e) {
          return null;
}
      
      int idx = decodedAuthInfo.indexOf(":");
      
      if (idx == -1) {
      	return null;
      }
      
      return decodedAuthInfo.substring(0, idx);
  }
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:24,代码来源:NdexService.java


示例14: postLogin

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
@POST
@Path("/authentication")
@Consumes("application/x-www-form-urlencoded")
@PermitAll
public Response postLogin(@FormParam("j_username") String username,@FormParam("j_password") String password) {
    Response.ResponseBuilder rb;

    Subject subject;
    try {
        subject = securityService.getSubject();
        if (!subject.isAuthenticated()) {
            UsernamePasswordToken token = new UsernamePasswordToken(username, password);
            subject.login(token);
            token.clear();
            String userPassword= username + ":" + password;
            String basicAuth = new String(Base64.encodeBytes(userPassword.getBytes()));
            Token cltToken = new Token();
            cltToken.setAccess_token("Basic "+basicAuth);
            cltToken.setExpires_in(1799);
            cltToken.setToken_type("bearer");
            cltToken.setScope("read write");
            rb = Response.ok(cltToken);
            return rb.build();

        } else {
            LOG.debug("User [" + subject.getPrincipal() + "] already authenticated.");
            if(subject.getPrincipal().toString().equals(username))
            {
                rb = Response.ok();
                return rb.build();
            }
        }
    } catch (Exception e) {
        LOG.debug("User failed to log.");
    }
    JSONObject JSONEntity = new JSONObject();
    JSONEntity.put("message","invalid user or password");
    return Response.status(Response.Status.BAD_REQUEST).entity(JSONEntity.toString()).build();

}
 
开发者ID:ffacon,项目名称:tapestry5-angular2-demo,代码行数:41,代码来源:UserService.java


示例15: aroundWriteTo

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException
{
   MessageDigest digest = null;
   try
   {
      digest = MessageDigest.getInstance("MD5");
   }
   catch (NoSuchAlgorithmException e)
   {
      throw new IllegalArgumentException(e);
   }
   ByteArrayOutputStream buffer = new ByteArrayOutputStream();
   DigestOutputStream digestStream = new DigestOutputStream(buffer, digest);
   OutputStream old = context.getOutputStream();
   context.setOutputStream(digestStream);

   try
   {
      context.proceed();

      byte[] hash = digest.digest();
      String encodedHash = Base64.encodeBytes(hash);
      context.getHeaders().putSingle("Content-MD5", encodedHash);

      byte[] content = buffer.toByteArray();
      old.write(content);
   }
   finally
   {
      context.setOutputStream(old);
   }
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:34,代码来源:ContentMD5Writer.java


示例16: confirmAuthorization

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public String confirmAuthorization(String url) throws Exception
   {
      WebTarget target = ClientBuilder.newClient().target(url);
      Invocation.Builder builder = target.request();
      String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
      builder.header("Authorization", "Basic " + base64Credentials);
      Response response = null;
      try {
         response = builder.post(null);
         if (302 != response.getStatus()) {
            throw new RuntimeException("Initiation failed");
        }
        // check that we got all tokens
        String callbackURI = response.getStringHeaders().getFirst("Location");
        if (callbackURI == null) {
            throw new RuntimeException("Callback failed");
        }
        return callbackURI;
      } finally {
         response.close();
      }
      
//      HttpClient client = new HttpClient();
//      PostMethod method = new PostMethod(url);
//      Base64 base64 = new Base64();
//      String base64Credentials = new String(base64.encode("admin:admin".getBytes()));
//      method.addRequestHeader(new Header("Authorization", "Basic " + base64Credentials));
//      
//      int status = client.executeMethod(method);
//      if (302 != status) {
//          throw new RuntimeException("Initiation failed");
//      }
//      // check that we got all tokens
//      String callbackURI = method.getResponseHeader("Location").getValue();
//      if (callbackURI == null) {
//          throw new RuntimeException("Callback failed");
//      }
//      return callbackURI;
   }
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:40,代码来源:EndUser.java


示例17: registerTrustedOpenIdRealms

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
public void registerTrustedOpenIdRealms() 
   throws Exception
{
  WebTarget target = ClientBuilder.newClient().target(OpenIdTrustedRealmsURL);
  Invocation.Builder builder = target.request();
  String base64Credentials = new String(Base64.encodeBytes("admin:admin".getBytes()));
  builder.header("Authorization", "Basic " + base64Credentials);
  Form form = new Form("xopenid.realm", OpenIdTrustedRealm);
  Response response = builder.post(Entity.form(form));
  response.close();
  if (HttpResponseCodes.SC_OK != response.getStatus()) {
     throw new RuntimeException("OpenId realms can not be registered");
  }     
}
 
开发者ID:resteasy,项目名称:resteasy-examples,代码行数:15,代码来源:Subscriber.java


示例18: run

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
@Override
public void run()
{
    logger.log(Level.FINER, "PullJSONWebServiceDataSource.InvocationTimerTask.run");

    String json = null;
    try
    {
        String        token = _username + ":" + _password;
        String        base64Token = Base64.encodeBytes(token.getBytes(StandardCharsets.UTF_8));
        ClientRequest request = new ClientRequest(_serviceURL);
        request.accept(MediaType.APPLICATION_JSON);
        request.header("Authorization", "Basic " + base64Token);

        ClientResponse<String> response = request.get(new GenericType<String>() {});

        if (response.getStatus() == HttpResponseCodes.SC_OK)
            json = response.getEntity();
        else
        {
            logger.log(Level.WARNING, "Problem in getting 'json' " + response.getStatus());
        }
    }
    catch (Throwable throwable)
    {
        logger.log(Level.WARNING, "Problems with web service invoke", throwable);
    }

    if (json != null)
        _dataProvider.produce(json);
}
 
开发者ID:arjuna-technologies,项目名称:WebService_DataBroker_PlugIn,代码行数:32,代码来源:PullJSONWebServiceDataSource.java


示例19: parseCredentials

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
/**************************************************************************
* Base64-decodes and parses the Authorization header to get the username
* and password.
* 
* @param requestContext
*            The servlet HTTP request context.
* @throws IOException
*            Decoding the Authorization header failed.
* @return a String array containing the username and password.
**************************************************************************/
public static String[] parseCredentials(ContainerRequestContext requestContext) throws IOException
{
    final MultivaluedMap<String, String> headers = requestContext.getHeaders();
    final List<String> authHeader = headers.get("Authorization");
    
    if (authHeader == null || authHeader.isEmpty())
        return null;

    final String encodedAuthInfo = authHeader.get(0).replaceFirst("Basic" + " ", "");
    final String decodedAuthInfo = new String(Base64.decode(encodedAuthInfo));
    
    return decodedAuthInfo.split(":");
}
 
开发者ID:ndexbio,项目名称:ndex-rest,代码行数:24,代码来源:Security.java


示例20: testBasicAuthentication

import org.jboss.resteasy.util.Base64; //导入依赖的package包/类
/**
 * Test method for
 * {@link org.jboss.dcp.api.rest.AuthenticationInterceptor#preProcess(org.jboss.resteasy.spi.HttpRequest, org.jboss.resteasy.core.ResourceMethod)}
 * .
 */
@Test
public void testBasicAuthentication() {
	AuthenticationInterceptor tested = getTested();

	HttpRequest requestMock = getHttpRequestMock();
	ResourceMethod methodMock = Mockito.mock(ResourceMethod.class);

	String uname = "uname";
	String pwd = "pwd";

	List<String> value = new ArrayList<String>();
	value.add("NTLM:sdfsdfkjskdfs");
	value.add("Basic:" + Base64.encodeBytes(uname.getBytes()));
	value.add("Basic:" + Base64.encodeBytes((uname + ":" + pwd).getBytes()));
	value.add("PPP:sdfsdfkjskdfs");
	Mockito.when(requestMock.getHttpHeaders().getRequestHeader("Authorization")).thenReturn(value);

	Mockito.when(tested.providerService.authenticate(uname, pwd)).thenReturn(true);

	ServerResponse res = tested.preProcess(requestMock, methodMock);
	Assert.assertNull(res);

	SecurityContext ctx = ResteasyProviderFactory.getContextData(SecurityContext.class);
	Assert.assertEquals(uname, ctx.getUserPrincipal().getName());
	Assert.assertEquals("BASIC", ctx.getAuthenticationScheme());
}
 
开发者ID:macanhhuy,项目名称:dcp-api,代码行数:32,代码来源:AuthenticationInterceptorTest.java



注:本文中的org.jboss.resteasy.util.Base64类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InMemoryLookupTable类代码示例发布时间:2022-05-23
下一篇:
Java ParserUtils类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap