Examples of DirectoryServerManagerException


Examples of org.wso2.carbon.directory.server.manager.DirectoryServerManagerException

    public String getServiceName(String serverName)
            throws DirectoryServerManagerException {

        String[] components = serverName.split("/");
        if (components == null || components.length != 2) {
            throw new DirectoryServerManagerException("Invalid server name provided. " +
                    "Could not retrieve service component.");
        }

        // Check whether there is a uid by that name
        if (isExistingServiceUid(components[0])) {
View Full Code Here

Examples of org.wso2.carbon.directory.server.manager.DirectoryServerManagerException

        DirContext dirContext;
        try {
            dirContext = this.connectionSource.getContext();
        } catch (UserStoreException e) {
            log.error("Unable to retrieve directory context.", e);
            throw new DirectoryServerManagerException("Unable to retrieve directory context.", e);
        }

        //first search the existing user entry.
        String searchBase = realmConfiguration.getUserStoreProperty(LDAPConstants.USER_SEARCH_BASE);

        String filter =
                "(&(" + LDAPServerManagerConstants.LDAP_UID + "=" + uid + ")" + getServerPrincipleIncludeString() + ")";

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        searchControls.setReturningAttributes(new String[]{LDAPServerManagerConstants.LDAP_UID});

        try {
            NamingEnumeration<SearchResult> namingEnumeration = dirContext.search(searchBase, filter, searchControls);
            return namingEnumeration.hasMore();

        } catch (NamingException e) {
            log.error("Unable to check whether service exists in directory server. UID - " + uid, e);
            throw new DirectoryServerManagerException("Can not access the directory service", e);
        } finally {
            try {
                JNDIUtil.closeContext(dirContext);
            } catch (UserStoreException e) {
                log.error("Unable to close directory context.", e);
View Full Code Here

Examples of org.wso2.carbon.directory.server.manager.DirectoryServerManagerException

        DirContext dirContext;
        try {
            dirContext = this.connectionSource.getContext();
        } catch (UserStoreException e) {
            log.error("Unable to retrieve directory context.", e);
            throw new DirectoryServerManagerException("Unable to retrieve directory context.", e);
        }

        //first search the existing user entry.
        String searchBase = realmConfiguration.getUserStoreProperty(LDAPConstants.USER_SEARCH_BASE);

        String filter = getServicePrincipleFilter(servicePrinciple);

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        searchControls.setReturningAttributes(new String[]{LDAPServerManagerConstants.LDAP_UID});

        try {
            NamingEnumeration<SearchResult> namingEnumeration = dirContext.search(searchBase, filter, searchControls);
            return namingEnumeration.hasMore();

        } catch (NamingException e) {
            String message = "Unable to search entry with search base " + searchBase + ", filter -" + filter;
            log.error(message, e);
            throw new DirectoryServerManagerException("Can not access the directory service", e);
        } finally {
            try {
                JNDIUtil.closeContext(dirContext);
            } catch (UserStoreException e) {
                log.error("Unable to close directory context.", e);
View Full Code Here

Examples of org.wso2.carbon.directory.server.manager.DirectoryServerManagerException

            throw new DirectoryServerManagerException("Invalid server name provided - " + serverName +
                    ". Server name should take following form, ftp/wso2.example.com");
        }*/

        if (!(credentials instanceof String)) {
            throw new DirectoryServerManagerException("Invalid credentials provided");
        }

        /*String password = (String) credentials;

        if (!isPasswordValid(password)) {
            throw new DirectoryServerManagerException("Password does not meet password policy requirements.");
        }*/

        DirContext dirContext;
        try {
            dirContext = this.connectionSource.getContext();
        } catch (UserStoreException e) {
            throw new DirectoryServerManagerException("An error occurred while retrieving LDAP connection context.", e);
        }

        String searchBase = this.realmConfiguration.getUserStoreProperty(LDAPConstants.USER_SEARCH_BASE);
        try {

            dirContext = (DirContext) dirContext.lookup(searchBase);

            BasicAttributes basicAttributes = new BasicAttributes(true);

            // Put only service name as uid. i.e. if server name is like ftp/wso2.example.com
            // then add only ftp as uid
            String serverUid = getServiceName(serverName);

            constructBasicAttributes(basicAttributes, serverUid, serverName, credentials, serverDescription,
                    LDAPServerManagerConstants.SERVER_PRINCIPAL_ATTRIBUTE_VALUE);

            dirContext.bind(LDAPServerManagerConstants.LDAP_UID + "=" + serverUid, null, basicAttributes);

        } catch (NamingException e) {
            String message = "Can not access the directory context or user " +
                    "already exists in the system";
            log.error(message, e);
            throw new DirectoryServerManagerException(message, e);
        } finally {
            try {
                JNDIUtil.closeContext(dirContext);
            } catch (UserStoreException e) {
                log.error("Unable to close directory context.", e);
View Full Code Here

Examples of org.wso2.carbon.directory.server.manager.DirectoryServerManagerException

        searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        searchCtls.setCountLimit(maxItemLimit);

        if (filter.contains("?") || filter.contains("**")) {
            log.error("Invalid search character " + filter);
            throw new DirectoryServerManagerException(
                    "Invalid character sequence entered for service principle search. Please enter valid sequence.");
        }

        StringBuffer searchFilter;
        searchFilter = new StringBuffer(this.realmConfiguration.getUserStoreProperty(LDAPConstants.USER_FILTER));
        String searchBase = this.realmConfiguration.getUserStoreProperty(LDAPConstants.USER_SEARCH_BASE);

        StringBuffer buff = new StringBuffer();
        buff.append("(&").append(searchFilter).append("(")
                .append(LDAPServerManagerConstants.KRB5_PRINCIPAL_NAME_ATTRIBUTE).append("=")
                .append(filter).append(")").append(getServerPrincipleIncludeString()).append(")");

        String returnedAtts[] = {LDAPServerManagerConstants.KRB5_PRINCIPAL_NAME_ATTRIBUTE,
                LDAPServerManagerConstants.LDAP_COMMON_NAME};
        searchCtls.setReturningAttributes(returnedAtts);
        DirContext dirContext = null;
        try {
            dirContext = connectionSource.getContext();
            NamingEnumeration<SearchResult> answer = dirContext.search(searchBase, buff.toString(),
                    searchCtls);
            List<ServerPrinciple> list = new ArrayList<ServerPrinciple>();
            int i = 0;
            while (answer.hasMoreElements() && i < maxItemLimit) {
                SearchResult sr = answer.next();
                if (sr.getAttributes() != null) {
                    Attribute serverNameAttribute = sr.getAttributes()
                            .get(LDAPServerManagerConstants.KRB5_PRINCIPAL_NAME_ATTRIBUTE);
                    Attribute serverDescription = sr.getAttributes().get(LDAPServerManagerConstants.LDAP_COMMON_NAME);
                    if (serverNameAttribute != null) {

                        ServerPrinciple principle;
                        String serviceName;
                        String serverPrincipleFullName = (String) serverNameAttribute.get();

                        if (serverPrincipleFullName.toLowerCase(Locale.ENGLISH)
                                .contains(LDAPServerManagerConstants.KERBEROS_TGT)) {
                            continue;   
                        }

                        if (serverPrincipleFullName.contains("@")) {
                            serviceName = serverPrincipleFullName.split("@")[0];
                        } else {
                            serviceName = serverPrincipleFullName;
                        }

                        if (serverDescription != null) {
                            principle = new ServerPrinciple(serviceName,
                                    (String) serverDescription.get());
                        } else {

                            principle = new ServerPrinciple(serviceName);
                        }

                        list.add(principle);
                        i++;
                    }
                }
            }

            serverNames = list.toArray(new ServerPrinciple[list.size()]);
            Arrays.sort(serverNames);

        } catch (NamingException e) {
            log.error(e.getMessage(), e);
            throw new DirectoryServerManagerException("Unable to list service principles.", e);
        } catch (UserStoreException e) {
            log.error("Unable to retrieve LDAP connection context.", e);
            throw new DirectoryServerManagerException("Unable to list service principles.", e);
        } finally {
            try {
                JNDIUtil.closeContext(dirContext);
            } catch (UserStoreException e) {
                log.error("Unable to close directory context.", e);
View Full Code Here

Examples of org.wso2.carbon.directory.server.manager.DirectoryServerManagerException

                MessageDigest messageDigest = MessageDigest.getInstance(passwordHashMethod);
                byte[] digestValue = messageDigest.digest(password.getBytes());
                passwordToStore = "{" + passwordHashMethod + "}" + Base64.encode(digestValue);

            } catch (NoSuchAlgorithmException e) {
                throw new DirectoryServerManagerException("Invalid hashMethod", e);
            }
        }

        return passwordToStore;
    }
View Full Code Here

Examples of org.wso2.carbon.directory.server.manager.DirectoryServerManagerException

                    if (password.startsWith("{")) {
                        passwordHashMethod = password.substring(password.indexOf("{") + 1, password.indexOf("}"));
                    }

                    if (!password.equals(getPasswordToStore((String) oldCredential, passwordHashMethod))) {
                        throw new DirectoryServerManagerException("Old password does not match");
                    }
                }
            } catch (NamingException e) {
                log.error("Unable to retrieve old password details. ");
                throw new DirectoryServerManagerException("Could not find old password details");
            }
        }

        Attribute passwordAttribute = new BasicAttribute(LDAPServerManagerConstants.LDAP_PASSWORD);
        passwordAttribute.add(getPasswordToStore((String) newPassword, passwordHashMethod));
View Full Code Here

Examples of org.wso2.carbon.directory.server.manager.DirectoryServerManagerException

        DirContext dirContext;

        try {
            dirContext = this.connectionSource.getContext();
        } catch (UserStoreException e) {
            throw new DirectoryServerManagerException("Unable to retrieve directory connection.", e);
        }

        //first search the existing user entry.
        String searchBase = this.realmConfiguration.getUserStoreProperty(LDAPConstants.USER_SEARCH_BASE);
        String searchFilter = getServicePrincipleFilter(serverName);

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        searchControls.setReturningAttributes(new String[]{LDAPServerManagerConstants.LDAP_PASSWORD});

        try {
            NamingEnumeration<SearchResult> namingEnumeration = dirContext
                    .search(searchBase, searchFilter, searchControls);
            // here we assume only one user
            while (namingEnumeration.hasMore()) {

                BasicAttributes basicAttributes = new BasicAttributes(true);

                SearchResult searchResult = namingEnumeration.next();
                Attributes attributes = searchResult.getAttributes();

                Attribute userPassword = attributes.get(LDAPServerManagerConstants.LDAP_PASSWORD);
                Attribute newPasswordAttribute =
                        getChangePasswordAttribute(userPassword, oldCredential, newCredentials);
                basicAttributes.put(newPasswordAttribute);

                String dnName = searchResult.getName();
                dirContext = (DirContext) dirContext.lookup(searchBase);

                dirContext.modifyAttributes(dnName, DirContext.REPLACE_ATTRIBUTE, basicAttributes);
            }

        } catch (NamingException e) {
            log.error("Unable to update server principle password details. Server name - " + serverName);
            throw new DirectoryServerManagerException("Can not access the directory service", e);
        } finally {
            try {
                JNDIUtil.closeContext(dirContext);
            } catch (UserStoreException e) {
                log.error("Unable to close directory context.", e);
View Full Code Here

Examples of org.wso2.carbon.directory.server.manager.DirectoryServerManagerException

        DirContext dirContext;
        try {
            dirContext = this.connectionSource.getContext();
        } catch (UserStoreException e) {
            throw new DirectoryServerManagerException("Unable to retrieve directory connection.", e);
        }

        //first search the existing user entry.
        String searchBase = this.realmConfiguration.getUserStoreProperty(LDAPConstants.USER_SEARCH_BASE);
        String searchFilter = getServicePrincipleFilter(serverName);

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        searchControls.setReturningAttributes(new String[]{LDAPServerManagerConstants.LDAP_PASSWORD});

        try {
            NamingEnumeration<SearchResult> namingEnumeration = dirContext
                    .search(searchBase, searchFilter, searchControls);
            // here we assume only one user
            while (namingEnumeration.hasMore()) {

                SearchResult searchResult = namingEnumeration.next();
                Attributes attributes = searchResult.getAttributes();

                Attribute userPassword = attributes.get(LDAPServerManagerConstants.LDAP_PASSWORD);

                NamingEnumeration passwords = userPassword.getAll();

                String passwordHashMethod = null;
                if (passwords.hasMore()) {
                    byte[] byteArray = (byte[]) passwords.next();
                    String password = new String(byteArray);

                    if (password.startsWith("{")) {
                        passwordHashMethod = password.substring(password.indexOf("{") + 1, password.indexOf("}"));
                    }

                    return password.equals(getPasswordToStore((String) existingCredentials, passwordHashMethod));
                }
            }

        } catch (NamingException e) {
            log.error("Failed, validating password. " +
                    "Can not access the directory service", e);
            throw new DirectoryServerManagerException("Failed, validating password. " +
                    "Can not access the directory service", e);
        } finally {
            try {
                JNDIUtil.closeContext(dirContext);
            } catch (UserStoreException e) {
View Full Code Here

Examples of org.wso2.carbon.directory.server.manager.DirectoryServerManagerException

        DirContext dirContext;
        try {
            dirContext = this.connectionSource.getContext();
        } catch (UserStoreException e) {
            throw new DirectoryServerManagerException("Unable to retrieve directory connection.", e);
        }

        String searchBase = this.realmConfiguration.getUserStoreProperty(LDAPConstants.USER_SEARCH_BASE);

        //first search the existing user entry.
        String searchFilter = getServicePrincipleFilter(serverName);

        SearchControls searchControls = new SearchControls();
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        searchControls.setReturningAttributes(new String[]{"uid"});
        try {
            NamingEnumeration<SearchResult> namingEnumeration = dirContext.
                    search(searchBase, searchFilter, searchControls);

            // here we assume only one user
            if (namingEnumeration.hasMore()) {

                SearchResult searchResult;

                searchResult = namingEnumeration.next();

                Attributes attributes = searchResult.getAttributes();

                Attribute userId = attributes.get("uid");
                return (String) userId.get();
            } else {
                return null;
            }

        } catch (NamingException e) {
            log.error("Could not find user id for given server " + serverName, e);
            throw new DirectoryServerManagerException("Could not find user id for given server " + serverName, e);
        } finally {
            try {
                JNDIUtil.closeContext(dirContext);
            } catch (UserStoreException e) {
                log.error("Unable to close directory context.", e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.