Package com.google.gsa

Examples of com.google.gsa.Credential



        //First read the u/p the credentails store, in this case using the same as the root login
        logger.debug("HttpBasic: trying to get creds from repository ID: " +
                     id);
        Credential httpBasicCred = null;
        try {
            httpBasicCred = creds.getCredential(id);
        } catch (NullPointerException npe) {
            logger.error("NPE while reading credentials of ID: " + id);
        }
        if (httpBasicCred != null) {
            credentials =
                    new UsernamePasswordCredentials(httpBasicCred.getUsername(),
                                                    httpBasicCred.getPassword());
        } else {
            logger.debug("HttpBasic: trying to get creds from repository \"root\"");
            httpBasicCred = creds.getCredential("root");
            if (httpBasicCred != null) {
                logger.info("Trying with root credentails");
                credentials =
                        new UsernamePasswordCredentials(httpBasicCred.getUsername(),
                                                        httpBasicCred.getPassword());
            }
        }

        logger.debug("Authenticating");
        Header[] headers = null;
View Full Code Here


            }


            //Get user credentials
            //First read the u/p the credentails store, in this case using the same as the root login
            Credential userNamePwdCred = null;

            if (isNegotiate) {
                logger.debug("KerbAuth: IsNegotiate");
                responseCode = authNegotiate(request, response);
            } else {
                logger.debug("KerbAuth: It's NOT IsNegotiate with id: " + id);

                try {
                    logger.debug("HttpKrb: trying to get creds from repository id: " +
                                 id);
                    userNamePwdCred = creds.getCredential(id);
                } catch (NullPointerException npe) {
                    logger.error("NPE while reading credentials of ID: " + id);
                }

                if (userNamePwdCred == null) {
                    logger.debug("HttpKrb: trying to get creds from repository \"root\"");
                    userNamePwdCred = creds.getCredential("root");
                }

                //Execute Authentication method with username and password
                responseCode = authUsernamePassword(userNamePwdCred);
            }


            if (responseCode == HttpServletResponse.SC_OK) {
                //create cookie
                createCookie(request, response);
                //add cookie to the cookie array
                authCookies.add(gsaKrbAuthCookie);
                //add Krb credentials
                Credential krb5Cred = new Credential(KRB5_ID);
                krb5Cred.setKrbSubject(getUserSubject());
                krb5Cred.setUsername(getUsername());
                creds.add(krb5Cred);
            }

        } catch (Exception e) {
            logger.debug("Error creating Credentials: " + e.getMessage());
View Full Code Here

        cookies = request.getCookies();

        //First read the u/p the credentails store, in this case using the same as the root login
        logger.debug("LDAPUniqueCreds: trying to get creds from repository ID: " +
                     id);
        Credential cred = null;
        try {
            cred = creds.getCredential(id);
        } catch (NullPointerException npe) {
            logger.error("NPE while reading credentials of ID: " + id);
        }
        if (cred == null) {
            cred = creds.getCredential("root");
            if (cred != null) {
                logger.info("LDAPUniqueCreds: credential ID used is \"root\"");
            } else {
                logger.error("LDAPUniqueCreds: No credentials available for " +
                             id);
            }
        }


        try {
            authMaxAge = Integer.parseInt(valveConf.getAuthMaxAge());
        } catch (NumberFormatException nfe) {
            logger.error("Configuration error: chack the configuration file as the number set for authMaxAge is not OK:");
        }

        //If the required cookie was not found need to authenticate.
        logger.debug("Authenticating");
        try {

            //read values from config file (if any)
            readLDAPParameters(id);

            //Check if the LDAP credentials are OK                     
            logger.debug("Base user is: " + ldapBaseuser);
            Ldap ldapconn =
                new Ldap(ldapHost, cred.getUsername(), cred.getPassword(),
                         ldapBaseuser, ldapDomain, rdnAttr);

            try {
                logger.debug("Connection to LDAP");
                DirContext ctx = ldapconn.openConnection();
                if (ctx == null) {
                    //Just send a comment 
                    logger.debug("The user(" + cred.getUsername() +
                                 ")/password doesn't match");
                    ldapconn.closeConnection(ctx);
                    return (HttpServletResponse.SC_UNAUTHORIZED);
                }
View Full Code Here

        //Insert LDAP attributes from the config file
        getLDAPAttributes(id);

        //First read the u/p the credentails store, in this case using the same as the root login
        logger.debug("LDAPSSO: trying to get creds from repository ID: " + id);
        Credential cred = null;
        try {
            cred = creds.getCredential(id);
        } catch (NullPointerException npe) {
            logger.error("NPE while reading credentials of ID: " + id);
        }
        if (cred == null) {
            cred = creds.getCredential("root");
            if (cred != null) {
                logger.info("LDAPSSO: credential ID used is \"root\"");
            } else {
                logger.error("LDAPSSO: No credentials available for " + id);
            }
        }

        Cookie[] cookies = null;

        // Initialize status code
        int statusCode = HttpServletResponse.SC_UNAUTHORIZED;

        // Read cookies
        cookies = request.getCookies();

        try {
            authMaxAge = Integer.parseInt(valveConf.getAuthMaxAge());
        } catch (NumberFormatException nfe) {
            logger.error("Configuration error: chack the configuration file as the number set for authMaxAge is not OK:");
        }

        //If the required cookie was not found need to authenticate.
        logger.info("Authenticating root user with LDAP");
        try {

            //Check if the LDAP credentials are OK                     
            Ldap ldapconn =
                new Ldap(ldapHost, cred.getUsername(), cred.getPassword(),
                         ldapBaseuser, ldapDomain, rdnAttr);
            try {
                logger.debug("Connecting to LDAP");
                DirContext ctx = ldapconn.openConnection();
                if (ctx == null) {
                    //Just send a comment 
                    logger.debug("The user(" + cred.getUsername() +
                                 ")/password doesn't match");
                    ldapconn.closeConnection(ctx);
                    return (HttpServletResponse.SC_UNAUTHORIZED);
                }


                //Fetching credentials
                logger.debug("Fetching credentials from the LDAP");

                fetchingCredentials(ldapconn, ctx, cred.getUsername(), creds);

                //Close the connection
                ldapconn.closeConnection(ctx);

            } catch (Exception ex) {
View Full Code Here

                    passwordAttr =
                            ldapconn.getAttributeByDN(attrRepository.getPasswordAttr(),
                                                      userDName, ctx);
                    //add the credentials into the "creds" object
                    logger.debug("LDAP credentials were acquired OK. Adding them into the credential container");
                    Credential credAttr = new Credential(id);
                    credAttr.setUsername(usernameAttr);
                    credAttr.setPassword(passwordAttr);
                    creds.add(credAttr);
                } else {
                    logger.debug("Credentials for " + id +
                                 " were not found for the user " + username);
                }
View Full Code Here

        }

        Vector<Cookie> authCookies = new Vector<Cookie>();

        //Credentials
        Credential cred =
            CrawlingUtils.getBasicCredentials(authZHeader, realm, credID);

        //Protection: check credentials have the right format
        if (cred == null) {
            logger.error("Basic Credentials does not have the correct format");
            return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        }

        //Add credentials
        Credentials creds = new Credentials();
        creds.add(cred);

        //Session status: set default value
        int resultCode = HttpServletResponse.SC_UNAUTHORIZED;

        //Instantiate Crawling session       
        crawlSession = new CrawlingSession(new Long(timeout).longValue());
        //Set Valve Config
        crawlSession.setValveConf(valveConf);

        //Get session
        logger.debug("Session ID to be seeked: " + credStr);
        UserSession userSession = crawlSession.getSession(credStr);

        //Check if session exists. If not, create/recreate it
        if (userSession == null) {

            resultCode =
                    crawlSession.authenticate(credStr, cred.getUsername(), httpRequest,
                                              httpResponse, authCookies, url,
                                              creds, credID);

            //Check resultCode
            if (resultCode != HttpServletResponse.SC_OK) {
                logger.error("Authentication result is not OK: " + resultCode);
                return resultCode;
            } else {
                userSession = crawlSession.getSession(credStr);
            }

        } else {

            //Check the session is valid
            if (!crawlSession.isValidSession(credStr)) {
                //reauthenticate
                resultCode =
                        crawlSession.reauthenticate(credStr, cred.getUsername(),
                                                    httpRequest, httpResponse,
                                                    authCookies, url, creds,
                                                    credID);

                //Check resultCode
View Full Code Here

     */
    public static Credential getBasicCredentials(String basicHeader,
                                                 String domain,
                                                 String authnID) {

        Credential basicCred = null;

        try {

            if ((basicHeader != null) && (!basicHeader.equals(""))) {
                if (basicHeader.startsWith(HEADER_BASIC)) {
                    String credStr =
                        basicHeader.substring(HEADER_BASIC.length());
                    logger.debug("Basic cred is: " + credStr);

                    //Decode the Header and get the credentials
                    byte[] basicByte = credStr.getBytes();
                    String basicCredential =
                        new String(Base64.decodeBase64(basicByte));

                    //Get Username and password
                    String username =
                        new String(basicCredential.substring(0, basicCredential.indexOf(CRED_SEPARATOR)));
                    String password =
                        new String(basicCredential.substring(basicCredential.indexOf(CRED_SEPARATOR) +
                                                             1));

                    logger.debug("Crawler: username [" + username + "]");

                    //Creating the Credential object
                    basicCred = new Credential(authnID);
                    basicCred.setUsername(username);
                    basicCred.setPassword(password);
                    basicCred.setDomain(domain);

                }
            }

        } catch (Exception ex) {
View Full Code Here

TOP

Related Classes of com.google.gsa.Credential

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.