From 8157f26401ed333be6b705736a48e4624852e3d8 Mon Sep 17 00:00:00 2001 From: Asok Date: Sun, 18 Jan 2015 12:10:35 +0530 Subject: [PATCH 1/5] updating windows plugin --- .../cdm/api/windows/DiscoveryService.java | 47 --- .../cdm/api/windows/EnrolmentService.java | 43 --- .../windows/impl/DiscoveryServiceImpl.java | 72 ----- .../windows/impl/EnrolmentServiceImpl.java | 305 ------------------ .../util/CertificateSigningService.java | 92 ------ .../cdm/api/windows/util/WindowsAPIUtil.java | 45 --- .../src/main/resources/applicationContext.xml | 52 --- .../jax-rs/src/main/resources/ca_cert.pem | 20 -- .../jax-rs/src/main/resources/ca_private.key | 27 -- .../src/main/resources/discover-service.xml | 27 -- .../src/main/resources/enrollment-service.xml | 27 -- .../jax-rs/src/main/resources/log4j.xml | 50 --- .../src/main/resources/policy-service.xml | 15 - .../src/main/resources/wap-provisioning.xml | 80 ----- .../resources/windows-mdm-server.properties | 8 - 15 files changed, 910 deletions(-) delete mode 100644 product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/DiscoveryService.java delete mode 100644 product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/EnrolmentService.java delete mode 100644 product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/DiscoveryServiceImpl.java delete mode 100644 product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/EnrolmentServiceImpl.java delete mode 100644 product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/util/CertificateSigningService.java delete mode 100644 product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/util/WindowsAPIUtil.java delete mode 100644 product/modules/agents/windows/jax-rs/src/main/resources/applicationContext.xml delete mode 100644 product/modules/agents/windows/jax-rs/src/main/resources/ca_cert.pem delete mode 100644 product/modules/agents/windows/jax-rs/src/main/resources/ca_private.key delete mode 100644 product/modules/agents/windows/jax-rs/src/main/resources/discover-service.xml delete mode 100644 product/modules/agents/windows/jax-rs/src/main/resources/enrollment-service.xml delete mode 100644 product/modules/agents/windows/jax-rs/src/main/resources/log4j.xml delete mode 100644 product/modules/agents/windows/jax-rs/src/main/resources/policy-service.xml delete mode 100644 product/modules/agents/windows/jax-rs/src/main/resources/wap-provisioning.xml delete mode 100644 product/modules/agents/windows/jax-rs/src/main/resources/windows-mdm-server.properties diff --git a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/DiscoveryService.java b/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/DiscoveryService.java deleted file mode 100644 index 64cd0e8ecbe..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/DiscoveryService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package cdm.api.windows; - -import javax.ws.rs.*; -import javax.ws.rs.core.Response; -import java.io.InputStream; - -@Path("/EnrollmentServer") -public interface DiscoveryService { - - @Path("/Discovery.svc") - @POST - @Consumes({ "application/soap+xml;charset=utf-8", "application/xml" }) - @Produces("application/soap+xml;charset=utf-8") - Response getDiscoveryResponse( - InputStream discoveryRequest); - - @Path("/Discovery.svc") - @GET - @Consumes("text/html") - @Produces("text/html") - Response getDiscoveryOKRequest(); - - @Path("/Discovery.svc") - @GET - @Consumes({ "application/soap+xml;charset=utf-8", "application/xml" }) - @Produces("text/html") - Response getDiscoveryOKRequestWithBody(InputStream discoveryRequest); - -} diff --git a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/EnrolmentService.java b/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/EnrolmentService.java deleted file mode 100644 index 9a61a3c61df..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/EnrolmentService.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package cdm.api.windows; - -import javax.swing.text.Document; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; - -@Path("/ENROLLMENTSERVER") -public interface EnrolmentService { - - @Path("/PolicyEnrollmentWebservice.svc") - @POST - @Consumes("application/soap+xml;charset=utf-8") - @Produces("application/soap+xml;charset=utf-8") - Response getPolicies(Document request); - - @Path("/DeviceEnrollmentWebservice.svc") - @POST - @Consumes("application/soap+xml;charset=utf-8") - @Produces("application/soap+xml;charset=utf-8") - Response enrollUser(Document request); - -} diff --git a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/DiscoveryServiceImpl.java b/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/DiscoveryServiceImpl.java deleted file mode 100644 index 59de66ae0f9..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/DiscoveryServiceImpl.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package cdm.api.windows.impl; - -import cdm.api.windows.DiscoveryService; - -import javax.ws.rs.core.Response; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - - -import org.apache.log4j.Logger; - -public class DiscoveryServiceImpl implements DiscoveryService { - - private Logger LOGGER = Logger.getLogger(DiscoveryServiceImpl.class); - - public Response getDiscoveryResponse(InputStream discoveryRequest) { - LOGGER.info("Received Discovery Service POST Request [{}]"); - - String response = null; - File file = null; - FileInputStream fis = null; - byte[] data = null; - - try { - - file = new File("./conf/discover-service.xml"); - fis = new FileInputStream(file); - data = new byte[(int) file.length()]; - fis.read(data); - fis.close(); - response = new String(data, "UTF-8"); - - } catch (IOException e) { - LOGGER.error("An Unexpected Error has occurred while processing the request ", e); - } - LOGGER.info("Sending Discovery Response"); - - return Response.ok().entity(response).build(); - } - - public Response getDiscoveryOKRequest() { - LOGGER.info("Received a GET Request without body"); - return Response.ok().build(); - } - - public Response getDiscoveryOKRequestWithBody(InputStream discoveryRequest) { - LOGGER.info("Received a GET Request with body [{}]"); - return Response.ok().build(); - } - - -} diff --git a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/EnrolmentServiceImpl.java b/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/EnrolmentServiceImpl.java deleted file mode 100644 index c3acde83871..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/impl/EnrolmentServiceImpl.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package cdm.api.windows.impl; - -import cdm.api.windows.EnrolmentService; -import org.apache.log4j.Logger; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.bouncycastle.pkcs.PKCS10CertificationRequest; -import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import sun.misc.BASE64Decoder; -import sun.misc.BASE64Encoder; -import javax.swing.text.Document; -import javax.ws.rs.core.Response; -import javax.xml.namespace.NamespaceContext; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathFactory; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.StringWriter; -import java.security.KeyFactory; -import java.security.PrivateKey; -import java.security.Security; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.security.spec.PKCS8EncodedKeySpec; -import java.util.Iterator; - -import cdm.api.windows.util.CertificateSigningService; - -public class EnrolmentServiceImpl implements EnrolmentService { - - private Logger LOGGER = Logger.getLogger(EnrolmentServiceImpl.class); - - static { - Security.addProvider(new BouncyCastleProvider()); - } - - private String enrollmentResponseFile; - - private String wapProvisioningXmlFile; - - private String privatePemKeyFilePath; - - private String caCertificateFilePath; - - PrivateKey privateKey; - - X509Certificate rooCACertificate; - - public void init() { - - try { - FileInputStream in = new FileInputStream(privatePemKeyFilePath); - byte[] keyBytes = new byte[in.available()]; - in.read(keyBytes); - in.close(); - - String key = new String(keyBytes, "UTF-8"); - key = key.replaceAll( - "(-+BEGIN RSA PRIVATE KEY-+\\r?\\n|-+END RSA PRIVATE KEY-+\\r?\\n?)", ""); - - // don't use this for real projects! - BASE64Decoder decoder = new BASE64Decoder(); - keyBytes = decoder.decodeBuffer(key); - - // generate private key - - PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes); - KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - - privateKey = keyFactory.generatePrivate(spec); - - LOGGER.info("Private Key Algorithm : " + privateKey.getAlgorithm()); - } catch (Exception e) { - LOGGER.error("An unexpected Error has occurred while reading CA Private Key, ", e); - } - - try { - FileInputStream fr = new FileInputStream(caCertificateFilePath); - CertificateFactory cf = CertificateFactory.getInstance("X509"); - rooCACertificate = (X509Certificate) cf.generateCertificate(fr); - - rooCACertificate.verify(rooCACertificate.getPublicKey()); - - LOGGER.info("CA Certificate Expiration Date : " + rooCACertificate.getNotAfter()); - - } catch (Exception e) { - LOGGER.error("An unexpected Error has occurred while reading CA Root Certificate, ", e); - } - - /*try { - KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA"); - gen.initialize(2048); - key = gen.generateKeyPair(); - PrivateKey privateKey = key.getPrivate(); - PublicKey publicKey = key.getPublic(); - - - *//** - * Following details need to be provided - * - * Serial number - * Signature algorithm - * Issuer Name. - * Subject Name -- or a Subject Alternative Name (SAN). - * Date range (not before, not after). - * Subject Public Key. - *//* - - X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator(); - v3CertGen.setSerialNumber(BigInteger.valueOf(new SecureRandom().nextInt(Integer.MAX_VALUE))); - v3CertGen.setIssuerDN(new X509Principal("CN=wso2.com")); - //v3CertGen.setIssuerDN(new X509Principal("CN=wso2.com, OU=Mobile, O=wso2 L=Colombo, C=LK")); - v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30)); - v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365*10))); - v3CertGen.setSubjectDN(new X509Principal("CN=wso2.com")); - v3CertGen.setPublicKey(publicKey); - v3CertGen.setSignatureAlgorithm("SHA1withRSA"); - - rooCACertificate = v3CertGen.generateX509Certificate(privateKey); - - } catch (Exception e) { - e.printStackTrace(); - }*/ - } - - public Response getPolicies(Document request) { - LOGGER.info("Received Get Policies Request"); - - String response = null; - File file = null; - FileInputStream fis = null; - byte[] data = null; - - try { - - file = new File("./conf/policy-service.xml"); - fis = new FileInputStream(file); - data = new byte[(int) file.length()]; - fis.read(data); - fis.close(); - response = new String(data, "UTF-8"); - - } catch (IOException e) { - LOGGER.error("An Unexpected Error has occurred while processing the request ", e); - } - - LOGGER.info("Sending Get Policy Response"); - return Response.ok().entity(response).build(); - } - - public Response enrollUser(Document request) { - LOGGER.info("Received User Enrollment Request"); - - XPath xPath = XPathFactory.newInstance().newXPath(); - xPath.setNamespaceContext(new MyNamespaceContext()); - String response = null; - - DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); - - try { - NodeList nl = (NodeList) xPath.evaluate( - "/s:Envelope/s:Body/wst:RequestSecurityToken/wsse:BinarySecurityToken", request, - XPathConstants.NODESET); - Node node = nl.item(0); - String certificateDataString = node.getTextContent(); - byte[] derByteArray = - javax.xml.bind.DatatypeConverter.parseBase64Binary(certificateDataString); - - PKCS10CertificationRequest certificationRequest = - new PKCS10CertificationRequest(derByteArray); - JcaPKCS10CertificationRequest csrReq = - new JcaPKCS10CertificationRequest(certificationRequest); - - LOGGER.info("Public Key of CSR : " + csrReq.getPublicKey()); - - X509Certificate signedCert = - CertificateSigningService.signCSR(csrReq, privateKey, rooCACertificate); - - LOGGER.info("Verifying Signed Certificate with CSR's public key : " + - signedCert.getPublicKey()); - - BASE64Encoder base64Encoder = new BASE64Encoder(); - String rootCertEncodedString = base64Encoder.encode(rooCACertificate.getEncoded()); - String signedCertEncoded = base64Encoder.encode(signedCert.getEncoded()); - - DocumentBuilder builder = domFactory.newDocumentBuilder(); - org.w3c.dom.Document dDoc = builder.parse(wapProvisioningXmlFile); - - NodeList wapParm = dDoc.getElementsByTagName("parm"); - - NamedNodeMap rootCertAttributes = wapParm.item(0).getAttributes(); - Node b64Encoded = rootCertAttributes.getNamedItem("value"); - b64Encoded.setTextContent(rootCertEncodedString); - - NamedNodeMap clientCertAttributes = wapParm.item(1).getAttributes(); - Node b64CliendEncoded = clientCertAttributes.getNamedItem("value"); - b64CliendEncoded.setTextContent(signedCertEncoded); - - String wapProvisioning = convertDocumentToString(dDoc); - String encodedWap = base64Encoder.encode(wapProvisioning.getBytes()); - - org.w3c.dom.Document responseXml = builder.parse(enrollmentResponseFile); - NodeList token = responseXml.getElementsByTagName("BinarySecurityToken"); - - Node firstToken = token.item(0); - firstToken.setTextContent(encodedWap); - - response = convertDocumentToString(responseXml); - } catch (Exception e) { - LOGGER.error("An Unexpected Error has occurred while processing the request ", e); - } - - LOGGER.info("Sending User Enrollment Response"); - return Response.ok().entity(response).build(); - } - - private String convertDocumentToString(org.w3c.dom.Document document) throws Exception { - DOMSource domSource = new DOMSource(document); - StringWriter writer = new StringWriter(); - StreamResult result = new StreamResult(writer); - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - transformer.transform(domSource, result); - String wapProvisioning = writer.toString(); - - return wapProvisioning; - - } - - public void setEnrollmentResponseFile(String enrollmentResponseFile) { - this.enrollmentResponseFile = enrollmentResponseFile; - } - - public void setWapProvisioningXmlFile(String wapProvisioningXmlFile) { - this.wapProvisioningXmlFile = wapProvisioningXmlFile; - } - - public void setPrivatePemKeyFilePath(String privatePemKeyFilePath) { - this.privatePemKeyFilePath = privatePemKeyFilePath; - } - - public void setCaCertificateFilePath(String caCertificateFilePath) { - this.caCertificateFilePath = caCertificateFilePath; - } - - public void setPrivateKey(PrivateKey privateKey) { - this.privateKey = privateKey; - } - - public void setRooCACertificate(X509Certificate rooCACertificate) { - this.rooCACertificate = rooCACertificate; - } - - private static class MyNamespaceContext implements NamespaceContext { - - public String getNamespaceURI(String prefix) { - - if ("s".equals(prefix)) { - return "http://www.w3.org/2003/05/soap-envelope"; - } else if ("wst".equals(prefix)) { - return "http://docs.oasis-open.org/ws-sx/ws-trust/200512"; - } else if ("wsse".equals(prefix)) { - return "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; - } - return null; - - } - - public String getPrefix(String namespaceURI) { - return null; - } - - public Iterator getPrefixes(String namespaceURI) { - return null; - } - } -} diff --git a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/util/CertificateSigningService.java b/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/util/CertificateSigningService.java deleted file mode 100644 index 6b006940977..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/util/CertificateSigningService.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package cdm.api.windows.util; - -import org.apache.log4j.Logger; -import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.cert.X509v3CertificateBuilder; -import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; -import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils; -import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder; -import org.bouncycastle.operator.ContentSigner; -import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; -import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest; - -import java.math.BigInteger; -import java.security.PrivateKey; -import java.security.SecureRandom; -import java.security.cert.X509Certificate; -import java.util.Date; - -public class CertificateSigningService { - - private static Logger LOGGER = Logger.getLogger(CertificateSigningService.class); - - public static X509Certificate signCSR(JcaPKCS10CertificationRequest jcaRequest, - PrivateKey privateKey, X509Certificate caCert) - throws Exception { - try { - - X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(caCert, - BigInteger - .valueOf( - new SecureRandom() - .nextInt( - Integer.MAX_VALUE)), - new Date( - System.currentTimeMillis() - - 1000L * - 60 * - 60 * - 24 * - 30), - new Date( - System.currentTimeMillis() + - (1000L * - 60 * - 60 * - 24 * - 365 * - 10)), - new X500Name( - "CN=abimaran"), - jcaRequest - .getPublicKey()); - - JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils(); - - ContentSigner signer = - new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(privateKey); - - X509Certificate theCert = - new JcaX509CertificateConverter().setProvider("BC").getCertificate( - certificateBuilder.build(signer)); - - LOGGER.info("Signed Certificate CN : " + theCert.getSubjectDN().getName()); - - LOGGER.info("Signed CSR's public key : " + theCert.getPublicKey()); - - return theCert; - - } catch (Exception e) { - throw new Exception("Error in signing the certificate", e); - } - } - -} diff --git a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/util/WindowsAPIUtil.java b/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/util/WindowsAPIUtil.java deleted file mode 100644 index ca784e18951..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/java/cdm/api/windows/util/WindowsAPIUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package cdm.api.windows.util; - - -import com.google.gson.JsonObject; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; - - -/** - * WindowsAPIUtil class provides utility function used by Android REST-API classes. - */ -public class WindowsAPIUtil { - - public static Device convertToDeviceObject(JsonObject json){ - Device device = new Device(); - device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - device.setName("Test Device"); - device.setOwner("harshan"); - return device; - } - - public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId){ - DeviceIdentifier identifier = new DeviceIdentifier(); - identifier.setId(deviceId); - identifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - return identifier; - } -} diff --git a/product/modules/agents/windows/jax-rs/src/main/resources/applicationContext.xml b/product/modules/agents/windows/jax-rs/src/main/resources/applicationContext.xml deleted file mode 100644 index 5dd63f2c881..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/resources/applicationContext.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/product/modules/agents/windows/jax-rs/src/main/resources/ca_cert.pem b/product/modules/agents/windows/jax-rs/src/main/resources/ca_cert.pem deleted file mode 100644 index 6eaad0f5705..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/resources/ca_cert.pem +++ /dev/null @@ -1,20 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDXDCCAkQCCQDWxw0vNF9H8DANBgkqhkiG9w0BAQUFADBwMQswCQYDVQQGEwJM -SzEQMA4GA1UECBMHQ29sb21ibzEQMA4GA1UEBxMHQ29sb21ibzENMAsGA1UEChME -d3NvMjEPMA0GA1UECxMGbW9iaWxlMR0wGwYDVQQDFBRjYV93c28yV2luZG93c01v -YmlsZTAeFw0xNDA3MDcxMDE4MDhaFw0xNTA3MDcxMDE4MDhaMHAxCzAJBgNVBAYT -AkxLMRAwDgYDVQQIEwdDb2xvbWJvMRAwDgYDVQQHEwdDb2xvbWJvMQ0wCwYDVQQK -EwR3c28yMQ8wDQYDVQQLEwZtb2JpbGUxHTAbBgNVBAMUFGNhX3dzbzJXaW5kb3dz -TW9iaWxlMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz+w93X1S8nOM -VM3ScGP8XY9+PnoUaFZgKaD3d9Z6cj4HPKjIzv8iTMx9JBfDjSsLiks5nJqxm1in -juck7n0tl/CZ5L2j/3DhsA4D0Ngp5JsH5ZF+Vu2T+z8wUq8UwGD6qsn/EP9jBbj/ -WN0TtOPcfhOhfJVxaNOrt+9htYad9WOeU8Rh+CIb5oQrigEd417e5d5j4wcU8QLj -sVQQ8WRCYDrnKKof834ZnViBYX4UAdLtXkWFtKcD0RM/cB2LdjydwP3HEj6pkwjT -hRLGHdVF21VCbKOF6mnQagvuseT/ynioBNY60TXb283BQ6YrDfMytvRuzguEQ/7/ -AsTPclNZxQIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQB3cwy5pibn009WvAYzmw9B -oB77bt21GQO4gFLJlNkvIRrneE5SinjoO6ezWOgY3+8t9ViNeD874momq4kuE6Hb -XDZE1qqinJlqfMJQuEaFkDZKg55kO66wy5+8ioFhA9V8SpeM+SYy3ENBucxiDLQE -ZhM7RKJCpSIq0rRHJyBRbs6GoW7cOB5QQcFDfSW+/CajicWzeD/OJMIfjJezCsZ8 -GNXJpyAS/Te+ysHlfmrKMb1VMZphFNiTmpEx8OI8F/kbhmdwePaZ3SOw2kJp8e3v -Ke4/zPwB95wjz8luzU+PbqNO2K4ZKtXHk6rx5yybR1UBpYINvUEjsRI3hgy1IoE+ ------END CERTIFICATE----- diff --git a/product/modules/agents/windows/jax-rs/src/main/resources/ca_private.key b/product/modules/agents/windows/jax-rs/src/main/resources/ca_private.key deleted file mode 100644 index 764b3166303..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/resources/ca_private.key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAz+w93X1S8nOMVM3ScGP8XY9+PnoUaFZgKaD3d9Z6cj4HPKjI -zv8iTMx9JBfDjSsLiks5nJqxm1injuck7n0tl/CZ5L2j/3DhsA4D0Ngp5JsH5ZF+ -Vu2T+z8wUq8UwGD6qsn/EP9jBbj/WN0TtOPcfhOhfJVxaNOrt+9htYad9WOeU8Rh -+CIb5oQrigEd417e5d5j4wcU8QLjsVQQ8WRCYDrnKKof834ZnViBYX4UAdLtXkWF -tKcD0RM/cB2LdjydwP3HEj6pkwjThRLGHdVF21VCbKOF6mnQagvuseT/ynioBNY6 -0TXb283BQ6YrDfMytvRuzguEQ/7/AsTPclNZxQIDAQABAoIBAQCrNz+Od1fpnOrv -Hnnu4Pb82F+99Ot/K7mOLiX6Qdyc3KU690Y85m2JTk6yfPsj8VFUdTOg2OXuJWf9 -TivkU6JK3u7rJJq6i2rdffz4aji9Lkina1LdJFBacaNKQzBUZsekAiiPB660FK34 -sDw9FfIIxAOTwsAb8UoTcgVE5PCIEx7R7YdAI0/mMnd98kTc2YdcnAmGwrDFQNer -eOLhq8H/6SxUADyos3s6Tgw3/yIo9BnBpe8uPNoakEPgYJLh263uF2rJ2h0+yLDV -9F9by+yFCqyVqS8P06NI+NMe8WsYJo99RGQsLZ7PsI5jiJSTRYgOF4ROQfAcCZiK -UWKCwcwhAoGBAPOg32J8AZX64FFDqyruN/1Q6hJfkVAVM+B3dxNAYIpccLuuxJ7x -JMIWkAFfBlOoaXZzxaDIXmXrd3h5qxRTd6W/gAR9nRko7YHaK7NszpEPA8hVOjjx -kkTNs/KjlELrLspRWL+iDqR5Nscw0V9y2D6tyYuGp475wK4PmKbgcKAdAoGBANp7 -M9nFEAUTeHzdo9csbrGy6wUuCRlixFvXKOH+1ezeuNvxh0XtbJPj7FrPT4nuCKEV -Wud1w3/IRaeCYeKXaHk6eF8zN1gVkN0MAQJ+9KtfZ0QnmQSsluJfrUBGej6UYO0z -DUv5CLNYLPwOVGTb/jb5n+lY2IzjKmA+aWZRML/JAoGBAJSfUycVVzJTdXydt1Hd -OTLDpcfHnTIpfRg2SOHpp/tAIVWdbD06Bp6QfREZExb96jhkr+9BzLSITL2mG4Ou -15K5nDMhHjE3Eozgt0Ah5HIBouEXfQk39W8bvecLe2rHZifuMCHXju8vMweY9GEy -AlFaW1VOs/E40x5cTVegG5TRAoGANLxmUJtTeZYwkBtDr+2GrpfcSLzK73i6otx1 -fs9vPaSpBFXxa/yaJ7xtUaIWtdlh9dfcwF/Zl590yLEdBX+8dP6bDYekRTu3YtPB -7qNMVY1KtNXGBq3OIcgsXoZkfXR9TOP0wrDS289d1F11G39KhmSMp9uNMbynfuGx -uUPBu5kCgYA1UUtQkVPbkKaaopSrDkqAJDlsUnNVkvXH5yWqdAYI2Frw1iOwhED3 -cKmwAejf8nl1HPwfDTGQMRB5PCDkK7mWJ5w9W4MUbJ7ZiNPHloZutUTcw3Nz58cn -OZMZGR/Trtn+YLoj2526NPwKqlw0bRB27UR0KOdgPOHynI3uYPnwgQ== ------END RSA PRIVATE KEY----- diff --git a/product/modules/agents/windows/jax-rs/src/main/resources/discover-service.xml b/product/modules/agents/windows/jax-rs/src/main/resources/discover-service.xml deleted file mode 100644 index 05f8f939b90..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/resources/discover-service.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - http://schemas.microsoft.com/windows/management/2012/01/enrollment/IDiscoveryService/DiscoverResponse - - - d9eb2fdd-e38a-46ee-bd93-aea9dc86a3b8 - - urn:uuid: 748132ec-a575-4329-b01b-6171a9cf8478 - - - - - OnPremise - - https://EnterpriseEnrollment.wso2.com/ENROLLMENTSERVER/PolicyEnrollmentWebservice.svc - - - https://EnterpriseEnrollment.wso2.com/ENROLLMENTSERVER/DeviceEnrollmentWebservice.svc - - - - - \ No newline at end of file diff --git a/product/modules/agents/windows/jax-rs/src/main/resources/enrollment-service.xml b/product/modules/agents/windows/jax-rs/src/main/resources/enrollment-service.xml deleted file mode 100644 index 4be6e477ac2..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/resources/enrollment-service.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - http://schemas.microsoft.com/windows/pki/2009/01/enrollment/RSTRC/wstep - urn:uuid:81a5419a-496b-474f-a627-5cdd33eed8ab - - - 2012-08-02T00:32:59.420Z - 2014-08-02T00:37:59.420Z - - - - - - - http://schemas.microsoft.com/5.0.0.0/ConfigurationManager/Enrollment/DeviceEnrollmentToken - - - - - 0 - - - - \ No newline at end of file diff --git a/product/modules/agents/windows/jax-rs/src/main/resources/log4j.xml b/product/modules/agents/windows/jax-rs/src/main/resources/log4j.xml deleted file mode 100644 index 7cd7d64125b..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/resources/log4j.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/product/modules/agents/windows/jax-rs/src/main/resources/policy-service.xml b/product/modules/agents/windows/jax-rs/src/main/resources/policy-service.xml deleted file mode 100644 index e38440d6bdf..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/resources/policy-service.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - http://schemas.microsoft.com/windows/pki/2009/01/enrollmentpolicy/IPolicy/GetPoliciesResponse - - - - - - - - \ No newline at end of file diff --git a/product/modules/agents/windows/jax-rs/src/main/resources/wap-provisioning.xml b/product/modules/agents/windows/jax-rs/src/main/resources/wap-provisioning.xml deleted file mode 100644 index d51958a7155..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/resources/wap-provisioning.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/product/modules/agents/windows/jax-rs/src/main/resources/windows-mdm-server.properties b/product/modules/agents/windows/jax-rs/src/main/resources/windows-mdm-server.properties deleted file mode 100644 index 6f092e31fb2..00000000000 --- a/product/modules/agents/windows/jax-rs/src/main/resources/windows-mdm-server.properties +++ /dev/null @@ -1,8 +0,0 @@ -service.url=http://0.0.0.0:9090 - - -discovery.service.file.location=./conf/discover-service.xml -policy.certificate.file.location=./conf/policy-service.xml -enrollment.service.file.location=./conf/enrollment-service.xml - -enrollment.service.wap.provisioning.file.location=./conf/wap-provisioning.xml \ No newline at end of file From 8de9a702d780a0078b8ad2937f23808fd21bf43b Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Tue, 20 Jan 2015 13:48:20 +0530 Subject: [PATCH 2/5] added authentication response handler, comment fixes --- .../cdm/agent/AuthenticationActivity.java | 245 ++++++++---------- .../src/org/wso2/cdm/agent/ServerDetails.java | 62 +++-- .../org/wso2/cdm/agent/utils/Constant.java | 27 ++ 3 files changed, 171 insertions(+), 163 deletions(-) create mode 100644 product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Constant.java diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationActivity.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationActivity.java index 6620526626f..c47ba61671e 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationActivity.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/AuthenticationActivity.java @@ -28,6 +28,7 @@ import org.wso2.cdm.agent.proxy.IdentityProxy; import org.wso2.cdm.agent.services.AlarmReceiver; import org.wso2.cdm.agent.utils.CommonDialogUtils; import org.wso2.cdm.agent.utils.CommonUtilities; +import org.wso2.cdm.agent.utils.Constant; import org.wso2.cdm.agent.utils.HTTPConnectorUtils; import org.wso2.cdm.agent.utils.Preference; import org.wso2.cdm.agent.utils.ServerUtils; @@ -66,24 +67,26 @@ import com.actionbarsherlock.view.MenuItem; import com.google.android.gcm.GCMRegistrar; /** - * Activity that captures username, password and device ownership details + * Activity that captures username, password and device ownership details. */ public class AuthenticationActivity extends SherlockActivity implements APIAccessCallBack, APIResultCallBack { + private String TAG = AuthenticationActivity.class.getSimpleName(); - Button authenticate; - EditText username; - EditText txtDomain; - EditText password; + Button btnRegister; + EditText etUsername; + EditText etDomain; + EditText etPassword; RadioButton radioBYOD, radioCOPE; String deviceType; Context context; - String senderId = ""; - String usernameForRegister = ""; + String senderId; + String usernameForRegister; String usernameVal; String passwordVal; + String domain; ProgressDialog progressDialog; AlertDialog.Builder alertDialog; @@ -103,21 +106,21 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces context = AuthenticationActivity.this; deviceType = getResources().getString(R.string.device_enroll_type_byod); - txtDomain = (EditText) findViewById(R.id.txtDomain); - username = (EditText) findViewById(R.id.username); - password = (EditText) findViewById(R.id.editText2); + etDomain = (EditText) findViewById(R.id.etDomain); + etUsername = (EditText) findViewById(R.id.etUsername); + etPassword = (EditText) findViewById(R.id.etPassword); radioBYOD = (RadioButton) findViewById(R.id.radioBYOD); radioCOPE = (RadioButton) findViewById(R.id.radioCOPE); - txtDomain.setFocusable(true); - txtDomain.requestFocus(); - authenticate = (Button) findViewById(R.id.btnRegister); - authenticate.setEnabled(false); - authenticate.setOnClickListener(onClickAuthenticate); + etDomain.setFocusable(true); + etDomain.requestFocus(); + btnRegister = (Button) findViewById(R.id.btnRegister); + btnRegister.setEnabled(false); + btnRegister.setOnClickListener(onClickAuthenticate); // change button color background till user enters a valid input - authenticate.setBackground(getResources().getDrawable(R.drawable.btn_grey)); - authenticate.setTextColor(getResources().getColor(R.color.black)); + btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_grey)); + btnRegister.setTextColor(getResources().getColor(R.color.black)); - username.addTextChangedListener(new TextWatcher() { + etUsername.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @@ -133,7 +136,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces } }); - password.addTextChangedListener(new TextWatcher() { + etPassword.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @@ -155,18 +158,14 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces @Override public void onClick(View view) { - if (username.getText() != null && !username.getText().toString().trim().equals("") && - password.getText() != null && !password.getText().toString().trim().equals("")) { - - passwordVal = password.getText().toString().trim(); - if (txtDomain.getText() != null && - !txtDomain.getText().toString().trim().equals("")) { - usernameVal = - username.getText().toString().trim() + "@" + - txtDomain.getText().toString().trim(); - - } else { - usernameVal = username.getText().toString().trim(); + if (etUsername.getText() != null && + !etUsername.getText().toString().trim().equals("") && + etPassword.getText() != null && !etPassword.getText().toString().trim().equals("")) { + + passwordVal = etPassword.getText().toString().trim(); + usernameVal = etUsername.getText().toString().trim(); + if (etDomain.getText() != null && !etDomain.getText().toString().trim().equals("")) { + usernameVal += "@" + etDomain.getText().toString().trim(); } if (radioBYOD.isChecked()) { @@ -174,22 +173,24 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces } else { deviceType = getResources().getString(R.string.device_enroll_type_cope); } + StringBuilder messageBuilder = new StringBuilder(); + messageBuilder.append(getResources().getString(R.string.dialog_init_middle)); + messageBuilder.append(" "); + messageBuilder.append(deviceType); + messageBuilder.append(" "); + messageBuilder.append(getResources().getString(R.string.dialog_init_end)); alertDialog = CommonDialogUtils.getAlertDialogWithTwoButtonAndTitle(context, getResources().getString(R.string.dialog_init_device_type), - getResources().getString(R.string.dialog_init_middle) + - " " + - deviceType + - " " + - getResources().getString(R.string.dialog_init_end), + messageBuilder.toString(), getResources().getString(R.string.yes), - getResources().getString(R.string.no), dialogClickListener, dialogClickListener); alertDialog.show(); } else { - if (username.getText() != null && !username.getText().toString().trim().equals("")) { + if (etUsername.getText() != null && + !etUsername.getText().toString().trim().equals("")) { Toast.makeText(context, getResources().getString(R.string.toast_error_password), Toast.LENGTH_LONG).show(); @@ -250,14 +251,14 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces Map requestParametres = new HashMap(); - requestParametres.put("username", + requestParametres.put(Constant.USERNAME, usernameVal); - requestParametres.put("password", + requestParametres.put(Constant.PASSWORD, passwordVal); response = HTTPConnectorUtils.postData(context, CommonUtilities.SERVER_URL + - CommonUtilities.SERVER_AUTHENTICATION_ENDPOINT, + CommonUtilities.SERVER_AUTHENTICATION_ENDPOINT, requestParametres); return response; } @@ -274,55 +275,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces @Override protected void onPostExecute(Map result) { - JSONObject response = - null; - if (result != null) { - String responseStatus = - result.get("status"); - try { - if (responseStatus != null) { - if (responseStatus.equalsIgnoreCase(CommonUtilities.REQUEST_SUCCESSFUL)) { - response = - new JSONObject( - result.get("response")); - senderId = - response.getString("senderId"); - getLicense(); - } else if (responseStatus.equalsIgnoreCase(CommonUtilities.UNAUTHORIZED_ACCESS)) { - CommonDialogUtils.stopProgressDialog(progressDialog); - alertDialog = - CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context, - getResources().getString(R.string.title_head_authentication_error), - getResources().getString(R.string.error_authentication_failed), - getResources().getString(R.string.button_ok), - dialogClickListener); - } else if (responseStatus.trim() - .equals(CommonUtilities.INTERNAL_SERVER_ERROR)) { - CommonDialogUtils.stopProgressDialog(progressDialog); - showInternalServerErrorMessage(); - - } else { - Log.e(TAG, - "Status: " + - responseStatus); - showAuthCommonErrorMessage(); - } - } else { - Log.e(TAG, - "The value of status is null in authenticate()"); - showAuthCommonErrorMessage(); - } - - } catch (JSONException e) { - Log.e(TAG, - e.getMessage()); - showAuthCommonErrorMessage(); - } - } else { - Log.e(TAG, - "The result is null in authenticate()"); - showAuthCommonErrorMessage(); - } + authenticateResponse(result); } @@ -331,14 +284,52 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces mLicenseTask.execute(); } + + /** + * Handles the response received from server for the authentication request. + * @param result Received response from server. + */ + private void authenticateResponse(Map result){ + if (result != null) { + String responseStatus = + result.get(Constant.STATUS); + if (responseStatus != null) { + if (responseStatus.equalsIgnoreCase(CommonUtilities.REQUEST_SUCCESSFUL)) { + getLicense(); + } else if (responseStatus.equalsIgnoreCase(CommonUtilities.UNAUTHORIZED_ACCESS)) { + CommonDialogUtils.stopProgressDialog(progressDialog); + alertDialog = + CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context, + getResources().getString(R.string.title_head_authentication_error), + getResources().getString(R.string.error_authentication_failed), + getResources().getString(R.string.button_ok), + dialogClickListener); + } else if (responseStatus.trim() + .equals(CommonUtilities.INTERNAL_SERVER_ERROR)) { + Log.e(TAG, "Error: Internal server error"); + showInternalServerErrorMessage(); + + } else { + Log.e(TAG, "Status: " + responseStatus); + showAuthCommonErrorMessage(); + } + } else { + Log.e(TAG, "The value of status is null in authenticating"); + showAuthCommonErrorMessage(); + } + + } else { + Log.e(TAG, "The result is null in authenticating"); + showAuthCommonErrorMessage(); + } + } /** * Initialize get device license agreement. Check if the user has already - * agreed - * to license agreement + * agreed to license agreement */ private void getLicense() { - String isAgreed = + String licenseAgreedResponse = Preference.get(context, getResources().getString(R.string.shared_pref_isagreed)); String type = @@ -347,9 +338,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces // No need to display license for COPE devices if (type.trim().equals(getResources().getString(R.string.device_enroll_type_byod))) { - if (isAgreed == null) { - Map requestParams = new HashMap(); - requestParams.put("domain", txtDomain.getText().toString().trim()); + if (licenseAgreedResponse == null) { // Get License OnCancelListener cancelListener = new OnCancelListener() { @@ -361,7 +350,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces getResources().getString(R.string.error_enrollment_failed), getResources().getString(R.string.button_ok), null); - } }; @@ -403,7 +391,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces response = HTTPConnectorUtils.postData(context, CommonUtilities.SERVER_URL + - CommonUtilities.LICENSE_ENDPOINT, + CommonUtilities.LICENSE_ENDPOINT, null); return response; } @@ -433,12 +421,11 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces private void manipulateLicenseResponse(Map result) { String responseStatus; CommonDialogUtils.stopProgressDialog(progressDialog); - String licenseAgreement = ""; if (result != null) { responseStatus = result.get(CommonUtilities.STATUS_KEY); if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL)) { - licenseAgreement = result.get("response"); + String licenseAgreement = result.get(Constant.RESPONSE); if (licenseAgreement != null) { Preference.put(context, getResources().getString(R.string.shared_pref_eula), @@ -488,7 +475,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces String html = "" + message + ""; String mime = "text/html"; String encoding = "utf-8"; - web.getSettings().setJavaScriptEnabled(true); web.loadDataWithBaseURL(null, html, mime, encoding, null); Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK); @@ -545,7 +531,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces editor.putString(getResources().getString(R.string.shared_pref_registered), "0"); editor.putString(getResources().getString(R.string.shared_pref_ip), ""); editor.commit(); - // finish(); Intent intentIP = new Intent(AuthenticationActivity.this, ServerDetails.class); intentIP.putExtra(getResources().getString(R.string.intent_extra_from_activity), @@ -567,12 +552,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces dialog.cancel(); } }); - /* - * builder1.setNegativeButton("No", new - * DialogInterface.OnClickListener() { public void - * onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); - */ - AlertDialog alert = builder.create(); alert.show(); } @@ -588,12 +567,6 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces dialog.dismiss(); } }); - /* - * builder1.setNegativeButton("No", new - * DialogInterface.OnClickListener() { public void - * onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); - */ - AlertDialog alert = builder.create(); alert.show(); } @@ -611,21 +584,21 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces String serverURL = CommonUtilities.SERVER_PROTOCOL + serverIP + ":" + CommonUtilities.SERVER_PORT + CommonUtilities.OAUTH_ENDPOINT; - if (txtDomain.getText() != null && !txtDomain.getText().toString().trim().equals("")) { + if (etDomain.getText() != null && !etDomain.getText().toString().trim().equals("")) { usernameForRegister = - username.getText().toString().trim() + "@" + - txtDomain.getText().toString().trim(); + etUsername.getText().toString().trim() + "@" + + etDomain.getText().toString().trim(); IdentityProxy.getInstance().init(clientKey, clientSecret, usernameForRegister, - password.getText().toString().trim(), serverURL, + etPassword.getText().toString().trim(), serverURL, AuthenticationActivity.this, this.getApplicationContext()); } else { - usernameForRegister = username.getText().toString().trim(); + usernameForRegister = etUsername.getText().toString().trim(); IdentityProxy.getInstance().init(clientKey, clientSecret, usernameForRegister, - password.getText().toString().trim(), serverURL, + etPassword.getText().toString().trim(), serverURL, AuthenticationActivity.this, this.getApplicationContext()); } @@ -635,19 +608,19 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces boolean isReady = false; - if (username.getText().toString().length() >= 1 && - password.getText().toString().length() >= 1) { + if (etUsername.getText().toString().length() >= 1 && + etPassword.getText().toString().length() >= 1) { isReady = true; } if (isReady) { - authenticate.setBackground(getResources().getDrawable(R.drawable.btn_orange)); - authenticate.setTextColor(getResources().getColor(R.color.white)); - authenticate.setEnabled(true); + btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_orange)); + btnRegister.setTextColor(getResources().getColor(R.color.white)); + btnRegister.setEnabled(true); } else { - authenticate.setBackground(getResources().getDrawable(R.drawable.btn_grey)); - authenticate.setTextColor(getResources().getColor(R.color.black)); - authenticate.setEnabled(false); + btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_grey)); + btnRegister.setTextColor(getResources().getColor(R.color.black)); + btnRegister.setEnabled(false); } } @@ -699,12 +672,12 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces @Override public void onClick(DialogInterface dialog, int which) { - username.setText(CommonUtilities.EMPTY_STRING); - password.setText(CommonUtilities.EMPTY_STRING); - txtDomain.setText(CommonUtilities.EMPTY_STRING); - authenticate.setEnabled(false); - authenticate.setBackground(getResources().getDrawable(R.drawable.btn_grey)); - authenticate.setTextColor(getResources().getColor(R.color.black)); + etUsername.setText(CommonUtilities.EMPTY_STRING); + etPassword.setText(CommonUtilities.EMPTY_STRING); + etDomain.setText(CommonUtilities.EMPTY_STRING); + btnRegister.setEnabled(false); + btnRegister.setBackground(getResources().getDrawable(R.drawable.btn_grey)); + btnRegister.setTextColor(getResources().getColor(R.color.black)); } }; @@ -766,7 +739,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces editor.commit(); Map requestParams = new HashMap(); - requestParams.put("domain", txtDomain.getText().toString().trim()); + requestParams.put("domain", etDomain.getText().toString().trim()); // Check network connection availability before calling the API. if (PhoneState.isNetworkAvailable(context)) { // Call get sender ID API. @@ -871,7 +844,7 @@ public class AuthenticationActivity extends SherlockActivity implements APIAcces responseStatus = result.get(CommonUtilities.STATUS_KEY); if (responseStatus.equals(CommonUtilities.REQUEST_SUCCESSFUL)) { try { - response = new JSONObject(result.get("response")); + response = new JSONObject(result.get(Constant.RESPONSE)); senderId = response.getString("sender_id"); mode = response.getString("notifier"); interval = (float) Float.parseFloat(response.getString("notifierInterval")); diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java index 5c65322b5b5..a9e28245a74 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java @@ -40,12 +40,12 @@ import org.wso2.cdm.agent.utils.Responce; */ public class ServerDetails extends Activity { - TextView serverIP; - Button startRegistration; + TextView evServerIP; + Button btnStartRegistration; Context context; DialogInterface.OnClickListener dialogClickListener; DeviceInfo info; - TextView severAddressLabel; + TextView tvSeverAddress; String senderID = null; ProgressDialog progressDialog; @@ -62,49 +62,51 @@ public class ServerDetails extends Activity { setContentView(R.layout.activity_settings); context = ServerDetails.this; info = new DeviceInfo(ServerDetails.this); - serverIP = (TextView) findViewById(R.id.etServerIP); - severAddressLabel = (TextView) findViewById(R.id.severAddressLabel); - startRegistration = (Button) findViewById(R.id.startRegistration); + evServerIP = (TextView) findViewById(R.id.evServerIP); + tvSeverAddress = (TextView) findViewById(R.id.tvSeverAddress); + btnStartRegistration = (Button) findViewById(R.id.btnStartRegistration); // Checking if the device meets minimum requirements Responce compatibility = info.isCompatible(); if (!compatibility.getCode()) { - startRegistration.setVisibility(View.GONE); - severAddressLabel.setVisibility(View.GONE); - serverIP.setVisibility(View.GONE); + btnStartRegistration.setVisibility(View.GONE); + tvSeverAddress.setVisibility(View.GONE); + evServerIP.setVisibility(View.GONE); alertDialog = - CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context.getApplicationContext(), + CommonDialogUtils.getAlertDialogWithOneButtonAndTitle(context, getResources().getString(R.string.error_authorization_failed), getResources().getString(compatibility.getDescriptionResourceID()), getResources().getString(R.string.button_ok), onRootedClickListner); } else { - startRegistration.setVisibility(View.VISIBLE); - serverIP.setVisibility(View.VISIBLE); + btnStartRegistration.setVisibility(View.VISIBLE); + evServerIP.setVisibility(View.VISIBLE); String ipSaved = Preference.get(context.getApplicationContext(), getResources().getString(R.string.shared_pref_ip)); - regId = Preference.get(context.getApplicationContext().getApplicationContext(), getResources().getString(R.string.shared_pref_regId)); + regId = Preference.get(context.getApplicationContext(), getResources().getString(R.string.shared_pref_regId)); - //heck if we have the IP saved previously. + //check if we have the IP saved previously. if (ipSaved != null) { - serverIP.setText(ipSaved); + evServerIP.setText(ipSaved); CommonUtilities.setServerURL(ipSaved); startAuthenticationActivity(); } else { - serverIP.setText(CommonUtilities.SERVER_IP); + evServerIP.setText(CommonUtilities.SERVER_IP); } // on click handler for start registration - startRegistration.setOnClickListener(new OnClickListener() { + btnStartRegistration.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - AlertDialog.Builder builder = new AlertDialog.Builder(ServerDetails.this); - builder.setMessage(getResources().getString(R.string.dialog_init_confirmation) + - " " + - serverIP.getText().toString() + - " " + - getResources().getString(R.string.dialog_init_end_general)) + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(ServerDetails.this); + StringBuilder messageBuilder = new StringBuilder(); + messageBuilder.append(getResources().getString(R.string.dialog_init_confirmation)); + messageBuilder.append(" "); + messageBuilder.append(evServerIP.getText().toString()); + messageBuilder.append(" "); + messageBuilder.append(getResources().getString(R.string.dialog_init_end_general)); + alertBuilder.setMessage(messageBuilder.toString()) .setPositiveButton(getResources().getString(R.string.yes), dialogClickListener) .setNegativeButton(getResources().getString(R.string.no), @@ -117,11 +119,11 @@ public class ServerDetails extends Activity { public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: - if (!serverIP.getText().toString().trim().equals("")) { - CommonUtilities.setServerURL(serverIP.getText().toString().trim()); + if (!evServerIP.getText().toString().trim().equals("")) { + CommonUtilities.setServerURL(evServerIP.getText().toString().trim()); Preference.put(context.getApplicationContext(), getResources().getString(R.string.shared_pref_ip), - serverIP.getText().toString().trim()); + evServerIP.getText().toString().trim()); startAuthenticationActivity(); } else { @@ -148,6 +150,9 @@ public class ServerDetails extends Activity { } }; + /** + * This method is called to open AuthenticationActivity. + */ private void startAuthenticationActivity() { Intent intent = new Intent(ServerDetails.this, AuthenticationActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); @@ -161,10 +166,13 @@ public class ServerDetails extends Activity { */ @Override protected void onDestroy() { - //Avoiding memory leaks by destroying context object context = null; super.onDestroy(); } + + + + // Old API manager communication code. // diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Constant.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Constant.java new file mode 100644 index 00000000000..8e551e336aa --- /dev/null +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/utils/Constant.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.cdm.agent.utils; + +/** + * Constant values throughout the agent + */ +public class Constant { + public static final String USERNAME = "username"; + public static final String PASSWORD = "password"; + public static final String STATUS = "status"; + public static final String RESPONSE = "response"; + +} From 2663ee014cf347cb2722c7d5de9f350c73d68db8 Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Tue, 20 Jan 2015 13:49:33 +0530 Subject: [PATCH 3/5] xml element name changes of UI --- .../modules/agents/android/client/bin/R.txt | 43 ++++++++++--------- .../res/layout/activity_authentication.xml | 6 +-- .../client/res/layout/activity_settings.xml | 10 ++--- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/product/modules/agents/android/client/bin/R.txt b/product/modules/agents/android/client/bin/R.txt index 6e3120ce0f2..9ba843835b9 100644 --- a/product/modules/agents/android/client/bin/R.txt +++ b/product/modules/agents/android/client/bin/R.txt @@ -276,7 +276,7 @@ int drawable repeat_bg 0x7f020087 int drawable top_bar 0x7f020088 int drawable wifi 0x7f020089 int drawable wipe 0x7f02008a -int id TextView01 0x7f060090 +int id TextView01 0x7f060091 int id abs__action_bar 0x7f06004e int id abs__action_bar_container 0x7f06004d int id abs__action_bar_subtitle 0x7f06003d @@ -317,42 +317,45 @@ int id abs__textButton 0x7f06003f int id abs__title 0x7f060047 int id abs__titleDivider 0x7f060048 int id abs__up 0x7f06000b -int id action_settings 0x7f060094 +int id action_settings 0x7f060095 int id background_container 0x7f06001f int id blocks_now 0x7f06001e int id blocks_ruler 0x7f06001d int id btnEnroll 0x7f060082 -int id btnLogin 0x7f06008f +int id btnLogin 0x7f060090 int id btnOK 0x7f060064 int id btnRefresh 0x7f06007d int id btnRegister 0x7f060070 int id btnReset 0x7f06007e int id btnSetPin 0x7f060087 +int id btnStartRegistration 0x7f06008b int id btnTryAgain 0x7f060073 int id btnUnreg 0x7f060065 int id btnUnregister 0x7f060088 -int id button_layout 0x7f06008c -int id debug_log 0x7f06009a -int id dialogButtonCancel 0x7f06008e -int id dialogButtonOK 0x7f06008d +int id button_layout 0x7f06008d +int id debug_log 0x7f06009b +int id dialogButtonCancel 0x7f06008f +int id dialogButtonOK 0x7f06008e int id dialog_discard_confirm 0x7f06001a int id dialog_moderator 0x7f06001b int id dialog_wave 0x7f06001c int id disableHome 0x7f060009 -int id editText2 0x7f06006c int id edit_query 0x7f060053 int id enrollPanel 0x7f060081 int id error 0x7f060072 -int id etServerIP 0x7f06008a +int id etDomain 0x7f06006a +int id etPassword 0x7f06006c +int id etUsername 0x7f06006b +int id evServerIP 0x7f06008a int id footer 0x7f060071 int id footerlogo 0x7f060068 int id fragment_container 0x7f060034 int id gridview 0x7f060014 int id homeAsUp 0x7f060006 int id incompatibleError 0x7f060074 -int id info 0x7f060097 -int id info_setting 0x7f060098 -int id ip_setting 0x7f060096 +int id info 0x7f060098 +int id info_setting 0x7f060099 +int id ip_setting 0x7f060097 int id layout_topbar 0x7f060067 int id lblPin 0x7f060084 int id linInner 0x7f060062 @@ -361,25 +364,24 @@ int id linearLayoutText 0x7f060080 int id listMode 0x7f060002 int id listview 0x7f060060 int id logo 0x7f06005f -int id more 0x7f060095 +int id more 0x7f060096 int id normal 0x7f060001 -int id notify 0x7f060091 +int id notify 0x7f060092 int id option_button 0x7f06007c -int id pin_setting 0x7f060099 +int id pin_setting 0x7f06009a int id preference_brand_view 0x7f06002d int id preference_empty_view 0x7f06002c int id radioBYOD 0x7f06006e int id radioCOPE 0x7f06006f int id radioGroupType 0x7f06006d -int id rowImage 0x7f060092 -int id rowTextView 0x7f060093 +int id rowImage 0x7f060093 +int id rowTextView 0x7f060094 int id scroller 0x7f060061 int id setting_invite_email_button 0x7f060030 int id setting_invite_email_edittext 0x7f06002f int id setting_invite_email_imageview 0x7f060031 int id setting_invite_email_layout 0x7f06002e int id setting_invite_email_textview 0x7f060032 -int id severAddressLabel 0x7f060089 int id sg_button1 0x7f060039 int id sg_button2 0x7f06003a int id sg_button3 0x7f06003b @@ -407,14 +409,14 @@ int id swipeable_bottom 0x7f060010 int id swipeable_container 0x7f060012 int id swipeable_top 0x7f060011 int id tabMode 0x7f060003 -int id text 0x7f06008b +int id text 0x7f06008c int id title_bar_layout 0x7f060020 int id title_container 0x7f060016 int id title_logo 0x7f060017 int id title_option 0x7f060019 int id title_text 0x7f060018 +int id tvSeverAddress 0x7f060089 int id txtDevice 0x7f060076 -int id txtDomain 0x7f06006a int id txtId 0x7f060075 int id txtLog 0x7f06007f int id txtMessage 0x7f060063 @@ -428,7 +430,6 @@ int id txtRoot 0x7f06007b int id txtSDK 0x7f060079 int id useLogo 0x7f060004 int id user_edit_location 0x7f060033 -int id username 0x7f06006b int id webview 0x7f060015 int id wrap_content 0x7f060000 int integer abs__max_action_buttons 0x7f0a0000 diff --git a/product/modules/agents/android/client/res/layout/activity_authentication.xml b/product/modules/agents/android/client/res/layout/activity_authentication.xml index f27509b5a7b..cd459ddba41 100644 --- a/product/modules/agents/android/client/res/layout/activity_authentication.xml +++ b/product/modules/agents/android/client/res/layout/activity_authentication.xml @@ -27,7 +27,7 @@ android:layout_height="wrap_content" android:layout_margin="5dp" android:singleLine="true" - android:id="@+id/txtDomain" + android:id="@+id/etDomain" android:hint="Domain" android:textColor="@android:color/black" android:inputType="text" /> @@ -37,7 +37,7 @@ android:layout_height="wrap_content" android:layout_margin="5dp" android:singleLine="true" - android:id="@+id/username" + android:id="@+id/etUsername" android:hint="Username" android:textColor="@android:color/black" android:inputType="textEmailAddress" /> @@ -47,7 +47,7 @@ -