Package javax.security.auth.login

Examples of javax.security.auth.login.FailedLoginException


        username = ((NameCallback) callbacks[0]).getName();
        if (username == null || username.equals("")) {
            // Clear out the private state
            username = null;
            password = null;
            throw new FailedLoginException();
        }
        String realPassword = users.getProperty(username);
        if (realPassword == null || realPassword.equals("")) {
            // Clear out the private state
            username = null;
            password = null;
            throw new FailedLoginException();
        } else {
            // Decrypt the password if needed, so we can compare it with the supplied one
            realPassword = (String) EncryptionManager.decrypt(realPassword);
        }
        char[] entered = ((PasswordCallback) callbacks[1]).getPassword();
        password = entered == null ? null : new String(entered);
        if (!checkPassword(realPassword, password)) {
            // Clear out the private state
            username = null;
            password = null;
            throw new FailedLoginException();
        }

        loginSucceeded = true;
        return true;
    }
View Full Code Here


            throw (LoginException) new LoginException().initCause(uce);
        }
        assert callbacks.length == 2;
        cbUsername = ((NameCallback) callbacks[0]).getName();
        if (cbUsername == null || cbUsername.equals("")) {
            throw new FailedLoginException();
        }
        char[] provided = ((PasswordCallback) callbacks[1]).getPassword();
        cbPassword = provided == null ? null : new String(provided);

        try {
            Connection conn;
            if (dataSource != null) {
                conn = dataSource.getConnection();
            } else {
                conn = driver.connect(connectionURL, properties);
            }

            try {
                PreparedStatement statement = conn.prepareStatement(userSelect);
                try {
                    int count = countParameters(userSelect);
                    for (int i = 0; i < count; i++) {
                        statement.setObject(i + 1, cbUsername);
                    }
                    ResultSet result = statement.executeQuery();

                    try {
                        boolean found = false;
                        while (result.next()) {
                            String userName = result.getString(1);
                            String userPassword = result.getString(2);

                            if (cbUsername.equals(userName)) {
                                found = true;
                                if (!checkPassword(userPassword, cbPassword)) {
                                    throw new FailedLoginException();
                                }
                                break;
                            }
                        }
                        if(!found) {
                            // User does not exist
                            throw new FailedLoginException();
                        }
                    } finally {
                        result.close();
                    }
                } finally {
View Full Code Here

        } catch (HeaderMismatchException e) {
            throw (LoginException) new LoginException("Header Mistmatch error").initCause(e);
        }

        if (headerMap.isEmpty()) {
            throw new FailedLoginException();
        }

        if (authenticationAuthority.equalsIgnoreCase("Siteminder")) {
            HeaderHandler headerHandler = new SiteminderHeaderHandler();
            username = headerHandler.getUser(headerMap);
        } else if (authenticationAuthority.equalsIgnoreCase("Datapower")) {
            /* To be Done */
        }
        if (username == null || username.equals("")) {
            username = null;
            throw new FailedLoginException();
        }

        try {
            boolean result = authenticate(username);
            if (!result) {
                throw new FailedLoginException();
            }
        } catch (LoginException e) {
            // Clear out the private state
            username = null;
            groups.clear();
View Full Code Here

            NamingEnumeration results = context.search(userBase, filter, constraints);

            if (results == null || !results.hasMore()) {
                log.error("No roles associated with user " + username);
                loginSucceeded = false;
                throw new FailedLoginException();
            }

            SearchResult result = (SearchResult) results.next();

            if (results.hasMore()) {
                // ignore for now
            }
            NameParser parser = context.getNameParser("");
            Name contextName = parser.parse(context.getNameInNamespace());
            Name baseName = parser.parse(userBase);
            Name entryName = parser.parse(result.getName());
            Name name = contextName.addAll(baseName);
            name = name.addAll(entryName);
            String dn = name.toString();

            Attributes attrs = result.getAttributes();
            if (attrs == null) {
                return false;
            }
            ArrayList<String> roles = null;
            if (userRoleName != null) {
                roles = addAttributeValues(userRoleName, attrs, roles);
            }
            // check the credentials by binding to server
            // bindUser(context, dn);
            // if authenticated add more roles
            roles = getRoles(context, dn, username, roles);
            for (String role : roles) {
                groups.add(role);
            }
            if (groups.isEmpty()) {
                log.error("No roles associated with user " + username);
                loginSucceeded = false;
                throw new FailedLoginException();
            } else
                loginSucceeded = true;

        } catch (CommunicationException e) {
            close(context);
            throw (LoginException) new FailedLoginException().initCause(e);
        } catch (NamingException e) {
            close(context);
            throw (LoginException) new FailedLoginException().initCause(e);
        }
        return true;
    }
View Full Code Here

        context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn);
        try {
            context.getAttributes("", null);
        } catch (AuthenticationException e) {
            log.debug("Authentication failed for dn=" + dn);
            throw new FailedLoginException();
        } finally {

            if (connectionUsername != null) {
                context.addToEnvironment(Context.SECURITY_PRINCIPAL, connectionUsername);
            } else {
View Full Code Here

            synchronized (userData) {
                history = userData.get(username);
            }
            if(history != null && !history.isLoginAllowed(lockoutDuration, failurePeriod, failureCount)) {
                username = null;
                throw new FailedLoginException("Maximum login failures exceeded; try again later");
            }
        }
        return false;
    }
View Full Code Here

        try {
            handler.handle(callbacks);
            assert callbacks.length == 1;
            X509Certificate certificate = ((CertificateCallback)callbacks[0]).getCertificate();
            if (certificate == null) {
                throw new FailedLoginException();
            }
            principal = certificate.getSubjectX500Principal();

            if(!users.containsKey(principal.getName())) {
                // Clear out the private state
                principal = null;
                throw new FailedLoginException();
            }

            loginSucceeded = true;
            return true;
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            //try username/pw callbacks
            callbacks[0] = new NameCallback("User name");
            try {
                handler.handle(callbacks);
                assert callbacks.length == 1;
                String name = ((NameCallback)callbacks[0]).getName();
                if (name == null) {
                    throw new FailedLoginException();
                }
                principal = new X500Principal(name);
                //this normalizes the name by removing spaces
                name = principal.getName();
                if(!users.containsKey(name)) {
                    // Clear out the private state
                    principal = null;
                    throw new FailedLoginException();
                }
                principal = new X500Principal(name);
                loginSucceeded = true;
                return true;
            } catch (IOException ioe) {
View Full Code Here

        assert callbacks.length == 1;
        username = ((NameCallback) callbacks[0]).getName();
        if (username == null || username.equals("")) {
            // Clear out the private state
            username = null;
            throw new FailedLoginException();
        }

        loginSucceeded = true;
        return true;
    }
View Full Code Here

        } catch (HeaderMismatchException e) {
            throw (LoginException) new LoginException("Header Mistmatch error").initCause(e);
        }

        if (headerMap.isEmpty()) {
            throw new FailedLoginException();
        }

        if (authenticationAuthority.equalsIgnoreCase("Siteminder")) {
            HeaderHandler headerHandler = new SiteminderHeaderHandler();
            username = headerHandler.getUser(headerMap);
        } else if (authenticationAuthority.equalsIgnoreCase("Datapower")) {
            /* To be Done */
        }
        if (username == null || username.equals("")) {
            username = null;
            throw new FailedLoginException();
        }

        if (dataSource != null) {
            try {
                conn = dataSource.getConnection();
                try {
                    statement = conn.prepareStatement(groupSelect);
                    int count = countParameters(groupSelect);
                    for (int i = 0; i < count; i++) {
                        statement.setObject(i + 1, username);
                    }
                    result = statement.executeQuery();
                    while (result.next()) {
                        String userName = result.getString(1);
                        String groupName = result.getString(2);
                        if (userName.equals(username))
                            groups.add(groupName);
                    }
                    if (groups.isEmpty()) {
                        log.error("No roles associated with user " + username);
                        loginSucceeded = false;
                        throw new FailedLoginException();
                    } else
                        loginSucceeded = true;
                } finally {
                    result.close();
                    statement.close();
View Full Code Here

            throw (LoginException) new LoginException().initCause(uce);
        }
        username = ((NameCallback) callbacks[0]).getName();
        if (username == null || username.equals("")) {
            username = null;
            throw new FailedLoginException();
        }
        byte[] token = Base64.decode(username);
        try {
            GSSManager manager = GSSManager.getInstance();
            Oid krb5Oid = new Oid("1.3.6.1.5.5.2");
View Full Code Here

TOP

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

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.