Search in sources :

Example 1 with NumberFormatException

use of java.lang.NumberFormatException in project OpenAM by OpenRock.

the class SAMLServiceManager method setValues.

// implemented as synchronized to preserve the event handling order.
private static synchronized void setValues() {
    if (ci == null) {
        // set the values as default
        Map newMap = new HashMap();
        newMap.put(SAMLConstants.ARTIFACT_TIMEOUT_NAME, new Integer(SAMLConstants.ARTIFACT_TIMEOUT_DEFAULT));
        newMap.put(SAMLConstants.ASSERTION_TIMEOUT_NAME, new Integer(SAMLConstants.ASSERTION_TIMEOUT_DEFAULT));
        newMap.put(SAMLConstants.ARTIFACT_NAME, SAMLConstants.ARTIFACT_NAME_DEFAULT);
        newMap.put(SAMLConstants.TARGET_SPECIFIER, SAMLConstants.TARGET_SPECIFIER_DEFAULT);
        newMap.put(SAMLConstants.ASSERTION_MAX_NUMBER_NAME, new Integer(SAMLConstants.ASSERTION_MAX_NUMBER_DEFAULT));
        newMap.put(SAMLConstants.CLEANUP_INTERVAL_NAME, new Integer(SAMLConstants.CLEANUP_INTERVAL_DEFAULT));
        newMap.put(SAMLConstants.SIGN_REQUEST, Boolean.valueOf(SAMLConstants.SIGN_REQUEST_DEFAULT));
        newMap.put(SAMLConstants.SIGN_RESPONSE, Boolean.valueOf(SAMLConstants.SIGN_RESPONSE_DEFAULT));
        newMap.put(SAMLConstants.SIGN_ASSERTION, Boolean.valueOf(SAMLConstants.SIGN_ASSERTION_DEFAULT));
        map = newMap;
    } else {
        // set the values
        try {
            Map newMap = new HashMap();
            Map attrs = ci.getConfiguration(null, null);
            // retrieve not before time skew period 
            Set values = (Set) attrs.get(SAMLConstants.NOTBEFORE_TIMESKEW_NAME);
            int value = SAMLConstants.NOTBEFORE_TIMESKEW_DEFAULT;
            if ((values != null) && (values.size() == 1)) {
                try {
                    value = Integer.parseInt((String) values.iterator().next());
                } catch (NumberFormatException nfe) {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager:invalid" + " not before time skew period value: " + value + ", using default.", nfe);
                    value = SAMLConstants.NOTBEFORE_TIMESKEW_DEFAULT;
                }
                if (value <= 0) {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager:invalid" + " not before time skew period value=" + value + ", using default.");
                    value = SAMLConstants.NOTBEFORE_TIMESKEW_DEFAULT;
                }
            }
            Integer newValue = new Integer(value);
            newMap.put(SAMLConstants.NOTBEFORE_TIMESKEW_NAME, newValue);
            // retrieve artifact timeout
            values = (Set) attrs.get(SAMLConstants.ARTIFACT_TIMEOUT_NAME);
            value = SAMLConstants.ARTIFACT_TIMEOUT_DEFAULT;
            if ((values != null) && (values.size() == 1)) {
                try {
                    value = Integer.parseInt((String) values.iterator().next());
                } catch (NumberFormatException nfe) {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager:invalid" + " artifact timeout value: " + value + ", using default.", nfe);
                    value = SAMLConstants.ARTIFACT_TIMEOUT_DEFAULT;
                }
                if (value <= 0) {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager:invalid" + " artifact timeout value=" + value + ", using default.");
                    value = SAMLConstants.ARTIFACT_TIMEOUT_DEFAULT;
                }
            }
            newValue = new Integer(value);
            newMap.put(SAMLConstants.ARTIFACT_TIMEOUT_NAME, newValue);
            // retrieve assertion timeout
            values = (Set) attrs.get(SAMLConstants.ASSERTION_TIMEOUT_NAME);
            value = SAMLConstants.ASSERTION_TIMEOUT_DEFAULT;
            if ((values != null) && (values.size() == 1)) {
                try {
                    value = Integer.parseInt((String) values.iterator().next());
                } catch (NumberFormatException nfe) {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager:invalid" + " assertion timeout value: " + value + ", using default.", nfe);
                    value = SAMLConstants.ASSERTION_TIMEOUT_DEFAULT;
                }
                if (value <= 0) {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager:invalid" + " assertion timeout value=" + value + ", using default.");
                    value = SAMLConstants.ASSERTION_TIMEOUT_DEFAULT;
                }
            }
            newValue = new Integer(value);
            newMap.put(SAMLConstants.ASSERTION_TIMEOUT_NAME, newValue);
            values = (Set) attrs.get(SAMLConstants.ASSERTION_MAX_NUMBER_NAME);
            value = SAMLConstants.ASSERTION_MAX_NUMBER_DEFAULT;
            if ((values != null) && (values.size() == 1)) {
                try {
                    value = Integer.parseInt((String) values.iterator().next());
                } catch (NumberFormatException nfe) {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager:invalid" + " assertion max number value: " + value + ", using default.", nfe);
                    value = SAMLConstants.ASSERTION_MAX_NUMBER_DEFAULT;
                }
                if (value < 0) {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager:invalid" + " assertion max number value=" + value + ", using default.");
                    value = SAMLConstants.ASSERTION_MAX_NUMBER_DEFAULT;
                }
            }
            newValue = new Integer(value);
            newMap.put(SAMLConstants.ASSERTION_MAX_NUMBER_NAME, newValue);
            values = (Set) attrs.get(SAMLConstants.CLEANUP_INTERVAL_NAME);
            value = SAMLConstants.CLEANUP_INTERVAL_DEFAULT;
            if ((values != null) && (values.size() == 1)) {
                try {
                    value = Integer.parseInt((String) values.iterator().next());
                } catch (NumberFormatException nfe) {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager:invalid" + " cleanup interval value: " + value + ", using default.", nfe);
                    value = SAMLConstants.CLEANUP_INTERVAL_DEFAULT;
                }
                if (value <= 0) {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager:invalid" + " cleanup interval value=" + value + ", using default.");
                    value = SAMLConstants.CLEANUP_INTERVAL_DEFAULT;
                }
            }
            newValue = new Integer(value);
            newMap.put(SAMLConstants.CLEANUP_INTERVAL_NAME, newValue);
            // retrieve the Artifact Name from the SAML saml config file 
            String artifactName = CollectionHelper.getMapAttr(attrs, SAMLConstants.ARTIFACT_NAME, SAMLConstants.ARTIFACT_NAME_DEFAULT);
            newMap.put(SAMLConstants.ARTIFACT_NAME, artifactName);
            values = (Set) attrs.get(SAMLConstants.NAME_ID_FORMAT_MAP);
            Map nameIDFormatAttrMap = null;
            if ((values != null) && (!values.isEmpty())) {
                for (Iterator iter = values.iterator(); iter.hasNext(); ) {
                    String str = (String) iter.next();
                    int index = str.indexOf("=");
                    if (index != -1) {
                        String nameIDFormat = str.substring(0, index).trim();
                        String attrName = str.substring(index + 1).trim();
                        if ((nameIDFormat.length() != 0) && (attrName.length() != 0)) {
                            if (nameIDFormatAttrMap == null) {
                                nameIDFormatAttrMap = new HashMap();
                            }
                            nameIDFormatAttrMap.put(nameIDFormat, attrName);
                        }
                    }
                }
                newMap.put(SAMLConstants.NAME_ID_FORMAT_MAP, nameIDFormatAttrMap);
            }
            values = (Set) attrs.get(SAMLConstants.ATTRIBUTE_MAP);
            Map attrMap = null;
            if ((values != null) && (!values.isEmpty())) {
                for (Iterator iter = values.iterator(); iter.hasNext(); ) {
                    String str = (String) iter.next();
                    int index = str.indexOf("=");
                    if (index != -1) {
                        String samlAttr = str.substring(0, index).trim();
                        String localAttr = str.substring(index + 1).trim();
                        if ((samlAttr.length() != 0) && (localAttr.length() != 0)) {
                            if (attrMap == null) {
                                attrMap = new HashMap();
                            }
                            attrMap.put(samlAttr, localAttr);
                        }
                    }
                }
                newMap.put(SAMLConstants.ATTRIBUTE_MAP, attrMap);
            }
            // get the targets which accept POST
            Set targets = (Set) attrs.get(SAMLConstants.POST_TO_TARGET_URLS);
            if ((targets == null) || (targets.size() == 0)) {
                SAMLUtilsCommon.debug.message("SAMLServiceManager: No POST " + "to targets found");
            } else {
                Set targetsNoProtocol = Collections.synchronizedSet(new HashSet());
                // strip off protocol from the URL
                Iterator it = targets.iterator();
                String targetString = null;
                while (it.hasNext()) {
                    try {
                        targetString = (String) it.next();
                        URL url = new URL(targetString);
                        String targetNoProtocol = new StringBuffer(url.getHost().toLowerCase()).append(":").append(String.valueOf(url.getPort())).append("/").append(url.getPath()).toString();
                        targetsNoProtocol.add(targetNoProtocol);
                    } catch (MalformedURLException me) {
                        SAMLUtilsCommon.debug.error("SAMLServiceManager: " + "Malformed Url in the POST to target " + "list, skipping entry:" + targetString);
                    }
                }
                if (targetsNoProtocol.size() > 0) {
                    newMap.put(SAMLConstants.POST_TO_TARGET_URLS, targetsNoProtocol);
                } else {
                    SAMLUtilsCommon.debug.error("SAMLServiceManager: All" + " POST to target URLs malformed");
                }
            }
            // retrieve site id and site issuer name list
            // get my server host and port info
            serverProtocol = SystemConfigurationUtil.getProperty(SAMLConstants.SERVER_PROTOCOL);
            serverHost = SystemConfigurationUtil.getProperty(SAMLConstants.SERVER_HOST);
            serverPort = SystemConfigurationUtil.getProperty(SAMLConstants.SERVER_PORT);
            serverURI = SystemConfigurationUtil.getProperty(SAMLConstants.SERVER_URI);
            String legacyId = serverProtocol + "://" + serverHost + ":" + serverPort;
            serverURL = legacyId + serverURI;
            String sb = serverURL;
            Map siteidMap = new HashMap();
            Map issuerNameMap = new HashMap();
            Map instanceMap = new HashMap();
            Set siteIDNameList = (Set) attrs.get(SAMLConstants.SITE_ID_ISSUER_NAME_LIST);
            if (siteIDNameList.size() == 0) {
                SAMLUtilsCommon.debug.error("SAMLServiceManager: No Site ID" + " or Issuer Name in the SAML service config.");
            } else {
                String entry = null;
                StringTokenizer tok1 = null;
                String instanceID = null;
                String siteID = null;
                String issuerName = null;
                String element = null;
                String key = null;
                Iterator iter = siteIDNameList.iterator();
                while (iter.hasNext()) {
                    entry = (String) iter.next();
                    // reset
                    instanceID = null;
                    siteID = null;
                    issuerName = null;
                    tok1 = new StringTokenizer(entry, "|");
                    while (tok1.hasMoreElements()) {
                        element = tok1.nextToken();
                        int pos = -1;
                        if ((pos = element.indexOf("=")) == -1) {
                            SAMLUtilsCommon.debug.error("SAMLSManager: " + "wrong format: " + element);
                            break;
                        }
                        int nextpos = pos + 1;
                        if (nextpos >= element.length()) {
                            SAMLUtilsCommon.debug.error("SAMLSManager: " + "wrong format: " + element);
                            break;
                        }
                        key = element.substring(0, pos);
                        if (key.equalsIgnoreCase(SAMLConstants.INSTANCEID)) {
                            instanceID = element.substring(nextpos);
                        } else if (key.equalsIgnoreCase(SAMLConstants.SITEID)) {
                            siteID = element.substring(nextpos);
                        } else if (key.equalsIgnoreCase(SAMLConstants.ISSUERNAME)) {
                            issuerName = element.substring(nextpos);
                        } else {
                            SAMLUtilsCommon.debug.error("SAMLSManager: " + "wrong format: " + element);
                        }
                    }
                    if (instanceID == null) {
                        SAMLUtilsCommon.debug.error("SAMLServiceManager: " + "missing instanceID:" + entry);
                        break;
                    }
                    boolean thisSite = instanceID.equalsIgnoreCase(sb) || instanceID.equalsIgnoreCase(legacyId);
                    if (siteID != null) {
                        siteID = SAMLUtilsCommon.getDecodedSourceIDString(siteID);
                        if (siteID != null) {
                            siteidMap.put(instanceID, siteID);
                            instanceMap.put(siteID, instanceID);
                            if (SAMLUtilsCommon.debug.messageEnabled()) {
                                SAMLUtilsCommon.debug.message("SAMLSMangr: " + "add instanceID: " + instanceID + ", serverURL=" + sb + ", legacy serverURL=" + legacyId + ", isthissite=" + thisSite);
                            }
                            if (thisSite) {
                                newMap.put(SAMLConstants.SITE_ID, siteID);
                            }
                        }
                    }
                    if (issuerName != null) {
                        issuerNameMap.put(instanceID, issuerName);
                        if (thisSite) {
                            newMap.put(SAMLConstants.ISSUER_NAME, issuerName);
                        }
                    }
                }
            // end of looping all the entries in the list
            }
            // set default site id
            if (!siteidMap.containsKey(sb) && !siteidMap.containsKey(legacyId)) {
                String siteID = SAMLSiteID.generateSourceID(sb);
                if (SAMLUtilsCommon.debug.warningEnabled()) {
                    SAMLUtilsCommon.debug.warning("SAMLSManager: site " + sb + " not configured, create new " + siteID);
                }
                if (siteID != null) {
                    siteID = SAMLUtilsCommon.getDecodedSourceIDString(siteID);
                    if (siteID != null) {
                        siteidMap.put(sb, siteID);
                        instanceMap.put(siteID, sb);
                        newMap.put(SAMLConstants.SITE_ID, siteID);
                    } else {
                        SAMLUtilsCommon.debug.error("Missing Site ID.");
                    }
                }
            }
            // set default issuer name
            if (!issuerNameMap.containsKey(sb) && !issuerNameMap.containsKey(legacyId)) {
                if (SAMLUtilsCommon.debug.warningEnabled()) {
                    SAMLUtilsCommon.debug.warning("SAMLSManager:issuer for " + sb + " not configured, set to " + sb);
                }
                issuerNameMap.put(sb, sb);
                newMap.put(SAMLConstants.ISSUER_NAME, sb);
            }
            newMap.put(SAMLConstants.SITE_ID_LIST, siteidMap);
            newMap.put(SAMLConstants.INSTANCE_LIST, instanceMap);
            newMap.put(SAMLConstants.ISSUER_NAME_LIST, issuerNameMap);
            Boolean signRequest = Boolean.valueOf(CollectionHelper.getMapAttr(attrs, SAMLConstants.SIGN_REQUEST, SAMLConstants.SIGN_REQUEST_DEFAULT));
            newMap.put(SAMLConstants.SIGN_REQUEST, signRequest);
            Boolean signResponse = Boolean.valueOf(CollectionHelper.getMapAttr(attrs, SAMLConstants.SIGN_RESPONSE, SAMLConstants.SIGN_RESPONSE_DEFAULT));
            newMap.put(SAMLConstants.SIGN_RESPONSE, signResponse);
            Boolean signAssertion = Boolean.valueOf(CollectionHelper.getMapAttr(attrs, SAMLConstants.SIGN_ASSERTION, SAMLConstants.SIGN_ASSERTION_DEFAULT));
            newMap.put(SAMLConstants.SIGN_ASSERTION, signAssertion);
            //retrieve target name 
            String targetName = CollectionHelper.getMapAttr(attrs, SAMLConstants.TARGET_SPECIFIER, SAMLConstants.TARGET_SPECIFIER_DEFAULT);
            newMap.put(SAMLConstants.TARGET_SPECIFIER, targetName);
            //retrieve the partner URL list 
            Set soapRevList = Collections.synchronizedSet(new HashSet());
            soapRevList = (Set) attrs.get(SAMLConstants.PARTNER_URLS);
            if (soapRevList.size() == 0) {
                if (SAMLUtilsCommon.debug.messageEnabled()) {
                    SAMLUtilsCommon.debug.message("SAMLServiceManager: " + "No entry in partner url config!");
                }
            } else {
                Set _Sites = Collections.synchronizedSet(new HashSet());
                Map _Soaps = Collections.synchronizedMap(new HashMap());
                Object[] soapObjects = soapRevList.toArray();
                int size = soapObjects.length;
                String e = null;
                String element = null;
                for (int i = 0; i < size; i++) {
                    String _siteID = null;
                    String _samlUrl = null;
                    String postUrl = null;
                    String host = null;
                    int port = -1;
                    String _destID = null;
                    String _soapRevUrl = null;
                    String _authType = null;
                    String _user = null;
                    String basic_auth_user = null;
                    String basic_auth_passwd = null;
                    String _certAlias = null;
                    String preferVersion = null;
                    PartnerAccountMapper _partnerAccountMapper = null;
                    SiteAttributeMapper _siteAttributeMapper = null;
                    PartnerSiteAttributeMapper _partnerSiteAttributeMapper = null;
                    ConsumerSiteAttributeMapper consumerSiteAttrMapper = null;
                    NameIdentifierMapper niMapper = null;
                    AttributeMapper attrMapper = null;
                    ActionMapper actionMapper = null;
                    String _issuer = null;
                    Set hostSet = null;
                    Set origHostSet = null;
                    e = (String) soapObjects[i];
                    // retrieve the trusted server list
                    if (e.toUpperCase().indexOf(SAMLConstants.SOURCEID) == -1) {
                        SAMLUtilsCommon.debug.error("Ignore this trusted " + "site since SourceID is absent:" + e);
                        continue;
                    }
                    StringTokenizer tok1 = new StringTokenizer(e, "|");
                    while (tok1.hasMoreElements()) {
                        // break on "|"
                        element = tok1.nextToken();
                        if (SAMLUtilsCommon.debug.messageEnabled()) {
                            SAMLUtilsCommon.debug.message("SAMLSManager:" + " PartnerUrl List:" + element);
                        }
                        //manually break on "=" since sourceid may contain "="
                        int pos = -1;
                        //ignore the attribute which not include "="
                        if ((pos = element.indexOf("=")) == -1) {
                            SAMLUtilsCommon.debug.error("SAMLSManager:" + " illegal format of PartnerUrl:" + element);
                            break;
                        }
                        int nextpos = pos + 1;
                        //ignore the attribute which is like "SOAPUrl="  
                        if (nextpos >= element.length()) {
                            break;
                        }
                        String key = element.substring(0, pos);
                        if (key.equalsIgnoreCase(SAMLConstants.SOURCEID)) {
                            _destID = SAMLUtilsCommon.getDecodedSourceIDString(element.substring(nextpos));
                        } else if (key.equalsIgnoreCase(SAMLConstants.TARGET)) {
                            _siteID = element.substring(nextpos);
                        } else if (key.equalsIgnoreCase(SAMLConstants.SAMLURL)) {
                            _samlUrl = element.substring(nextpos).trim();
                        } else if (key.equalsIgnoreCase(SAMLConstants.POSTURL)) {
                            postUrl = element.substring(nextpos).trim();
                        } else if (key.equalsIgnoreCase(SAMLConstants.SOAPUrl)) {
                            _soapRevUrl = element.substring(nextpos).trim();
                        } else if (key.equalsIgnoreCase(SAMLConstants.AUTHTYPE)) {
                            _authType = element.substring(nextpos);
                            if (SAMLUtilsCommon.debug.messageEnabled()) {
                                SAMLUtilsCommon.debug.message("authtype =" + _authType);
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.UID)) {
                            _user = element.substring(nextpos);
                            if (SAMLUtilsCommon.debug.messageEnabled()) {
                                SAMLUtilsCommon.debug.message("user = " + _user);
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.AUTH_UID)) {
                            basic_auth_user = element.substring(nextpos);
                            if (SAMLUtilsCommon.debug.messageEnabled()) {
                                SAMLUtilsCommon.debug.message("basic auth user=" + basic_auth_user);
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.AUTH_PASSWORD)) {
                            basic_auth_passwd = SAMLUtilsCommon.decodePassword(element.substring(nextpos));
                        } else if (key.equalsIgnoreCase(SAMLConstants.ACCOUNTMAPPER)) {
                            try {
                                Object temp = Class.forName(element.substring(nextpos)).newInstance();
                                if (temp instanceof PartnerAccountMapper) {
                                    _partnerAccountMapper = (PartnerAccountMapper) temp;
                                } else {
                                    SAMLUtilsCommon.debug.error("SAMLServiceManager:Invalid account " + "mapper");
                                }
                            } catch (InstantiationException ie) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:" + ie);
                            } catch (IllegalAccessException ae) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:" + ae);
                            } catch (ClassNotFoundException ce) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:" + ce);
                                _partnerAccountMapper = null;
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.PARTNERACCOUNTMAPPER)) {
                            // for backward compatibility
                            try {
                                _partnerAccountMapper = (PartnerAccountMapper) Class.forName(element.substring(nextpos)).newInstance();
                            } catch (InstantiationException ie) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:", ie);
                            } catch (IllegalAccessException ae) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:", ae);
                            } catch (ClassNotFoundException ce) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:", ce);
                                _partnerAccountMapper = null;
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.CERTALIAS)) {
                            _certAlias = element.substring(nextpos);
                            if (SAMLUtilsCommon.debug.messageEnabled()) {
                                SAMLUtilsCommon.debug.message("certAlias = " + _certAlias);
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.SITEATTRIBUTEMAPPER)) {
                            try {
                                Object temp = Class.forName(element.substring(nextpos)).newInstance();
                                if (temp instanceof SiteAttributeMapper) {
                                    _siteAttributeMapper = (SiteAttributeMapper) temp;
                                } else if (temp instanceof PartnerSiteAttributeMapper) {
                                    _partnerSiteAttributeMapper = (PartnerSiteAttributeMapper) temp;
                                } else if (temp instanceof ConsumerSiteAttributeMapper) {
                                    consumerSiteAttrMapper = (ConsumerSiteAttributeMapper) temp;
                                } else {
                                    SAMLUtilsCommon.debug.error("SAMLServiceManager:Invalid site " + "attribute mapper");
                                }
                            } catch (InstantiationException ie) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:" + ie);
                            } catch (IllegalAccessException ae) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:" + ae);
                            } catch (ClassNotFoundException ce) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:" + ce);
                                _siteAttributeMapper = null;
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.PARTNERSITEATTRIBUTEMAPPER)) {
                            try {
                                Object temp = Class.forName(element.substring(nextpos)).newInstance();
                                if (temp instanceof PartnerSiteAttributeMapper) {
                                    _partnerSiteAttributeMapper = (PartnerSiteAttributeMapper) temp;
                                } else if (temp instanceof ConsumerSiteAttributeMapper) {
                                    consumerSiteAttrMapper = (ConsumerSiteAttributeMapper) temp;
                                } else {
                                    SAMLUtilsCommon.debug.error("SAMLServiceManager:Invalid site " + "partner attribute mapper");
                                }
                            } catch (InstantiationException ie) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:", ie);
                            } catch (IllegalAccessException ae) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:", ae);
                            } catch (ClassNotFoundException ce) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:", ce);
                                _partnerSiteAttributeMapper = null;
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.NAMEIDENTIFIERMAPPER)) {
                            try {
                                niMapper = (NameIdentifierMapper) Class.forName(element.substring(nextpos)).newInstance();
                            } catch (Exception ex) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:", ex);
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.ATTRIBUTEMAPPER)) {
                            try {
                                attrMapper = (AttributeMapper) Class.forName(element.substring(nextpos)).newInstance();
                            } catch (Exception ex) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:" + ex);
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.ACTIONMAPPER)) {
                            try {
                                actionMapper = (ActionMapper) Class.forName(element.substring(nextpos)).newInstance();
                            } catch (Exception ex) {
                                SAMLUtilsCommon.debug.error("SAMLSManager:" + ex);
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.ISSUER)) {
                            _issuer = element.substring(nextpos).trim();
                            if (SAMLUtilsCommon.debug.messageEnabled()) {
                                SAMLUtilsCommon.debug.message("issuer = " + _issuer);
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.HOST_LIST)) {
                            origHostSet = new HashSet();
                            hostSet = new HashSet();
                            /* calling InetAddress.getAllByName here has
                                    two purposes:
                                        - emmit any errors if there is any
                                        - call the getAllByName method to init
                                        the jvm caching
                                */
                            StringTokenizer st = new StringTokenizer(element.substring(nextpos), ",");
                            InetAddress[] addr = null;
                            while (st.hasMoreTokens()) {
                                String token = st.nextToken().trim();
                                try {
                                    addr = InetAddress.getAllByName(token);
                                    for (int m = 0, length = addr.length; m < length; m++) {
                                        hostSet.add(addr[m].getHostAddress());
                                    }
                                } catch (Exception ne) {
                                    if (SAMLUtilsCommon.debug.warningEnabled()) {
                                        SAMLUtilsCommon.debug.warning("SAML Service" + " Manager: possible wrong " + "hostname in the host list.");
                                    }
                                }
                                //add here anyways, since
                                // it could be an alias name too
                                hostSet.add(token);
                                origHostSet.add(token);
                            }
                            if (SAMLUtilsCommon.debug.messageEnabled()) {
                                SAMLUtilsCommon.debug.message("hostSet = " + hostSet);
                            }
                        } else if (key.equalsIgnoreCase(SAMLConstants.VERSION)) {
                            preferVersion = element.substring(nextpos);
                        }
                    }
                    //provide default auth type 
                    if (_authType == null) {
                        _authType = SAMLConstants.NOAUTH;
                    }
                    // provide default AccountMapper
                    if (_partnerAccountMapper == null) {
                        try {
                            _partnerAccountMapper = (PartnerAccountMapper) Class.forName(DEFAULT_PARTNER_ACCOUNT_MAPPER).newInstance();
                        } catch (Exception ex0) {
                        // ignore
                        }
                    }
                    // provide default AttributeMapper
                    if (attrMapper == null) {
                        attrMapper = new DefaultAttributeMapper();
                    }
                    // default version 
                    if (preferVersion == null || preferVersion.length() == 0) {
                        try {
                            preferVersion = SystemConfigurationUtil.getProperty(SAMLConstants.SAML_PROTOCOL_VERSION).trim();
                        } catch (Exception pe) {
                            preferVersion = SAMLConstants.PROTOCOL_VERSION_1_0;
                        }
                    }
                    // create truseted server set 
                    if (_destID == null || _destID.length() == 0) {
                        SAMLUtilsCommon.debug.error("Ignore this trusted " + "site since SourceID is misconfigured: " + e);
                    } else {
                        if (_siteID == null || _siteID.length() == 0 || ((_samlUrl == null || _samlUrl.length() == 0) && (postUrl == null || postUrl.length() == 0))) {
                            SAMLUtilsCommon.debug.warning("Target or both" + " SAMLUrl and POSTUrl are misconfigured:" + e);
                        }
                        if (_siteID != null && _siteID.length() != 0) {
                            StringTokenizer tok2 = new StringTokenizer(_siteID, ",");
                            while (tok2.hasMoreElements()) {
                                String el = tok2.nextToken();
                                if (SAMLUtilsCommon.debug.messageEnabled()) {
                                    SAMLUtilsCommon.debug.message("SAMLServiceManager:target= " + el);
                                }
                                // break the target url to host and port 
                                StringTokenizer pt = new StringTokenizer(el, ":");
                                if (pt.countTokens() == 2) {
                                    host = pt.nextToken().trim();
                                    port = Integer.parseInt(pt.nextToken().trim());
                                } else {
                                    host = el;
                                    port = -1;
                                }
                            }
                            SiteEntry server = new SiteEntry(host, port, _destID, _samlUrl, postUrl, preferVersion);
                            _Sites.add(server);
                        }
                        // create the soap receiver map                      
                        SOAPEntry server = new SOAPEntry(_destID, _soapRevUrl, _authType, _user, basic_auth_user, basic_auth_passwd, _certAlias, _partnerAccountMapper, _siteAttributeMapper, _partnerSiteAttributeMapper, consumerSiteAttrMapper, niMapper, attrMapper, actionMapper, _issuer, origHostSet, preferVersion);
                        _Soaps.put(_destID, server);
                        if (_issuer != null) {
                            _Soaps.put(_issuer, server);
                        }
                    }
                }
                newMap.put(SAMLConstants.TRUSTED_SERVER_LIST, _Sites);
                newMap.put(SAMLConstants.PARTNER_URLS, _Soaps);
            }
            map = newMap;
        } catch (Exception e) {
            SAMLUtilsCommon.debug.error("SAMLServiceManager.setValues:" + " Exception:", e);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) URL(java.net.URL) ActionMapper(com.sun.identity.saml.plugins.ActionMapper) Iterator(java.util.Iterator) PartnerAccountMapper(com.sun.identity.saml.plugins.PartnerAccountMapper) DefaultAttributeMapper(com.sun.identity.saml.plugins.DefaultAttributeMapper) DefaultNameIdentifierMapper(com.sun.identity.saml.plugins.DefaultNameIdentifierMapper) NameIdentifierMapper(com.sun.identity.saml.plugins.NameIdentifierMapper) ConsumerSiteAttributeMapper(com.sun.identity.saml.plugins.ConsumerSiteAttributeMapper) SiteAttributeMapper(com.sun.identity.saml.plugins.SiteAttributeMapper) PartnerSiteAttributeMapper(com.sun.identity.saml.plugins.PartnerSiteAttributeMapper) HashSet(java.util.HashSet) PartnerSiteAttributeMapper(com.sun.identity.saml.plugins.PartnerSiteAttributeMapper) NumberFormatException(java.lang.NumberFormatException) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) MalformedURLException(java.net.MalformedURLException) DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) NumberFormatException(java.lang.NumberFormatException) StringTokenizer(java.util.StringTokenizer) ConsumerSiteAttributeMapper(com.sun.identity.saml.plugins.ConsumerSiteAttributeMapper) SiteAttributeMapper(com.sun.identity.saml.plugins.SiteAttributeMapper) AttributeMapper(com.sun.identity.saml.plugins.AttributeMapper) DefaultAttributeMapper(com.sun.identity.saml.plugins.DefaultAttributeMapper) PartnerSiteAttributeMapper(com.sun.identity.saml.plugins.PartnerSiteAttributeMapper) ConsumerSiteAttributeMapper(com.sun.identity.saml.plugins.ConsumerSiteAttributeMapper) HashMap(java.util.HashMap) Map(java.util.Map) InetAddress(java.net.InetAddress)

Example 2 with NumberFormatException

use of java.lang.NumberFormatException in project OpenAM by OpenRock.

the class IDPPBaseContainer method getDSTInteger.

/**
      * Gets a JAXB DSTInteger object.
      * @param value a String representing the value.
      * @return DSTInteger JAXB object.
      */
protected DSTInteger getDSTInteger(String value) {
    if (value == null) {
        IDPPUtils.debug.message("IDPPBaseContainer:getDSTInteger:null vals");
        return null;
    }
    try {
        DSTInteger dstInteger = IDPPUtils.getIDPPFactory().createDSTInteger();
        dstInteger.setValue(new BigInteger(value));
        return dstInteger;
    } catch (JAXBException je) {
        IDPPUtils.debug.error("IDPPBaseContainer:getDSTInteger:Error", je);
        return null;
    } catch (NumberFormatException nfe) {
        IDPPUtils.debug.error("IDPPBaseContainer:getDSTInteger: " + "Invalid number", nfe);
        return null;
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) BigInteger(java.math.BigInteger) NumberFormatException(java.lang.NumberFormatException)

Example 3 with NumberFormatException

use of java.lang.NumberFormatException in project platform_packages_providers_telephonyprovider by aosp-mirror.

the class ServiceStateProvider method insert.

@Override
public Uri insert(Uri uri, ContentValues values) {
    if (uri.isPathPrefixMatch(CONTENT_URI)) {
        // Parse the subId
        int subId = 0;
        try {
            subId = Integer.parseInt(uri.getLastPathSegment());
        } catch (NumberFormatException e) {
            Log.e(TAG, "insert: no subId provided in uri");
            throw e;
        }
        Log.d(TAG, "subId=" + subId);
        // handle DEFAULT_SUBSCRIPTION_ID
        if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
            subId = getDefaultSubId();
        }
        // create the new service state
        ServiceState newSS = new ServiceState();
        newSS.setVoiceRegState(values.getAsInteger(VOICE_REG_STATE));
        newSS.setDataRegState(values.getAsInteger(DATA_REG_STATE));
        newSS.setVoiceOperatorName(values.getAsString(VOICE_OPERATOR_ALPHA_LONG), values.getAsString(VOICE_OPERATOR_ALPHA_SHORT), values.getAsString(VOICE_OPERATOR_NUMERIC));
        newSS.setDataOperatorName(values.getAsString(DATA_OPERATOR_ALPHA_LONG), values.getAsString(DATA_OPERATOR_ALPHA_SHORT), values.getAsString(DATA_OPERATOR_NUMERIC));
        newSS.setIsManualSelection(values.getAsBoolean(IS_MANUAL_NETWORK_SELECTION));
        newSS.setRilVoiceRadioTechnology(values.getAsInteger(RIL_VOICE_RADIO_TECHNOLOGY));
        newSS.setRilDataRadioTechnology(values.getAsInteger(RIL_DATA_RADIO_TECHNOLOGY));
        newSS.setCssIndicator(values.getAsInteger(CSS_INDICATOR));
        newSS.setCdmaSystemAndNetworkId(values.getAsInteger(SYSTEM_ID), values.getAsInteger(NETWORK_ID));
        newSS.setCdmaRoamingIndicator(values.getAsInteger(CDMA_ROAMING_INDICATOR));
        newSS.setCdmaDefaultRoamingIndicator(values.getAsInteger(CDMA_DEFAULT_ROAMING_INDICATOR));
        newSS.setCdmaEriIconIndex(values.getAsInteger(CDMA_ERI_ICON_INDEX));
        newSS.setCdmaEriIconMode(values.getAsInteger(CDMA_ERI_ICON_MODE));
        newSS.setEmergencyOnly(values.getAsBoolean(IS_EMERGENCY_ONLY));
        newSS.setDataRoamingFromRegistration(values.getAsBoolean(IS_DATA_ROAMING_FROM_REGISTRATION));
        newSS.setIsUsingCarrierAggregation(values.getAsBoolean(IS_USING_CARRIER_AGGREGATION));
        // notify listeners
        // if ss is null (e.g. first service state update) we will notify for all fields
        ServiceState ss = getServiceState(subId);
        notifyChangeForSubIdAndField(getContext(), ss, newSS, subId);
        notifyChangeForSubId(getContext(), ss, newSS, subId);
        // store the new service state
        mServiceStates.put(subId, newSS);
        return uri;
    }
    return null;
}
Also used : ServiceState(android.telephony.ServiceState) NumberFormatException(java.lang.NumberFormatException)

Example 4 with NumberFormatException

use of java.lang.NumberFormatException in project platform_packages_providers_telephonyprovider by aosp-mirror.

the class ServiceStateProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if (!uri.isPathPrefixMatch(CONTENT_URI)) {
        throw new IllegalArgumentException("Invalid URI: " + uri);
    } else {
        // Parse the subId
        int subId = 0;
        try {
            subId = Integer.parseInt(uri.getLastPathSegment());
        } catch (NumberFormatException e) {
            Log.d(TAG, "query: no subId provided in uri, using default.");
            subId = getDefaultSubId();
        }
        Log.d(TAG, "subId=" + subId);
        // handle DEFAULT_SUBSCRIPTION_ID
        if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
            subId = getDefaultSubId();
        }
        // Get the service state
        ServiceState ss = getServiceState(subId);
        if (ss == null) {
            Log.d(TAG, "returning null");
            return null;
        }
        // Build the result
        final int voice_reg_state = ss.getVoiceRegState();
        final int data_reg_state = ss.getDataRegState();
        final int voice_roaming_type = ss.getVoiceRoamingType();
        final int data_roaming_type = ss.getDataRoamingType();
        final String voice_operator_alpha_long = ss.getVoiceOperatorAlphaLong();
        final String voice_operator_alpha_short = ss.getVoiceOperatorAlphaShort();
        final String voice_operator_numeric = ss.getVoiceOperatorNumeric();
        final String data_operator_alpha_long = ss.getDataOperatorAlphaLong();
        final String data_operator_alpha_short = ss.getDataOperatorAlphaShort();
        final String data_operator_numeric = ss.getDataOperatorNumeric();
        final int is_manual_network_selection = (ss.getIsManualSelection()) ? 1 : 0;
        final int ril_voice_radio_technology = ss.getRilVoiceRadioTechnology();
        final int ril_data_radio_technology = ss.getRilDataRadioTechnology();
        final int css_indicator = ss.getCssIndicator();
        final int network_id = ss.getCdmaNetworkId();
        final int system_id = ss.getCdmaSystemId();
        final int cdma_roaming_indicator = ss.getCdmaRoamingIndicator();
        final int cdma_default_roaming_indicator = ss.getCdmaDefaultRoamingIndicator();
        final int cdma_eri_icon_index = ss.getCdmaEriIconIndex();
        final int cdma_eri_icon_mode = ss.getCdmaEriIconMode();
        final int is_emergency_only = (ss.isEmergencyOnly()) ? 1 : 0;
        final int is_data_roaming_from_registration = (ss.getDataRoamingFromRegistration()) ? 1 : 0;
        final int is_using_carrier_aggregation = (ss.isUsingCarrierAggregation()) ? 1 : 0;
        return buildSingleRowResult(projection, sColumns, new Object[] { voice_reg_state, data_reg_state, voice_roaming_type, data_roaming_type, voice_operator_alpha_long, voice_operator_alpha_short, voice_operator_numeric, data_operator_alpha_long, data_operator_alpha_short, data_operator_numeric, is_manual_network_selection, ril_voice_radio_technology, ril_data_radio_technology, css_indicator, network_id, system_id, cdma_roaming_indicator, cdma_default_roaming_indicator, cdma_eri_icon_index, cdma_eri_icon_mode, is_emergency_only, is_data_roaming_from_registration, is_using_carrier_aggregation });
    }
}
Also used : ServiceState(android.telephony.ServiceState) NumberFormatException(java.lang.NumberFormatException)

Example 5 with NumberFormatException

use of java.lang.NumberFormatException in project clojure by clojure.

the class LispReader method readNumber.

private static Object readNumber(PushbackReader r, char initch) {
    StringBuilder sb = new StringBuilder();
    sb.append(initch);
    for (; ; ) {
        int ch = read1(r);
        if (ch == -1 || isWhitespace(ch) || isMacro(ch)) {
            unread(r, ch);
            break;
        }
        sb.append((char) ch);
    }
    String s = sb.toString();
    Object n = matchNumber(s);
    if (n == null)
        throw new NumberFormatException("Invalid number: " + s);
    return n;
}
Also used : StringBuilder(java.lang.StringBuilder) NumberFormatException(java.lang.NumberFormatException) Object(java.lang.Object) String(java.lang.String)

Aggregations

NumberFormatException (java.lang.NumberFormatException)11 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 Paint (android.graphics.Paint)3 Point (android.graphics.Point)3 EditText (android.widget.EditText)3 LinearLayout (android.widget.LinearLayout)3 TextView (android.widget.TextView)3 ServiceState (android.telephony.ServiceState)2 Object (java.lang.Object)2 String (java.lang.String)2 StringBuilder (java.lang.StringBuilder)2 Bundle (android.os.Bundle)1 SeekBar (android.widget.SeekBar)1 OnSeekBarChangeListener (android.widget.SeekBar.OnSeekBarChangeListener)1 ConfigurationException (com.sun.identity.plugin.configuration.ConfigurationException)1 DataStoreProviderException (com.sun.identity.plugin.datastore.DataStoreProviderException)1 ActionMapper (com.sun.identity.saml.plugins.ActionMapper)1 AttributeMapper (com.sun.identity.saml.plugins.AttributeMapper)1 ConsumerSiteAttributeMapper (com.sun.identity.saml.plugins.ConsumerSiteAttributeMapper)1