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


Java B64Code.decode方法代码示例

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


在下文中一共展示了B64Code.decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: login

import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
/**
 * Login a user using GSSAPI through SPNEGO or KRB5 mechs.
 *
 * @param username will not be used, credentials contains all that's necessary.
 * @param credentials a auth token String. Expect ClassCastException for anything else.
 * @return a UserIdentity if we succeed or null if we don't.
 */
public UserIdentity login(String username, Object credentials) {
  byte[] authToken = B64Code.decode((String)credentials);
  //Just to make sure no other api's have changed this setting such as Apache LDAP API version 1.0.0-M24 in
  //LdapNetworkConnection.java on line 1558.
  //If set to true GSSAPI negotiation fails in HTTP accept.
  System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

  try {
    GSSContext gssContext = setupContext();

    if (gssContext == null) {
      throw new IllegalStateException("GSS: Failed to establish GSSContext");
    }

    while (!gssContext.isEstablished()) {
      authToken = gssContext.acceptSecContext(authToken,0,authToken.length);
    }

    GSSName srcName = gssContext.getSrcName();
    String clientName = srcName.toString();
    String role = clientName.substring(clientName.indexOf('@') + 1);

    LOG.debug("GSS: Established a security context");
    LOG.debug("GSS: Client Principal is: " + srcName);
    LOG.debug("GSS: Server Principal is: " + gssContext.getTargName());
    LOG.debug("GSS: Client Default Role: " + role);

    SpnegoUserPrincipal user = new SpnegoUserPrincipal(clientName, authToken);
    Subject subject = new Subject();
    subject.getPrincipals().add(user);

    return service.newUserIdentity(subject, user, new String[]{role});
  } catch (GSSException gsse) {
    // Can't throw exception forward due to interface implementation
    LOG.info("GSS: Failed while validating credentials: " + gsse.getMessage());
    LOG.debug("", gsse);
  }

  return null;
}
 
开发者ID:stockholmuniversity,项目名称:cxf-server,代码行数:48,代码来源:SpnegoAndKrb5LoginService.java


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