当前位置: 首页>>代码示例>>Java>>正文


Java B64Code类代码示例

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


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

示例1: basicAuthentication

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
/**
 * Make a GET request with basic authentication specified
 *
 * @throws Exception
 */
@Test
public void basicAuthentication() throws Exception {
  final AtomicReference<String> user = new AtomicReference<String>();
  final AtomicReference<String> password = new AtomicReference<String>();
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      String auth = request.getHeader("Authorization");
      auth = auth.substring(auth.indexOf(' ') + 1);
      try {
        auth = B64Code.decode(auth, CHARSET_UTF8);
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
      int colon = auth.indexOf(':');
      user.set(auth.substring(0, colon));
      password.set(auth.substring(colon + 1));
      response.setStatus(HTTP_OK);
    }
  };
  assertTrue(get(url).basic("user", "p4ssw0rd").ok());
  assertEquals("user", user.get());
  assertEquals("p4ssw0rd", password.get());
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:31,代码来源:HttpRequestTest.java

示例2: getWeakETag

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
public String getWeakETag()
{
    try
    {
        StringBuilder b = new StringBuilder(32);
        b.append("W/\"");
        
        String name=getName();
        int length=name.length();
        long lhash=0;
        for (int i=0; i<length;i++)
            lhash=31*lhash+name.charAt(i);
        
        B64Code.encode(lastModified()^lhash,b);
        B64Code.encode(length()^lhash,b);
        b.append('"');
        return b.toString();
    } 
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
开发者ID:itead,项目名称:IoTgo_Android_App,代码行数:24,代码来源:Resource.java

示例3: HostedGraphiteSender

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
public HostedGraphiteSender(String apiKey) {

        source = Util.source();

        //  Create an https capable http client.
        SslContextFactory sslContextFactory = new SslContextFactory();
        httpClient = new HttpClient(sslContextFactory);

        HttpField agent = new HttpField("User-Agent", "app-server-metrics/" +
                (getClass().getPackage().getImplementationVersion() != null ? getClass().getPackage().getImplementationVersion() : "development"));

        httpClient.setUserAgentField(agent);

        try {
            httpClient.start();
        } catch (Exception e) {
            log.error(e);
        }

        this.authHeader = "Basic " + B64Code.encode(apiKey);
    }
 
开发者ID:GeoNet,项目名称:app-server-metrics,代码行数:22,代码来源:HostedGraphiteSender.java

示例4: basicAuthenticationLogin

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
private Optional<User> basicAuthenticationLogin() {
	String header = request.getHeader(HttpHeaders.AUTHORIZATION);
	if (header != null) {
		int space = header.indexOf(' ');
		if (space > 0) {
			String method = header.substring(0, space);
			if (PREFIX.equalsIgnoreCase(method)) {
				String decoded = B64Code.decode(header.substring(space + 1), StringUtil.__ISO_8859_1);
				int i = decoded.indexOf(':');
				if (i > 0) {
					String username = decoded.substring(0, i);
					String password = decoded.substring(i + 1);
					return userService.login(username, password);
				}
			}
		}
	}
	return Optional.empty();
}
 
开发者ID:Athou,项目名称:commafeed,代码行数:20,代码来源:SecurityCheckFactory.java

示例5: hashKey

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
public static String hashKey(String key)
{
    try
    {
        MessageDigest md = MessageDigest.getInstance("SHA1");
        md.update(key.getBytes("UTF-8"));
        md.update(MAGIC);
        return new String(B64Code.encode(md.digest()));
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
开发者ID:itead,项目名称:IoTgo_Android_App,代码行数:15,代码来源:WebSocketConnectionRFC6455.java

示例6: getUrl

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
/**
 * Simple logic to perform a authenticated GET request
 *
 * @param url
 * @param timeout
 * @return
 */
private String getUrl(String url, int timeout) {
    url += (url.contains("?") ? "&" : "?") + "timestamp=" + System.currentTimeMillis();
    startHttpClient(client);

    Request request = client.newRequest(url).timeout(TIMEOUT, TimeUnit.MILLISECONDS);

    AutelisConfiguration configuration = getConfig().as(AutelisConfiguration.class);
    String user = configuration.user;
    String password = configuration.password;

    String basicAuthentication = "Basic " + B64Code.encode(user + ":" + password, StringUtil.__ISO_8859_1);

    request.header(HttpHeader.AUTHORIZATION, basicAuthentication);

    try {
        ContentResponse response = request.send();
        int statusCode = response.getStatus();
        if (statusCode != HttpStatus.OK_200) {
            logger.debug("Method failed: {}", response.getStatus() + " " + response.getReason());
            return null;
        }
        return response.getContentAsString();
    } catch (Exception e) {
        logger.debug("Could not make http connection", e);
    }
    return null;
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:35,代码来源:AutelisHandler.java

示例7: setUp

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
/**
 * Set up server with handler
 *
 * @param handler
 * @return port
 * @throws Exception
 */
public static String setUp(final Handler handler) throws Exception {
  server = new Server();
  if (handler != null)
    server.setHandler(handler);
  Connector connector = new SelectChannelConnector();
  connector.setPort(0);
  server.setConnectors(new Connector[] { connector });
  server.start();

  proxy = new Server();
  Connector proxyConnector = new SelectChannelConnector();
  proxyConnector.setPort(0);
  proxy.setConnectors(new Connector[] { proxyConnector });

  ServletHandler proxyHandler = new ServletHandler();

  RequestHandler proxyCountingHandler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      proxyHitCount.incrementAndGet();
      String auth = request.getHeader("Proxy-Authorization");
      auth = auth.substring(auth.indexOf(' ') + 1);
      try {
        auth = B64Code.decode(auth, CHARSET_UTF8);
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
      int colon = auth.indexOf(':');
      proxyUser.set(auth.substring(0, colon));
      proxyPassword.set(auth.substring(colon + 1));
      request.setHandled(false);
    }
  };

  HandlerList handlerList = new HandlerList();
  handlerList.addHandler(proxyCountingHandler);
  handlerList.addHandler(proxyHandler);
  proxy.setHandler(handlerList);

  ServletHolder proxyHolder = proxyHandler.addServletWithMapping("org.eclipse.jetty.servlets.ProxyServlet", "/");
  proxyHolder.setAsyncSupported(true);

  proxy.start();

  proxyPort = proxyConnector.getLocalPort();

  return "http://localhost:" + connector.getLocalPort();
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:57,代码来源:ServerTestCase.java

示例8: login

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
@Override public UserIdentity login(String username, Object credentials) {
  String encodedAuthToken = (String) credentials;
  byte[] authToken = B64Code.decode(encodedAuthToken);

  GSSManager manager = GSSManager.getInstance();
  try {
    // http://java.sun.com/javase/6/docs/technotes/guides/security/jgss/jgss-features.html
    Oid spnegoOid = new Oid("1.3.6.1.5.5.2");
    Oid krb5Oid = new Oid("1.2.840.113554.1.2.2");
    GSSName gssName = manager.createName(serverPrincipal, null);
    // CALCITE-1922 Providing both OIDs is the bug in Jetty we're working around. By specifying
    // only one, we're requiring that clients *must* provide us the SPNEGO OID to authenticate
    // via Kerberos which is wrong. Best as I can tell, the SPNEGO OID is meant as another
    // layer of indirection (essentially is equivalent to setting the Kerberos OID).
    GSSCredential serverCreds = manager.createCredential(gssName,
        GSSCredential.INDEFINITE_LIFETIME, new Oid[] {krb5Oid, spnegoOid},
        GSSCredential.ACCEPT_ONLY);
    GSSContext gContext = manager.createContext(serverCreds);

    if (gContext == null) {
      LOG.debug("SpnegoUserRealm: failed to establish GSSContext");
    } else {
      while (!gContext.isEstablished()) {
        authToken = gContext.acceptSecContext(authToken, 0, authToken.length);
      }
      if (gContext.isEstablished()) {
        String clientName = gContext.getSrcName().toString();
        String role = clientName.substring(clientName.indexOf('@') + 1);

        LOG.debug("SpnegoUserRealm: established a security context");
        LOG.debug("Client Principal is: {}", gContext.getSrcName());
        LOG.debug("Server Principal is: {}", gContext.getTargName());
        LOG.debug("Client Default Role: {}", role);

        SpnegoUserPrincipal user = new SpnegoUserPrincipal(clientName, authToken);

        Subject subject = new Subject();
        subject.getPrincipals().add(user);

        return _identityService.newUserIdentity(subject, user, new String[]{role});
      }
    }
  } catch (GSSException gsse) {
    LOG.warn("Caught GSSException trying to authenticate the client", gsse);
  }

  return null;
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:49,代码来源:PropertyBasedSpnegoLoginService.java

示例9: validateRequest

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
/**
 * @see org.eclipse.jetty.security.Authenticator#validateRequest(javax.servlet.ServletRequest, javax.servlet.ServletResponse, boolean)
 */
@Override
public Authentication validateRequest(ServletRequest req, ServletResponse res, boolean mandatory) throws ServerAuthException {
  HttpServletRequest request = (HttpServletRequest) req;
  HttpServletResponse response = (HttpServletResponse) res;
  String credentials = request.getHeader(HttpHeader.PROXY_AUTHORIZATION.asString());

  try {
    if (!mandatory)
      return new DeferredAuthentication(this);

    if (credentials != null) {
      int space = credentials.indexOf(' ');
      if (space > 0) {
        String method = credentials.substring(0, space);
        if ("basic".equalsIgnoreCase(method)) {
          credentials = credentials.substring(space + 1);
          credentials = B64Code.decode(credentials, StandardCharsets.ISO_8859_1);
          int i = credentials.indexOf(':');
          if (i > 0) {
            String username = credentials.substring(0, i);
            String password = credentials.substring(i + 1);

            UserIdentity user = login(username, password, request);
            if (user != null) {
              return new UserAuthentication(getAuthMethod(), user);
            }
          }
        }
      }
    }

    if (DeferredAuthentication.isDeferred(response))
      return Authentication.UNAUTHENTICATED;

    response.setHeader(HttpHeader.PROXY_AUTHENTICATE.asString(), "basic realm=\"" + _loginService.getName() + '"');
    response.sendError(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED);
    return Authentication.SEND_CONTINUE;
  } catch (IOException e) {
    throw new ServerAuthException(e);
  }
}
 
开发者ID:SonarSource,项目名称:sonar-scanner-maven,代码行数:45,代码来源:ProxyAuthenticator.java

示例10: spnegoLogin

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
private UserIdentity spnegoLogin(Object credentials) {

    String encodedAuthToken = (String) credentials;
    byte[] authToken = B64Code.decode(encodedAuthToken);
    GSSManager manager = GSSManager.getInstance();

    try {
      // Providing both OID's is required here. If we provide only one,
      // we're requiring that clients provide us the SPNEGO OID to authenticate via Kerberos.
      Oid[] knownOids = new Oid[2];
      knownOids[0] = new Oid("1.3.6.1.5.5.2"); // spnego
      knownOids[1] = new Oid("1.2.840.113554.1.2.2"); // kerberos

      GSSName gssName = manager.createName(spnegoConfig.getSpnegoPrincipal(), null);
      GSSCredential serverCreds = manager.createCredential(gssName, GSSCredential.INDEFINITE_LIFETIME,
          knownOids, GSSCredential.ACCEPT_ONLY);
      GSSContext gContext = manager.createContext(serverCreds);

      if (gContext == null) {
        logger.debug("SPNEGOUserRealm: failed to establish GSSContext");
      } else {
        while (!gContext.isEstablished()) {
          authToken = gContext.acceptSecContext(authToken, 0, authToken.length);
        }

        if (gContext.isEstablished()) {
          String clientName = gContext.getSrcName().toString();
          String role = clientName.substring(clientName.indexOf(64) + 1);

          final SystemOptionManager sysOptions = drillContext.getOptionManager();
          final boolean isAdmin = ImpersonationUtil.hasAdminPrivileges(role,
              ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(sysOptions),
              ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(sysOptions));

          final Principal user = new DrillUserPrincipal(clientName, isAdmin);
          final Subject subject = new Subject();
          subject.getPrincipals().add(user);

          if (isAdmin) {
            return this._identityService.newUserIdentity(subject, user, DrillUserPrincipal.ADMIN_USER_ROLES);
          } else {
            return this._identityService.newUserIdentity(subject, user, DrillUserPrincipal.NON_ADMIN_USER_ROLES);
          }
        }
      }
    } catch (GSSException gsse) {
      logger.warn("Caught GSSException trying to authenticate the client", gsse);
    }
    return null;
  }
 
开发者ID:axbaretto,项目名称:drill,代码行数:51,代码来源:DrillSpnegoLoginService.java

示例11: setupServer

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
@BeforeClass
    public static void setupServer() throws Exception {
        // start a local HTTP proxy using Jetty server
        server = new Server();

/*
        final SSLContextParameters contextParameters = new SSLContextParameters();
        final SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setSslContext(contextParameters.createSSLContext());
        ServerConnector connector = new ServerConnector(server, sslContextFactory);
*/
        ServerConnector connector = new ServerConnector(server);

        connector.setHost(HTTP_PROXY_HOST);
        server.addConnector(connector);

        final String authenticationString = "Basic "
            + B64Code.encode(HTTP_PROXY_USER_NAME + ":" + HTTP_PROXY_PASSWORD, StringUtil.__ISO_8859_1);

        ConnectHandler connectHandler = new ConnectHandler() {
            @Override
            protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) {
                // validate proxy-authentication header
                final String header = request.getHeader(PROXY_AUTHORIZATION.toString());
                if (!authenticationString.equals(header)) {
                    LOG.warn("Missing header " + PROXY_AUTHORIZATION);
                    // ask for authentication header
                    response.setHeader(PROXY_AUTHENTICATE.toString(), String.format("Basic realm=\"%s\"", HTTP_PROXY_REALM));
                    return false;
                }
                LOG.info("Request contains required header " + PROXY_AUTHORIZATION);
                return true;
            }
        };
        server.setHandler(connectHandler);

        LOG.info("Starting proxy server...");
        server.start();

        httpProxyPort = connector.getLocalPort();
        LOG.info("Started proxy server on port {}", httpProxyPort);
    }
 
开发者ID:HydAu,项目名称:Camel,代码行数:43,代码来源:HttpProxyMojoIntegrationTest.java

示例12: toBasicAuth

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
public String toBasicAuth() {
  return "Basic " + B64Code.encode(_user + ":" + _password);
}
 
开发者ID:h2oai,项目名称:h2o-3,代码行数:4,代码来源:JettyProxy.java

示例13: getUsernameAndPassEncoded

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
protected static String getUsernameAndPassEncoded() {
    return "Basic " + B64Code.encode("cash1981" + ":" + "foo", StringUtil.__ISO_8859_1);
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:4,代码来源:AbstractCivilizationTest.java

示例14: getAdminEncoded

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
protected static String getAdminEncoded() {
    return "Basic " + B64Code.encode("admin" + ":" + "foo", StringUtil.__ISO_8859_1);
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:4,代码来源:AbstractCivilizationTest.java

示例15: getItchiEncoded

import org.eclipse.jetty.util.B64Code; //导入依赖的package包/类
protected static String getItchiEncoded() {
    return "Basic " + B64Code.encode("Itchi" + ":" + "foo", StringUtil.__ISO_8859_1);
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:4,代码来源:AbstractCivilizationTest.java


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