Search in sources :

Example 66 with SAXException

use of org.xml.sax.SAXException in project android_frameworks_base by ResurrectionRemix.

the class OSUManager method provisioningComplete.

public void provisioningComplete(OSUInfo osuInfo, MOData moData, Map<OSUCertType, List<X509Certificate>> certs, PrivateKey privateKey, Network osuNetwork) {
    synchronized (mWifiNetworkAdapter) {
        mProvisioningThread = null;
    }
    try {
        Log.d("ZXZ", "MOTree.toXML: " + moData.getMOTree().toXml());
        HomeSP homeSP = mWifiNetworkAdapter.addSP(moData.getMOTree());
        Integer spNwk = mWifiNetworkAdapter.addNetwork(homeSP, certs, privateKey, osuNetwork);
        if (spNwk == null) {
            notifyUser(OSUOperationStatus.ProvisioningFailure, "Failed to save network configuration", osuInfo.getName(LOCALE));
            mWifiNetworkAdapter.removeSP(homeSP.getFQDN());
        } else {
            Set<X509Certificate> rootCerts = OSUSocketFactory.getRootCerts(mKeyStore);
            X509Certificate remCert = getCert(certs, OSUCertType.Remediation);
            X509Certificate polCert = getCert(certs, OSUCertType.Policy);
            if (privateKey != null) {
                X509Certificate cltCert = getCert(certs, OSUCertType.Client);
                mKeyStore.setKeyEntry(CERT_CLT_KEY_ALIAS + homeSP, privateKey.getEncoded(), new X509Certificate[] { cltCert });
                mKeyStore.setCertificateEntry(CERT_CLT_CERT_ALIAS, cltCert);
            }
            boolean usingShared = false;
            int newCerts = 0;
            if (remCert != null) {
                if (!rootCerts.contains(remCert)) {
                    if (remCert.equals(polCert)) {
                        mKeyStore.setCertificateEntry(CERT_SHARED_ALIAS + homeSP.getFQDN(), remCert);
                        usingShared = true;
                        newCerts++;
                    } else {
                        mKeyStore.setCertificateEntry(CERT_REM_ALIAS + homeSP.getFQDN(), remCert);
                        newCerts++;
                    }
                }
            }
            if (!usingShared && polCert != null) {
                if (!rootCerts.contains(polCert)) {
                    mKeyStore.setCertificateEntry(CERT_POLICY_ALIAS + homeSP.getFQDN(), remCert);
                    newCerts++;
                }
            }
            if (newCerts > 0) {
                try (FileOutputStream out = new FileOutputStream(KEYSTORE_FILE)) {
                    mKeyStore.store(out, null);
                }
            }
            notifyUser(OSUOperationStatus.ProvisioningSuccess, null, osuInfo.getName(LOCALE));
            Log.d(TAG, "Provisioning complete.");
        }
    } catch (IOException | GeneralSecurityException | SAXException e) {
        Log.e(TAG, "Failed to provision: " + e, e);
        notifyUser(OSUOperationStatus.ProvisioningFailure, e.toString(), osuInfo.getName(LOCALE));
    }
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileOutputStream(java.io.FileOutputStream) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate) SAXException(org.xml.sax.SAXException)

Example 67 with SAXException

use of org.xml.sax.SAXException in project android_frameworks_base by ResurrectionRemix.

the class SubscriptionTimer method checkUpdates.

public void checkUpdates() {
    mHandler.removeCallbacks(this);
    long now = System.currentTimeMillis();
    long next = Long.MAX_VALUE;
    Collection<HomeSP> homeSPs = mWifiNetworkAdapter.getLoadedSPs();
    if (homeSPs.isEmpty()) {
        return;
    }
    for (HomeSP homeSP : homeSPs) {
        UpdateAction updateAction = mOutstanding.get(homeSP);
        try {
            if (updateAction == null) {
                updateAction = new UpdateAction(homeSP, now);
                mOutstanding.put(homeSP, updateAction);
            } else if (updateAction.remediate(now)) {
                mOSUManager.remediate(homeSP, false);
                mOutstanding.put(homeSP, new UpdateAction(homeSP, now));
            } else if (updateAction.policyUpdate(now)) {
                mOSUManager.remediate(homeSP, true);
                mOutstanding.put(homeSP, new UpdateAction(homeSP, now));
            }
            next = Math.min(next, updateAction.nextExpiry(now));
        } catch (IOException | SAXException e) {
            Log.d(OSUManager.TAG, "Failed subscription update: " + e.getMessage());
        }
    }
    setAlarm(next);
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 68 with SAXException

use of org.xml.sax.SAXException in project android_frameworks_base by ResurrectionRemix.

the class OMAParser method parse.

public MOTree parse(String text, String urn) throws IOException, SAXException {
    try {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        parser.parse(new InputSource(new StringReader(text)), this);
        return new MOTree(mRoot, urn);
    } catch (ParserConfigurationException pce) {
        throw new SAXException(pce);
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 69 with SAXException

use of org.xml.sax.SAXException in project OpenAM by OpenRock.

the class SAXUnmarshallerHandlerImpl method handleEvent.

public void handleEvent(ValidationEvent event, boolean canRecover) throws SAXException {
    ValidationEventHandler eventHandler;
    try {
        eventHandler = parent.getEventHandler();
    } catch (JAXBException e) {
        // impossible.
        throw new JAXBAssertionError();
    }
    boolean recover = eventHandler.handleEvent(event);
    // from the unmarshaller.getResult()
    if (!recover)
        aborted = true;
    if (!canRecover || !recover)
        throw new SAXException(new UnmarshalException(event.getMessage(), event.getLinkedException()));
}
Also used : ValidationEventHandler(javax.xml.bind.ValidationEventHandler) JAXBAssertionError(com.sun.xml.bind.JAXBAssertionError) UnmarshalException(javax.xml.bind.UnmarshalException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException)

Example 70 with SAXException

use of org.xml.sax.SAXException in project OpenAM by OpenRock.

the class UnmarshallerImpl method unmarshal.

public final Object unmarshal(Node node) throws JAXBException {
    try {
        DOMScanner scanner = new DOMScanner();
        UnmarshallerHandler handler = new InterningUnmarshallerHandler(createUnmarshallerHandler(new DOMLocator(scanner)));
        if (node instanceof Element)
            scanner.parse((Element) node, handler);
        else if (node instanceof Document)
            scanner.parse(((Document) node).getDocumentElement(), handler);
        else
            // no other type of input is supported
            throw new IllegalArgumentException();
        return handler.getResult();
    } catch (SAXException e) {
        throw createUnmarshalException(e);
    }
}
Also used : DOMScanner(com.sun.xml.bind.unmarshaller.DOMScanner) Element(org.w3c.dom.Element) UnmarshallerHandler(javax.xml.bind.UnmarshallerHandler) DOMLocator(com.sun.xml.bind.validator.DOMLocator) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Aggregations

SAXException (org.xml.sax.SAXException)2465 IOException (java.io.IOException)1622 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1049 Document (org.w3c.dom.Document)682 DocumentBuilder (javax.xml.parsers.DocumentBuilder)537 InputSource (org.xml.sax.InputSource)518 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)415 InputStream (java.io.InputStream)317 Element (org.w3c.dom.Element)311 NodeList (org.w3c.dom.NodeList)292 File (java.io.File)274 Node (org.w3c.dom.Node)247 ByteArrayInputStream (java.io.ByteArrayInputStream)235 StringReader (java.io.StringReader)224 SAXParser (javax.xml.parsers.SAXParser)209 SAXParseException (org.xml.sax.SAXParseException)196 TransformerException (javax.xml.transform.TransformerException)180 ArrayList (java.util.ArrayList)169 SAXParserFactory (javax.xml.parsers.SAXParserFactory)159 XMLReader (org.xml.sax.XMLReader)151