Package javax.security.auth.login

Examples of javax.security.auth.login.LoginContext


                    (PasswordValidationCallback.PlainTextPasswordRequest) request;

            final String username = plainTextRequest.getUsername();
            final String password = plainTextRequest.getPassword();

            LoginContext loginContext;
            try {
                loginContext = new LoginContext(getLoginContextName(), new AbstractCallbackHandler() {

                    @Override
                    protected void handleInternal(Callback callback) throws UnsupportedCallbackException {
                        if (callback instanceof NameCallback) {
                            ((NameCallback) callback).setName(username);
                        }
                        else if (callback instanceof PasswordCallback) {
                            ((PasswordCallback) callback).setPassword(password.toCharArray());
                        }
                        else {
                            throw new UnsupportedCallbackException(callback);
                        }
                    }
                });
            }
            catch (LoginException ex) {
                throw new PasswordValidationCallback.PasswordValidationException(ex);
            }
            catch (SecurityException ex) {
                throw new PasswordValidationCallback.PasswordValidationException(ex);
            }

            try {
                loginContext.login();
                Subject subject = loginContext.getSubject();
                if (!subject.getPrincipals().isEmpty()) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Authentication request for user '" + username + "' successful");
                    }
                    return true;
View Full Code Here


        @Override
        public boolean validate(X509Certificate certificate)
                throws CertificateValidationCallback.CertificateValidationException {
            Subject subject = new Subject();
            subject.getPrincipals().add(certificate.getSubjectX500Principal());
            LoginContext loginContext;
            try {
                loginContext = new LoginContext(getLoginContextName(), subject);
            }
            catch (LoginException ex) {
                throw new CertificateValidationCallback.CertificateValidationException(ex);
            }
            catch (SecurityException ex) {
                throw new CertificateValidationCallback.CertificateValidationException(ex);
            }

            try {
                loginContext.login();
                Subject subj = loginContext.getSubject();
                if (!subj.getPrincipals().isEmpty()) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Authentication request for certificate with DN [" +
                                certificate.getSubjectX500Principal().getName() + "] successful");
                    }
View Full Code Here

        PrintWriter pw = resp.getWriter();
        CallbackHandler handler = new ServletRequestCallbackHandler(req);
        Subject subject = new Subject();
        try
        {
            LoginContext lc = loginContextFactory.createLoginContext("sample",subject,handler);
            lc.login();

            pw.println("Principal authentication successful");
            pw.println(subject);
        }
        catch (LoginException e)
View Full Code Here

        Subject subject = new Subject();
        final ClassLoader cl = Thread.currentThread().getContextClassLoader();
        try
        {
            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
            LoginContext lc = new LoginContext("sample", subject, handler);
            lc.login();

            pw.println("Principal authentication successful");
            pw.println(subject);
        }
        catch (LoginException e)
View Full Code Here

        try
        {
            Configuration config = Configuration.getInstance("JavaLoginConfig", null,
                "FelixJaasProvider");
            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
            LoginContext lc = new LoginContext("sample", subject, handler, config);
            lc.login();

            pw.println("Principal authentication successful");
            pw.println(subject);
        }
        catch (NoSuchAlgorithmException e)
View Full Code Here

        CallbackHandler handler = new ServletRequestCallbackHandler(req);

        Subject subject = new Subject();
        try
        {
            LoginContext lc = new LoginContext("sample", subject, handler);
            lc.login();

            pw.println("Principal authentication successful");
            pw.println(subject);
        }
        catch (LoginException e)
View Full Code Here

            log.error("JAAS authentication failed", e);
        }
    }

    protected LoginContext getLoginContext() throws LoginException {
        return new LoginContext(getJaasConfigName(), subject,
                createCallbackHandler());
    }
View Full Code Here

    /**
     * Perform the tests of this quick start using the ClientLoginModule and LoginContext API to set the desired Principal.
     */
    private static void performTestingClientLoginModule(final String user, final SecuredEJBRemote secured,
        final IntermediateEJBRemote intermediate) throws Exception {
        LoginContext loginContext = null;
        try {
            if (user != null) {
                loginContext = getCLMLoginContext(user, "");
                loginContext.login();
            }

            System.out.println("-------------------------------------------------");
            System.out
                .println(String.format("* * About to perform test as %s * *\n\n", user == null ? "ConnectionUser" : user));

            makeCalls(secured, intermediate);
        } finally {
            if (loginContext != null) {
                loginContext.logout();
            }
            System.out.println("* * Test Complete * * \n\n");
            System.out.println("-------------------------------------------------");
        }
    }
View Full Code Here

                return new AppConfigurationEntry[] { clmEntry };
            }
        };

        return new LoginContext(configurationName, new Subject(), cbh, config);
    }
View Full Code Here

        }

        final JGDIShell shell = new JGDIShell();

        if (useCsp) {
            LoginContext lc = null;
            String jaasContextName = "jgdi";
            logger.config("setup jaas login context for jgdi");
            final String finalUrl = url;

            try {
                lc = new LoginContext(jaasContextName, new MyCallbackHandler());

                lc.login();
                try {
                    Subject.doAs(lc.getSubject(), new PrivilegedAction() {

                        public Object run() {
                            shell.exec(finalUrl);
                            return null;
                        }
                    });
                } finally {
                    lc.logout();
                }
            } catch (LoginException ex) {
                ex.printStackTrace();
            }
        } else {
View Full Code Here

TOP

Related Classes of javax.security.auth.login.LoginContext

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.