Package javax.security.auth.callback

Examples of javax.security.auth.callback.CallbackHandler


        // 1. Manage the thread's context classloader
        // 2. Add a DynamicImport for org.apache.felix.jaas.boot
        // 3. Fetch the config using the Configuration.getInstance API and pass that on

        PrintWriter pw = resp.getWriter();
        CallbackHandler handler = new ServletRequestCallbackHandler(req);

        Subject subject = new Subject();
        final ClassLoader cl = Thread.currentThread().getContextClassLoader();
        try
        {
View Full Code Here


        //
        //In that case client code does not have to
        //manage Thread Context Classloader or provide explicit configuration

        PrintWriter pw = resp.getWriter();
        CallbackHandler handler = new ServletRequestCallbackHandler(req);

        Subject subject = new Subject();
        try
        {
            LoginContext lc = new LoginContext("sample", subject, handler);
View Full Code Here

    /**
     * Creates a callback handler that can handle a standard username/password
     * callback, using the credentials username and password properties
     */
    public CallbackHandler createCallbackHandler() {
        return new CallbackHandler() {
            public void handle(Callback[] callbacks)
                    throws IOException, UnsupportedCallbackException {
                for (int i = 0; i < callbacks.length; i++) {
                    if (callbacks[i] instanceof NameCallback) {
                        ((NameCallback) callbacks[i]).setName(credentials.getUsername());
View Full Code Here

    }

    public static LoginContext getCLMLoginContext(final String username, final String password) throws LoginException {
        final String configurationName = "Testing";

        CallbackHandler cbh = new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                for (Callback current : callbacks) {
                    if (current instanceof NameCallback) {
                        ((NameCallback) current).setName(username);
                    } else if (current instanceof PasswordCallback) {
View Full Code Here

    * Creates a callback handler that can handle a standard username/password
    * callback, using the username and password properties.
    */
   public CallbackHandler createCallbackHandler()
   {
      return new CallbackHandler()
      {
         public void handle(Callback[] callbacks)
            throws IOException, UnsupportedCallbackException
         {
            for (int i=0; i < callbacks.length; i++)
View Full Code Here

        // TODO - Once authorization is in place we may be able to relax the realm check to
        //        allow anonymous along side fully authenticated connections.

        // If the mechanism is ANONYMOUS and we don't have a realm we return quickly.
        if (ANONYMOUS.equals(mechanismName) && realm == null) {
            return new CallbackHandler() {

                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    for (Callback current : callbacks) {
                        throw new UnsupportedCallbackException(current, "ANONYMOUS mechanism so not expecting a callback");
                    }
                }
            };
        }

        // For now for the JBOSS_LOCAL_USER we are only supporting the $local user and not allowing for
        // an alternative authorizationID.
        if (JBOSS_LOCAL_USER.equals(mechanismName)) {
            return new CallbackHandler() {

                @Override
                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    for (Callback current : callbacks) {
                        if (current instanceof NameCallback) {
                            NameCallback ncb = (NameCallback) current;
                            if (DOLLAR_LOCAL.equals(ncb.getDefaultName()) == false) {
                                throw new SaslException("Only " + DOLLAR_LOCAL + " user is acceptable.");
                            }
                        } else if (current instanceof AuthorizeCallback) {
                            AuthorizeCallback acb = (AuthorizeCallback) current;
                            acb.setAuthorized(acb.getAuthenticationID().equals(acb.getAuthorizationID()));
                        } else {
                            throw new UnsupportedCallbackException(current);
                        }
                    }

                }
            };
        }

        // In this calls only the AuthorizeCallback is needed, we are not making use if an authorization ID just yet
        // so don't need to be linked back to the realms.
        if (EXTERNAL.equals(mechanismName)) {
            return new CallbackHandler() {

                @Override
                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    for (Callback current : callbacks) {
                        if (current instanceof AuthorizeCallback) {
                            AuthorizeCallback acb = (AuthorizeCallback) current;
                            acb.setAuthorized(acb.getAuthenticationID().equals(acb.getAuthorizationID()));
                        } else {
                            throw new UnsupportedCallbackException(current);
                        }
                    }

                }
            };
        }

        final CallbackHandler realmCallbackHandler; // Referenced later by an inner-class so needs to be final.

        // We must have a match in this block or throw an IllegalStateException.
        if (DIGEST_MD5.equals(mechanismName) && digestMd5Supported() ||
                PLAIN.equals(mechanismName) && plainSupported()) {
            realmCallbackHandler = realm.getCallbackHandler();
        } else {
            return null;
        }

        // If there is not serverCallbackHandler then we don't need to wrap it so we can just return the realm
        // name fix handler which is already wrapping the real handler.
        if (serverCallbackHandler == null) {
            return realmCallbackHandler;
        }

        return new CallbackHandler() {
            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                serverCallbackHandler.handle(callbacks);
                if (handled(callbacks) == false) {
                    realmCallbackHandler.handle(callbacks);
                }
            }

            /*
            * Check if the PasswordCallback had already been handled.
View Full Code Here

            final CallbackHandler callerSuppliedCallbackHandler,
            final boolean isTextAuth) throws BootException, BootException, URISyntaxException, ClassNotFoundException, InstantiationException, IllegalAccessException, InjectionException, IOException, SAXParseException {
        AppClientContainer container = ACCModulesManager.getService(AppClientContainer.class);
        container.setClient(client);
        container.setBuilder(this);
        CallbackHandler callbackHandler =
                (callerSuppliedCallbackHandler != null ?
                    callerSuppliedCallbackHandler : getCallbackHandlerFromDescriptor(client.getDescriptor(classLoader).getCallbackHandler()));
        container.prepareSecurity(targetServers, messageSecurityConfigs, containerProperties,
                clientCredential, callbackHandler, classLoader, isTextAuth);
        return container;
View Full Code Here

            char [] pw = null;
            switch(type) {
                case TYPE_USER:
                case TYPE_SGE_DAEMON:   
                    if(pwFile == null) {
                        CallbackHandler cbh = new TextCallbackHandler();
                       
                        PasswordCallback keystorePWCallback = new PasswordCallback("keystore password: ", false);
                       
                        Callback [] cb = new Callback [] {
                            keystorePWCallback,
                        };
                       
                        cbh.handle(cb);
                        pw = keystorePWCallback.getPassword();
                        if(pw == null) {
                            pw = new char[0];
                        }
                    } else {
View Full Code Here

    public static final String DIGEST = "DIGEST-MD5";
    private static final Logger LOG = LoggerFactory.getLogger(DigestSaslTransportPlugin.class);

    protected TTransportFactory getServerTransportFactory() throws IOException {       
        //create an authentication callback handler
        CallbackHandler serer_callback_handler = new ServerCallbackHandler(login_conf);

        //create a transport factory that will invoke our auth callback for digest
        TSaslServerTransport.Factory factory = new TSaslServerTransport.Factory();
        factory.addServerDefinition(DIGEST, AuthUtils.SERVICE, "localhost", null, serer_callback_handler);
View Full Code Here

        if ( ss == null )
        {
            CoreSession adminSession = ldapSession.getLdapServer().getDirectoryService().getAdminSession();

            CallbackHandler callbackHandler = new DigestMd5CallbackHandler( ldapSession, adminSession, bindRequest );

            ss = Sasl.createSaslServer(
                SupportedSaslMechanisms.DIGEST_MD5,
                SaslConstants.LDAP_PROTOCOL,
                ( String ) ldapSession.getSaslProperty( SaslConstants.SASL_HOST ),
View Full Code Here

TOP

Related Classes of javax.security.auth.callback.CallbackHandler

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.