Package javax.security.sasl

Examples of javax.security.sasl.SaslException


          }
          break;
        }
        case INITIATE: {
          if (saslMessage.getAuthsCount() != 1) {
            throw new SaslException("Client mechanism is malformed");
          }
          // verify the client requested an advertised authType
          SaslAuth clientSaslAuth = saslMessage.getAuths(0);
          if (!negotiateResponse.getAuthsList().contains(clientSaslAuth)) {
            if (sentNegotiate) {
              throw new AccessControlException(
                  clientSaslAuth.getMethod() + " authentication is not enabled."
                      + "  Available:" + enabledAuthMethods);
            }
            saslResponse = buildSaslNegotiateResponse();
            break;
          }
          authMethod = AuthMethod.valueOf(clientSaslAuth.getMethod());
          // abort SASL for SIMPLE auth, server has already ensured that
          // SIMPLE is a legit option above.  we will send no response
          if (authMethod == AuthMethod.SIMPLE) {
            switchToSimple();
            break;
          }
          // sasl server for tokens may already be instantiated
          if (saslServer == null || authMethod != AuthMethod.TOKEN) {
            saslServer = createSaslServer(authMethod);
          }
          // fallthru to process sasl token
        }
        case RESPONSE: {
          if (!saslMessage.hasToken()) {
            throw new SaslException("Client did not send a token");
          }
          byte[] saslToken = saslMessage.getToken().toByteArray();
          if (LOG.isDebugEnabled()) {
            LOG.debug("Have read input token of size " + saslToken.length
                + " for processing by saslServer.evaluateResponse()");
          }
          saslToken = saslServer.evaluateResponse(saslToken);
          saslResponse = buildSaslResponse(
              saslServer.isComplete() ? SaslState.SUCCESS : SaslState.CHALLENGE,
              saslToken);
          break;
        }
        default:
          throw new SaslException("Client sent unsupported state " + state);
      }
      return saslResponse;
    }
View Full Code Here


        {
            if (mechanisms[i].equals(MECHANISM))
            {
                if (cbh == null)
                {
                    throw new SaslException("CallbackHandler must not be null");
                }

                String[] mechs = {"CRAM-MD5"};
                return Sasl.createSaslClient(mechs, authorizationId, protocol, serverName, props, cbh);
            }
View Full Code Here

        this.authorizationID = authorizationID;
        this.authenticationID = (String) userInfo[0];
        this.password = (byte[]) userInfo[1];
        if (authenticationID == null || password == null)
        {
            throw new SaslException("PLAIN: authenticationID and password must be specified");
        }
    }
View Full Code Here

            response[size++] = SEPARATOR;
            System.arraycopy(password, 0, response, size, password.length);
            clearPassword();
            return response;
        } catch (UnsupportedEncodingException e) {
            throw new SaslException("PLAIN: Cannot get UTF-8 encoding of ids",
                    e);
        }
    }
View Full Code Here

            }
            return (new Object[] { userid, pwbytes });
        }
        catch (IOException e)
        {
            throw new SaslException("Cannot get password", e);
        }
        catch (UnsupportedCallbackException e)
        {
            throw new SaslException("Cannot get userid/password", e);
        }
    }
View Full Code Here

        {
            if (mechanisms[i].equals(MECHANISM))
            {
                if (cbh == null)
                {
                    throw new SaslException("CallbackHandler must not be null");
                }

                String[] mechs = {"CRAM-MD5"};
                return Sasl.createSaslClient(mechs, authorizationId, protocol, serverName, props, cbh);
            }
View Full Code Here

        try
        {
            int authzidNullPosition = findNullPosition(response, 0);
            if (authzidNullPosition < 0)
            {
                throw new SaslException("Invalid PLAIN encoding, authzid null terminator not found");
            }
            int authcidNullPosition = findNullPosition(response, authzidNullPosition + 1);
            if (authcidNullPosition < 0)
            {
                throw new SaslException("Invalid PLAIN encoding, authcid null terminator not found");
            }

            // we do not currently support authcid in any meaningful way
            // String authcid = new String(response, 0, authzidNullPosition, "utf8");
            String authzid = new String(response, authzidNullPosition + 1, authcidNullPosition - 1, "utf8");

            // we do not care about the prompt but it throws if null
            NameCallback nameCb = new NameCallback("prompt", authzid);
            PasswordCallback passwordCb = new PasswordCallback("prompt", false);
            // TODO: should not get pwd as a String but as a char array...
            int passwordLen = response.length - authcidNullPosition - 1;
            String pwd = new String(response, authcidNullPosition + 1, passwordLen, "utf8");
            AuthorizeCallback authzCb = new AuthorizeCallback(authzid, authzid);
            Callback[] callbacks = new Callback[]{nameCb, passwordCb, authzCb};
            _cbh.handle(callbacks);
            String storedPwd = new String(passwordCb.getPassword());
            if (storedPwd.equals(pwd))
            {
                _complete = true;
            }
            if (authzCb.isAuthorized() && _complete)
            {
                _authorizationId = authzCb.getAuthenticationID();
                return null;
            }
            else
            {
                throw new SaslException("Authentication failed");
            }
        }
        catch (IOException e)
        {
            throw new SaslException("Error processing data: " + e, e);
        }
        catch (UnsupportedCallbackException e)
        {
            throw new SaslException("Unable to obtain data from callback handler: " + e, e);
        }
    }
View Full Code Here

        return _authorizationId;
    }

    public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException
    {
        throw new SaslException("Unsupported operation");
    }
View Full Code Here

        throw new SaslException("Unsupported operation");
    }

    public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException
    {
        throw new SaslException("Unsupported operation");
    }
View Full Code Here

                _authorizationId = authzCb.getAuthenticationID();
                return null;
            }
            else
            {
                throw new SaslException("Authentication failed");
            }
        }
        catch (AMQFrameDecodingException e)
        {
            throw new SaslException("Unable to decode response: " + e, e);
        }
        catch (IOException e)
        {
            throw new SaslException("Error processing data: " + e, e);
        }
        catch (UnsupportedCallbackException e)
        {
            throw new SaslException("Unable to obtain data from callback handler: " + e, e);
        }
    }
View Full Code Here

TOP

Related Classes of javax.security.sasl.SaslException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.