Package javax.security.auth.login

Examples of javax.security.auth.login.LoginException


        NameCallback user = new NameCallback("User name:");
        Callback[] callbacks = new Callback[]{user};
        try {
            handler.handle(callbacks);
        } catch (Exception e) {
            throw (LoginException)new LoginException("Unable to process callback: "+e.getMessage()).initCause(e);
        }
        if(callbacks.length != 1) {
            throw new IllegalStateException("Number of callbacks changed by server!");
        }
        user = (NameCallback) callbacks[0];
View Full Code Here


        callbacks[0] = new CertificateChainCallback();
        try {
            handler.handle(callbacks);
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            throw (LoginException) new LoginException().initCause(uce);
        }
        assert callbacks.length == 1;
        Certificate[] certificateChain = ((CertificateChainCallback)callbacks[0]).getCertificateChain();
        if (certificateChain == null || certificateChain.length == 0) {
            throw new FailedLoginException();
View Full Code Here

        callbacks[0] = new NameCallback("User name");
        callbacks[1] = new PasswordCallback("Password", false);
        try {
            handler.handle(callbacks);
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            throw (LoginException) new LoginException().initCause(uce);
        }
        cbUsername = ((NameCallback) callbacks[0]).getName();
        cbPassword = new String(((PasswordCallback) callbacks[1]).getPassword());

        if (cbUsername == null || "".equals(cbUsername)
                || cbPassword == null || "".equals(cbPassword)) {
            // Clear out the private state
            cbUsername = null;
            cbPassword = null;
            groups.clear();
            throw new FailedLoginException();
        }

        try {
            boolean result = authenticate(cbUsername, cbPassword);
            if (!result) {
                throw new FailedLoginException();
            }
        } catch (LoginException e) {
            // Clear out the private state
            cbUsername = null;
            cbPassword = null;
            groups.clear();
            throw e;
        } catch (Exception e) {
            // Clear out the private state
            cbUsername = null;
            cbPassword = null;
            groups.clear();
            throw (LoginException) new LoginException("LDAP Error").initCause(e);
        }

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

        callbacks[0] = new NameCallback("User name");
        callbacks[1] = new PasswordCallback("Password", false);
        try {
            callbackHandler.handle(callbacks);
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            throw (LoginException) new LoginException().initCause(uce);
        }

        String username = ((NameCallback) callbacks[0]).getName();
        char[] password = ((PasswordCallback) callbacks[1]).getPassword();
View Full Code Here

    }

    public boolean commit() throws LoginException {

        if (subject.isReadOnly()) {
            throw new LoginException("Subject is ReadOnly");
        }

        Set pvtCreds = subject.getPrivateCredentials();
        if (nupCredential != null && !pvtCreds.contains(nupCredential)) {
            pvtCreds.add(nupCredential);
View Full Code Here

        callbacks[0] = new NameCallback("User name");
        callbacks[1] = new PasswordCallback("Password", false);
        try {
            handler.handle(callbacks);
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            throw (LoginException) new LoginException().initCause(uce);
        }
        assert callbacks.length == 2;
        username = ((NameCallback) callbacks[0]).getName();
        if (username == null || username.equals("")) {
            // Clear out the private state
View Full Code Here

        callbacks[0] = new NameCallback("User name");
        callbacks[1] = new PasswordCallback("Password", false);
        try {
            handler.handle(callbacks);
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            throw (LoginException) new LoginException().initCause(uce);
        }
        cbUsername = ((NameCallback) callbacks[0]).getName();
        cbPassword = new String(((PasswordCallback) callbacks[1]).getPassword());

        if (cbUsername == null || "".equals(cbUsername)
            || cbPassword == null || "".equals(cbPassword)) {
            return false;
        }

        try {
            boolean result = authenticate(cbUsername, cbPassword);
            if(!result) {
                throw new FailedLoginException();
            } else {
                return true;
            }
        } catch (Exception e) {
            throw (LoginException) new LoginException("LDAP Error").initCause(e);
        }
    }
View Full Code Here

                    isInAdminGroup = true;
                    break;
                }
            }
            if(!isInAdminGroup){
                throw new LoginException("Only users in admin group are allowed");
            }
            return context.getSubject();
        } catch (LoginException e) {
            // do not propogate cause - we don't know what information is may contain
            throw new SecurityException("Invalid login");
View Full Code Here

        Callback[] callbacks = new Callback[1];
        callbacks[0] = new NameCallback("User name");
        try {
            callbackHandler.handle(callbacks);
        } catch (IOException ioe) {
            throw (LoginException) new LoginException().initCause(ioe);
        } catch (UnsupportedCallbackException uce) {
            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");
            GSSName gssName = manager.createName(targetName, GSSName.NT_USER_NAME);
            GSSCredential serverCreds = manager.createCredential(gssName, GSSCredential.INDEFINITE_LIFETIME, krb5Oid, GSSCredential.ACCEPT_ONLY);
            GSSContext gContext = manager.createContext(serverCreds);
            if (gContext == null) {
                log.debug("Failed to create a GSSContext");
            } else {
                while (!gContext.isEstablished()) {
                    token = gContext.acceptSecContext(token, 0, token.length);
                }
                if (gContext.isEstablished()) {
                    loginSucceeded = true;
                    srcName = gContext.getSrcName();
                    log.debug("A security context is successfully established" + gContext);
                    return loginSucceeded;
                } else {
                    log.error("Failed to establish a security context");
                    throw new LoginException("Failed to establish a security context");
                }
            }
        } catch (GSSException e) {
            throw (LoginException) new LoginException().initCause(e);
        }
        return loginSucceeded;
    }
View Full Code Here

                int totalResults = 0;
                try {
                    ctx = getConnection();
                    if (ctx == null) {
                        log.info("Failed to get a directory context object");
                        throw new LoginException("Failed to get a directory context object");
                    }
                    searchCtls.setReturningAttributes(returnedAtts);
                    searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
                    // Search for objects using the filter
                    NamingEnumeration<SearchResult> answer = ctx.search(searchBase, searchFilter, searchCtls);
                    // Loop through the search results
                    while (answer.hasMoreElements()) {
                        SearchResult sr = answer.next();
                        totalResults++;
                        Attributes attrs = sr.getAttributes();
                        if (attrs != null) {
                            try {
                                byte[] userSid = (byte[]) attrs.get("objectSid;binary").get();
                                Integer primaryGroupId = new Integer((String) attrs.get("primaryGroupID").get());
                                byte[] groupRid = integerToFourBytes(primaryGroupId);
                                byte[] groupSid = userSid.clone();
                                // Replace the last four bytes to construct
                                // groupSid
                                for (int i = 0; i < 4; ++i) {
                                    groupSid[groupSid.length - 1 - i] = groupRid[i];
                                }
                                groupSearchFilter = "(&(objectSid=" + binaryToStringSID(groupSid) + "))";
                                Attribute answer1 = attrs.get("memberOf");
                                for (int i = 0; i < answer1.size(); i++) {
                                    String str = answer1.get(i).toString();
                                    String str1[] = str.split("CN=");
                                    allPrincipals.add(new GeronimoGroupPrincipal(str1[1].substring(0, str1[1].indexOf(","))));
                                }
                            } catch (NullPointerException e) {
                                throw new LoginException("Errors listing attributes: " + e);
                            }
                        }
                    }
                    // Search for objects using the group search filter
                    NamingEnumeration<SearchResult> answer2 = ctx.search(searchBase, groupSearchFilter, searchCtls);
                    // Loop through the search results
                    while (answer2.hasMoreElements()) {
                        SearchResult sr = answer2.next();
                        String str1[] = sr.getName().split("CN=");
                        allPrincipals.add(new GeronimoGroupPrincipal(str1[1].substring(0, str1[1].indexOf(","))));
                    }
                } catch (NamingException e) {
                    throw (LoginException) new LoginException().initCause(e);
                } finally {
                    if (ctx != null) {
                        try {
                            ctx.close();
                        } catch (Exception e) {
View Full Code Here

TOP

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

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.