Package javax.security.sasl

Examples of javax.security.sasl.AuthorizeCallback


    /** {@inheritDoc} */
    @Override
    public void handle(Callback[] callbacks) throws
        UnsupportedCallbackException {
      AuthorizeCallback ac = null;
      for (Callback callback : callbacks) {
        if (callback instanceof AuthorizeCallback) {
          ac = (AuthorizeCallback) callback;
        } else {
          throw new UnsupportedCallbackException(callback,
              "Unrecognized SASL GSSAPI Callback");
        }
      }
      if (ac != null) {
        String authid = ac.getAuthenticationID();
        String authzid = ac.getAuthorizationID();
        if (authid.equals(authzid)) {
          ac.setAuthorized(true);
        } else {
          ac.setAuthorized(false);
        }
        if (ac.isAuthorized()) {
          if (LOG.isDebugEnabled())
            LOG.debug("SASL server GSSAPI callback: setting "
                + "canonicalized client ID: " + authzid);
          ac.setAuthorizedID(authzid);
        }
      }
    }
View Full Code Here


      @Override
      public void handle(Callback[] callbacks) throws InvalidToken,
      UnsupportedCallbackException {
        NameCallback nc = null;
        PasswordCallback pc = null;
        AuthorizeCallback ac = null;
        for (Callback callback : callbacks) {
          if (callback instanceof AuthorizeCallback) {
            ac = (AuthorizeCallback) callback;
          } else if (callback instanceof NameCallback) {
            nc = (NameCallback) callback;
          } else if (callback instanceof PasswordCallback) {
            pc = (PasswordCallback) callback;
          } else if (callback instanceof RealmCallback) {
            continue; // realm is ignored
          } else {
            throw new UnsupportedCallbackException(callback,
            "Unrecognized SASL DIGEST-MD5 Callback");
          }
        }
        if (pc != null) {
          DelegationTokenIdentifier tokenIdentifier = SaslRpcServer.
          getIdentifier(nc.getDefaultName(), secretManager);
          char[] password = getPassword(tokenIdentifier);

          if (LOG.isDebugEnabled()) {
            LOG.debug("SASL server DIGEST-MD5 callback: setting password "
                + "for client: " + tokenIdentifier.getUser());
          }
          pc.setPassword(password);
        }
        if (ac != null) {
          String authid = ac.getAuthenticationID();
          String authzid = ac.getAuthorizationID();
          if (authid.equals(authzid)) {
            ac.setAuthorized(true);
          } else {
            ac.setAuthorized(false);
          }
          if (ac.isAuthorized()) {
            if (LOG.isDebugEnabled()) {
              String username =
                SaslRpcServer.getIdentifier(authzid, secretManager).getUser().getUserName();
              LOG.debug("SASL server DIGEST-MD5 callback: setting "
                  + "canonicalized client ID: " + username);
            }
            ac.setAuthorizedID(authzid);
          }
        }
      }
View Full Code Here

                final String password = new String(server.getAuthKey(), UTF_8);

                // Second Pass - Now iterate the Callback(s) requiring a response.
                for (Callback current : toRespondTo) {
                    if (current instanceof AuthorizeCallback) {
                        AuthorizeCallback authorizeCallback = (AuthorizeCallback) current;
                        // Don't support impersonating another identity
                        authorizeCallback.setAuthorized(authorizeCallback.getAuthenticationID().equals(authorizeCallback.getAuthorizationID()));
                    } else if (current instanceof PasswordCallback) {
                        ((PasswordCallback) current).setPassword(password.toCharArray());
                    } else if (current instanceof VerifyPasswordCallback) {
                        VerifyPasswordCallback vpc = (VerifyPasswordCallback) current;
                        vpc.setVerified(password.equals(vpc.getPassword()));
View Full Code Here

                // Second Pass - Now iterate the Callback(s) requiring a response.
                for (Callback current : toRespondTo) {
                    if (current instanceof AuthorizeCallback) {

                        AuthorizeCallback authorizeCallback = (AuthorizeCallback) current;
                        // Don't support impersonating another identity
                        authorizeCallback.setAuthorized(authorizeCallback.getAuthenticationID().equals(authorizeCallback.getAuthorizationID()));
                    } else if (current instanceof PasswordCallback) {
                        String password = new String(server.getAuthKey());
                        ((PasswordCallback) current).setPassword(password.toCharArray());
                    }
                }
View Full Code Here

      saslFactory.addServerDefinition("GSSAPI", name, host, saslProperties,
        new SaslGssCallbackHandler() {
          @Override
          public void handle(Callback[] callbacks)
              throws UnsupportedCallbackException {
            AuthorizeCallback ac = null;
            for (Callback callback : callbacks) {
              if (callback instanceof AuthorizeCallback) {
                ac = (AuthorizeCallback) callback;
              } else {
                throw new UnsupportedCallbackException(callback,
                    "Unrecognized SASL GSSAPI Callback");
              }
            }
            if (ac != null) {
              String authid = ac.getAuthenticationID();
              String authzid = ac.getAuthorizationID();
              if (!authid.equals(authzid)) {
                ac.setAuthorized(false);
              } else {
                ac.setAuthorized(true);
                String userName = SecurityUtil.getUserFromPrincipal(authzid);
                log.info("Effective user: " + userName);
                ac.setAuthorizedID(userName);
              }
            }
          }
        });
      return saslFactory;
View Full Code Here

      saslFactory.addServerDefinition("GSSAPI", name, host, saslProperties,
        new SaslGssCallbackHandler() {
          @Override
          public void handle(Callback[] callbacks)
              throws UnsupportedCallbackException {
            AuthorizeCallback ac = null;
            for (Callback callback : callbacks) {
              if (callback instanceof AuthorizeCallback) {
                ac = (AuthorizeCallback) callback;
              } else {
                throw new UnsupportedCallbackException(callback,
                    "Unrecognized SASL GSSAPI Callback");
              }
            }
            if (ac != null) {
              String authid = ac.getAuthenticationID();
              String authzid = ac.getAuthorizationID();
              if (!authid.equals(authzid)) {
                ac.setAuthorized(false);
              } else {
                ac.setAuthorized(true);
                String userName = SecurityUtil.getUserFromPrincipal(authzid);
                LOG.info("Effective user: " + userName);
                ac.setAuthorizedID(userName);
              }
            }
          }
        });
      transportFactory = saslFactory;
View Full Code Here

                    passwordCB.setPassword( strPassword.toCharArray() );
                }
            }
            else if ( callback instanceof AuthorizeCallback )
            {
                AuthorizeCallback authorizeCB = ( AuthorizeCallback ) callback;

                // hnelson (CRAM-MD5, DIGEST-MD5)
                // hnelson@EXAMPLE.COM (GSSAPI)
                LOG.debug( "AuthorizeCallback authnID:  {}", authorizeCB.getAuthenticationID() );

                // hnelson (CRAM-MD5, DIGEST-MD5)
                // hnelson@EXAMPLE.COM (GSSAPI)
                LOG.debug( "AuthorizeCallback authzID:  {}", authorizeCB.getAuthorizationID() );

                // null (CRAM-MD5, DIGEST-MD5, GSSAPI)
                LOG.debug( "AuthorizeCallback authorizedID:  {}", authorizeCB.getAuthorizedID() );

                // false (CRAM-MD5, DIGEST-MD5, GSSAPI)
                LOG.debug( "AuthorizeCallback isAuthorized:  {}", authorizeCB.isAuthorized() );

                try
                {
                    authorize( authorizeCB );
                }
View Full Code Here

    /**
     * Test for <code>AuthorizeCallback(String authnID, String authzID)</code>
     * and get/set methods
     */
    public void test01() {
        AuthorizeCallback auth = new AuthorizeCallback(null, null);
        assertNull(auth.getAuthenticationID());
        assertNull(auth.getAuthorizationID());
        assertNull(auth.getAuthorizedID());
        assertFalse(auth.isAuthorized());

        auth.setAuthorized(true);
        assertTrue(auth.isAuthorized());
        assertNull(auth.getAuthorizedID());

        auth.setAuthorized(false);
        assertNull(auth.getAuthorizedID());
        assertFalse(auth.isAuthorized());

        auth.setAuthorizedID("ZZZ");
        auth.setAuthorized(true);
        assertEquals(auth.getAuthorizedID(), "ZZZ");
        assertNull(auth.getAuthorizationID());
        assertTrue(auth.isAuthorized());
    }
View Full Code Here

                "Long String LongString Long String LongString Long String LongString Long String LongString Long String LongString Long String LongString" };
        String[] newAuthorizedIDs = {
                "new authorizedIDs",
                "another authorizedIDs",
                "some long string for authorized IDs some long string for authorized IDs some long string for authorized IDs" };
        AuthorizeCallback auth;
        for (int i = 0; i < authenticationIDs.length; i++) {
            for (int j = 0; j < authorizedIDs.length; j++) {
                auth = new AuthorizeCallback(authenticationIDs[i],
                        authorizedIDs[j]);
                assertEquals(auth.getAuthenticationID(), authenticationIDs[i]);
                assertEquals(auth.getAuthorizationID(), authorizedIDs[j]);
                assertNull(auth.getAuthorizedID());
                assertFalse(auth.isAuthorized());

                auth.setAuthorized(true);
                assertTrue(auth.isAuthorized());
                assertEquals(auth.getAuthorizedID(), auth.getAuthorizationID());

                auth.setAuthorized(false);
                assertNull(auth.getAuthorizedID());
                assertFalse(auth.isAuthorized());

                for (int l = 0; l < newAuthorizedIDs.length; l++) {
                    auth.setAuthorizedID(newAuthorizedIDs[l]);
                    assertNull(auth.getAuthorizedID());
                    auth.setAuthorized(true);
                    assertFalse(auth.getAuthorizedID().equals(
                            auth.getAuthorizationID()));
                    assertEquals(auth.getAuthorizedID(), newAuthorizedIDs[l]);
                    auth.setAuthorizedID(newAuthorizedIDs[l] + " ZZZ");
                    assertFalse(auth.getAuthorizedID().equals(
                            auth.getAuthorizationID()));
                    assertFalse(auth.getAuthorizedID().equals(
                            newAuthorizedIDs[l]));
                    assertEquals(auth.getAuthorizedID(), newAuthorizedIDs[l]
                            + " ZZZ");

                    auth.setAuthorized(false);
                }

            }
        }
    }
View Full Code Here

            "Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID. Long stringID." };

    @Override
    protected Object[] getData() {
        String msg = null;
        return new Object[] { new AuthorizeCallback(msg, msg),
                new AuthorizeCallback("", null),
                new AuthorizeCallback(null, msgs[0]),
                new AuthorizeCallback(msgs[1], msgs[1]), };
    }
View Full Code Here

TOP

Related Classes of javax.security.sasl.AuthorizeCallback

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.