Search in sources :

Example 1 with XMLException

use of com.iplanet.services.util.XMLException in project OpenAM by OpenRock.

the class ServerGroup method process.

/**
     * Not to be called. This is a method to be called by the parser to read the
     * xml information.
     */
public void process(XMLParser parser, String name, Vector elems, Hashtable atts, String Pcdata) throws XMLException {
    if (DSConfigMgr.debugger.messageEnabled()) {
        DSConfigMgr.debugger.message("in ServerGroup.process()");
    }
    if (name.equals(DSConfigMgr.SERVERGROUP)) {
        // get the group ID.
        groupName = (String) atts.get(DSConfigMgr.NAME);
        // Get the Servers
        for (int i = 0; i < elems.size(); i++) {
            Object obj = elems.elementAt(i);
            if (DSConfigMgr.debugger.messageEnabled()) {
                DSConfigMgr.debugger.message("Object of type:" + obj.getClass().getName());
            }
            if (obj instanceof Server) {
                if (servers == null) {
                    if (DSConfigMgr.debugger.messageEnabled()) {
                        DSConfigMgr.debugger.message("Initializing servers list.");
                    }
                    servers = new ArrayList<Server>();
                }
                servers.add((Server) obj);
            } else if (obj instanceof LDAPUser) {
                if (users == null) {
                    users = new ArrayList();
                }
                users.add(obj);
            } else if (obj instanceof GenericNode) {
                // if it is generic node, its probably the base dn.
                GenericNode x = (GenericNode) obj;
                if (x._name.equals(DSConfigMgr.BASE_DN)) {
                    if (x._pcdata != null) {
                        if (DN.valueOf(x._pcdata).size() <= 0) {
                            throw new XMLException(DSConfigMgr.getString(IUMSConstants.DSCFG_INVALID_BASE_DN) + x._pcdata);
                        }
                    }
                    baseDN = DN.valueOf(x._pcdata).toString();
                } else if (x._name.equals(DSConfigMgr.MISC_CONFIG)) {
                    String attrName = (String) x._atts.get(DSConfigMgr.NAME);
                    String attrValue = (String) x._atts.get(DSConfigMgr.VALUE);
                    if (name != null && name.length() > 0) {
                        if (miscConfig == null) {
                            miscConfig = new HashMap();
                        }
                        miscConfig.put(attrName, attrValue);
                    }
                }
            }
        }
        if (servers == null || baseDN == null) {
            String errorMsg = null;
            if (servers == null) {
                errorMsg = "No server object found in the server group:" + groupName;
            }
            if (baseDN == null) {
                errorMsg = "No base DN string defined in the server group:" + groupName;
            }
            throw new XMLException(errorMsg);
        }
        // Get the rest of the attributes
        String maxConnPoolStr = System.getProperty("max_conn_pool");
        if (maxConnPoolStr == null)
            maxConnPoolStr = (String) atts.get(DSConfigMgr.MAX_CONN_POOL);
        String minConnPoolStr = System.getProperty("min_conn_pool");
        if (minConnPoolStr == null)
            minConnPoolStr = (String) atts.get(DSConfigMgr.MIN_CONN_POOL);
        try {
            maxConnPool = Integer.parseInt(maxConnPoolStr);
        } catch (NumberFormatException ex) {
            maxConnPool = 10;
        }
        try {
            minConnPool = Integer.parseInt(minConnPoolStr);
        } catch (NumberFormatException ex) {
            minConnPool = 1;
        }
        String ldapHeartbeatStr = System.getProperty(Constants.LDAP_HEARTBEAT);
        if (ldapHeartbeatStr == null)
            ldapHeartbeatStr = (String) atts.get(Constants.LDAP_HEARTBEAT);
        try {
            ldapHeartbeat = Integer.parseInt(ldapHeartbeatStr);
        } catch (NumberFormatException ex) {
            ldapHeartbeat = 10;
        }
    } else {
        throw new XMLException(DSConfigMgr.getString(IUMSConstants.DSCFG_SERVERGROUP_NODE_EXPECTED));
    }
    // Put it in the list of groups.
    parser.getGroupContainer().put(groupName, this);
}
Also used : XMLException(com.iplanet.services.util.XMLException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GenericNode(com.iplanet.services.util.GenericNode)

Example 2 with XMLException

use of com.iplanet.services.util.XMLException in project OpenAM by OpenRock.

the class BootstrapCreator method updateBootstrap.

public static void updateBootstrap() throws ConfigurationException {
    try {
        DSConfigMgrBase dsCfg = new DSConfigMgrBase();
        dsCfg.parseServiceConfigXML();
        instance.update(dsCfg);
    } catch (XMLException e) {
        throw new ConfigurationException(e.getMessage());
    } catch (SMSException e) {
        throw new ConfigurationException(e.getMessage());
    } catch (SSOException e) {
        throw new ConfigurationException(e.getMessage());
    }
}
Also used : XMLException(com.iplanet.services.util.XMLException) DSConfigMgrBase(com.iplanet.services.ldap.DSConfigMgrBase) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 3 with XMLException

use of com.iplanet.services.util.XMLException in project OpenAM by OpenRock.

the class ServerConfigMgr method getServerConfigXMLDoc.

private void getServerConfigXMLDoc() throws Exception {
    InputStream is = null;
    try {
        String strXML = ServerConfiguration.getServerConfigXML(ssoToken, SystemProperties.getServerInstanceName());
        is = new ByteArrayInputStream(strXML.getBytes());
        Document document = XMLUtils.getXMLDocument(is);
        if (document == null) {
            throw (new XMLException(i18n.getString("dscfg-error-reading-config-file") + "\n" + i18n.getString("dscfg-corrupted-serverconfig")));
        }
        root = XMLUtils.getRootNode(document, DSConfigMgr.ROOT);
        if (root == null) {
            throw new XMLException(i18n.getString("dscfg-unable-to-find-root-node") + "\n" + i18n.getString("dscfg-corrupted-serverconfig"));
        }
        defaultServerGroup = XMLUtils.getNamedChildNode(root, DSConfigMgr.SERVERGROUP, DSConfigMgr.NAME, DSConfigMgr.DEFAULT);
        if (defaultServerGroup == null) {
            throw new XMLException(i18n.getString("dscfg-unable-to-find-default-servergroup") + "\n" + i18n.getString("dscfg-corrupted-serverconfig"));
        }
        strXMLDeclarationHdr = getXMLDeclarationHeader(ssoToken, configFile);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
Also used : XMLException(com.iplanet.services.util.XMLException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Document(org.w3c.dom.Document)

Example 4 with XMLException

use of com.iplanet.services.util.XMLException in project OpenAM by OpenRock.

the class ServerConfigMgr method setUserPassword.

private void setUserPassword(String userType, String password) throws Exception {
    Node pwdNode = XMLUtils.getChildNode(getUserNode(userType), DSConfigMgr.AUTH_PASSWD);
    if (pwdNode == null) {
        throw (new XMLException(i18n.getString("dscfg-corrupted-serverconfig")));
    }
    // Encrypt the new password and store
    String encPassword = (String) AccessController.doPrivileged(new EncodeAction(password));
    NodeList textNodes = pwdNode.getChildNodes();
    Node textNode = textNodes.item(0);
    textNode.setNodeValue(encPassword);
    // Delete the remaining text nodes
    for (int i = 1; i < textNodes.getLength(); i++) {
        pwdNode.removeChild(textNodes.item(i));
    }
}
Also used : XMLException(com.iplanet.services.util.XMLException) EncodeAction(com.sun.identity.security.EncodeAction) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList)

Example 5 with XMLException

use of com.iplanet.services.util.XMLException in project OpenAM by OpenRock.

the class ServerConfigMgr method changePassword.

/**
     * Checks and sets the password
     */
private void changePassword(String userType, String oldPassword, String newPassword) throws Exception {
    String fileEncPassword = getUserPassword(userType);
    String userDN = getUserDN(userType);
    if ((fileEncPassword == null) || (fileEncPassword.length() == 0) || (userDN == null) || (userDN.length() == 0)) {
        debug.error("Null password or user DN for user type: " + userType + " from file: " + configFile);
        throw new XMLException(i18n.getString("dscfg-corrupted-serverconfig"));
    }
    // Verify old password
    if (!oldPassword.equals(AccessController.doPrivileged(new DecodeAction(fileEncPassword)))) {
        throw new Exception(i18n.getString("dscfg-old-passwd-donot-match"));
    }
    if (isAMSDKConfigured) {
        // this is to check if updating of DS is required.
        try {
            new AuthContext(new AuthPrincipal(userDN), newPassword.toCharArray());
            if (debug.messageEnabled()) {
                debug.message("DN: " + userDN + " new password is already updated in the directory");
            }
        } catch (LoginException lee) {
            try {
                AuthContext ac = new AuthContext(new AuthPrincipal(userDN), oldPassword.toCharArray());
                PersistentObject user = UMSObject.getObject(ac.getSSOToken(), new Guid(userDN));
                if (debug.messageEnabled()) {
                    debug.message("For DN: " + userDN + " changing password in directory");
                }
                user.setAttribute(new Attr("userPassword", newPassword));
                user.save();
            } catch (LoginException le) {
                if (debug.warningEnabled()) {
                    debug.warning("For DN: " + userDN + " new and old passwords donot match with directory");
                }
                throw new Exception(i18n.getString("dscfg-invalid-password") + "\n" + le.getMessage());
            }
        }
    }
    setUserPassword(userType, newPassword);
}
Also used : XMLException(com.iplanet.services.util.XMLException) DecodeAction(com.sun.identity.security.DecodeAction) AuthContext(com.sun.identity.authentication.internal.AuthContext) LoginException(javax.security.auth.login.LoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) PersistentObject(com.iplanet.ums.PersistentObject) AuthPrincipal(com.sun.identity.authentication.internal.AuthPrincipal) Guid(com.iplanet.ums.Guid) LoginException(javax.security.auth.login.LoginException) FileNotFoundException(java.io.FileNotFoundException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) IdRepoException(com.sun.identity.idm.IdRepoException) XMLException(com.iplanet.services.util.XMLException) IOException(java.io.IOException) ConfiguratorException(com.sun.identity.setup.ConfiguratorException)

Aggregations

XMLException (com.iplanet.services.util.XMLException)5 SSOException (com.iplanet.sso.SSOException)2 DSConfigMgrBase (com.iplanet.services.ldap.DSConfigMgrBase)1 GenericNode (com.iplanet.services.util.GenericNode)1 Guid (com.iplanet.ums.Guid)1 PersistentObject (com.iplanet.ums.PersistentObject)1 AuthContext (com.sun.identity.authentication.internal.AuthContext)1 AuthPrincipal (com.sun.identity.authentication.internal.AuthPrincipal)1 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 DecodeAction (com.sun.identity.security.DecodeAction)1 EncodeAction (com.sun.identity.security.EncodeAction)1 ConfiguratorException (com.sun.identity.setup.ConfiguratorException)1 SMSException (com.sun.identity.sm.SMSException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1