mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixed conflicts of local repo and merged
This commit is contained in:
commit
fd29deb372
@ -0,0 +1,152 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>certificate-mgt</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<name>WSO2 Carbon - Certificate Management Core</name>
|
||||||
|
<description>WSO2 Carbon - Certificate Management Core</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-scr-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<version>1.4.0</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||||
|
<Bundle-Description>Device Management Core Bundle</Bundle-Description>
|
||||||
|
<Private-Package>org.wso2.carbon.certificate.mgt.core.internal</Private-Package>
|
||||||
|
<Import-Package>
|
||||||
|
org.osgi.framework,
|
||||||
|
org.osgi.service.component,
|
||||||
|
org.apache.commons.logging,
|
||||||
|
javax.security.auth.x500,
|
||||||
|
javax.xml.parsers,
|
||||||
|
org.apache.commons.codec.binary,
|
||||||
|
org.bouncycastle.asn1,
|
||||||
|
org.bouncycastle.asn1.x500,
|
||||||
|
org.bouncycastle.asn1.x509,
|
||||||
|
org.bouncycastle.cert,
|
||||||
|
org.bouncycastle.cert.jcajce,
|
||||||
|
org.bouncycastle.cms,
|
||||||
|
org.bouncycastle.jce.provider,
|
||||||
|
org.bouncycastle.operator,
|
||||||
|
org.bouncycastle.operator.jcajce,
|
||||||
|
org.bouncycastle.pkcs,
|
||||||
|
org.bouncycastle.util,
|
||||||
|
org.jscep.message,
|
||||||
|
org.jscep.transaction,
|
||||||
|
org.w3c.dom,
|
||||||
|
org.xml.sax
|
||||||
|
</Import-Package>
|
||||||
|
<Export-Package>
|
||||||
|
!org.wso2.carbon.certificate.mgt.core.internal.*,
|
||||||
|
org.wso2.carbon.certificate.mgt.core.dto.*,
|
||||||
|
org.wso2.carbon.certificate.mgt.core.exception.*,
|
||||||
|
org.wso2.carbon.certificate.mgt.core.impl.*,
|
||||||
|
org.wso2.carbon.certificate.mgt.core.service.*,
|
||||||
|
org.wso2.carbon.certificate.mgt.core.util.*
|
||||||
|
</Export-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.18</version>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
<suiteXmlFiles>
|
||||||
|
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||||
|
</suiteXmlFiles>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.osgi</groupId>
|
||||||
|
<artifactId>org.eclipse.osgi</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.osgi</groupId>
|
||||||
|
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testng</groupId>
|
||||||
|
<artifactId>testng</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle.wso2</groupId>
|
||||||
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle.wso2</groupId>
|
||||||
|
<artifactId>bcpkix-jdk15on</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle.wso2</groupId>
|
||||||
|
<artifactId>bcmail-jdk15on</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.jscep.wso2</groupId>
|
||||||
|
<artifactId>jscep</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec.wso2</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io.wso2</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.certificate.mgt.core.dto;
|
||||||
|
|
||||||
|
public enum CAStatus {
|
||||||
|
|
||||||
|
CA_CERT_FAILED,
|
||||||
|
CA_CERT_RECEIVED,
|
||||||
|
CA_RA_CERT_RECEIVED
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.certificate.mgt.core.dto;
|
||||||
|
|
||||||
|
public class SCEPResponse {
|
||||||
|
|
||||||
|
private byte[] encodedResponse;
|
||||||
|
private CAStatus resultCriteria;
|
||||||
|
|
||||||
|
public byte[] getEncodedResponse() {
|
||||||
|
return encodedResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEncodedResponse(byte[] encodedResponse) {
|
||||||
|
this.encodedResponse = encodedResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CAStatus getResultCriteria() {
|
||||||
|
return resultCriteria;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResultCriteria(CAStatus resultCriteria) {
|
||||||
|
this.resultCriteria = resultCriteria;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.certificate.mgt.core.exception;
|
||||||
|
|
||||||
|
public class KeystoreException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8935640983869122660L;
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeystoreException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeystoreException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
setErrorMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeystoreException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeystoreException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeystoreException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,452 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.certificate.mgt.core.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.bouncycastle.asn1.x500.X500Name;
|
||||||
|
import org.bouncycastle.asn1.x509.KeyUsage;
|
||||||
|
import org.bouncycastle.asn1.x509.X509Extension;
|
||||||
|
import org.bouncycastle.cert.CertIOException;
|
||||||
|
import org.bouncycastle.cert.X509CertificateHolder;
|
||||||
|
import org.bouncycastle.cert.X509v3CertificateBuilder;
|
||||||
|
import org.bouncycastle.cert.jcajce.JcaCertStore;
|
||||||
|
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
|
||||||
|
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
|
||||||
|
import org.bouncycastle.cms.CMSAbsentContent;
|
||||||
|
import org.bouncycastle.cms.CMSException;
|
||||||
|
import org.bouncycastle.cms.CMSSignedData;
|
||||||
|
import org.bouncycastle.cms.CMSSignedDataGenerator;
|
||||||
|
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||||
|
import org.bouncycastle.operator.ContentSigner;
|
||||||
|
import org.bouncycastle.operator.OperatorCreationException;
|
||||||
|
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||||
|
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
||||||
|
import org.bouncycastle.util.Store;
|
||||||
|
import org.jscep.message.CertRep;
|
||||||
|
import org.jscep.message.MessageDecodingException;
|
||||||
|
import org.jscep.message.MessageEncodingException;
|
||||||
|
import org.jscep.message.PkcsPkiEnvelopeDecoder;
|
||||||
|
import org.jscep.message.PkcsPkiEnvelopeEncoder;
|
||||||
|
import org.jscep.message.PkiMessage;
|
||||||
|
import org.jscep.message.PkiMessageDecoder;
|
||||||
|
import org.jscep.message.PkiMessageEncoder;
|
||||||
|
import org.jscep.transaction.FailInfo;
|
||||||
|
import org.jscep.transaction.Nonce;
|
||||||
|
import org.jscep.transaction.TransactionId;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.dto.CAStatus;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.util.CommonUtil;
|
||||||
|
|
||||||
|
import javax.security.auth.x500.X500Principal;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.KeyFactory;
|
||||||
|
import java.security.KeyPair;
|
||||||
|
import java.security.KeyPairGenerator;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.NoSuchProviderException;
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.security.Security;
|
||||||
|
import java.security.SignatureException;
|
||||||
|
import java.security.cert.CertificateEncodingException;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.cert.CertificateExpiredException;
|
||||||
|
import java.security.cert.CertificateFactory;
|
||||||
|
import java.security.cert.CertificateNotYetValidException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CertificateGenerator {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(CertificateGenerator.class);
|
||||||
|
|
||||||
|
public List<X509Certificate> getRootCertificates(byte[] ca, byte[] ra) throws KeystoreException {
|
||||||
|
|
||||||
|
if (ca == null) {
|
||||||
|
throw new KeystoreException("CA certificate is mandatory");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ra == null) {
|
||||||
|
throw new KeystoreException("RA certificate is mandatory");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<X509Certificate> certificateList = new ArrayList<X509Certificate>();
|
||||||
|
InputStream caInputStream = null;
|
||||||
|
InputStream raInputStream = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
CertificateFactory certificateFactory = CertificateFactory.getInstance(ConfigurationUtil.X_509);
|
||||||
|
caInputStream = new ByteArrayInputStream(ca);
|
||||||
|
raInputStream = new ByteArrayInputStream(ra);
|
||||||
|
|
||||||
|
X509Certificate caCert = (X509Certificate) certificateFactory.generateCertificate(caInputStream);
|
||||||
|
X509Certificate raCert = (X509Certificate) certificateFactory.generateCertificate(raInputStream);
|
||||||
|
|
||||||
|
certificateList.add(caCert);
|
||||||
|
certificateList.add(raCert);
|
||||||
|
} catch (CertificateException e) {
|
||||||
|
String errorMsg = "Error occurred while fetching root certificates";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} finally {
|
||||||
|
if (caInputStream != null) {
|
||||||
|
try {
|
||||||
|
caInputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Error occurred when closing CA input stream");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (raInputStream != null) {
|
||||||
|
try {
|
||||||
|
raInputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Error occurred when closing RA input stream");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return certificateList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public X509Certificate generateX509Certificate() throws KeystoreException {
|
||||||
|
|
||||||
|
CommonUtil commonUtil = new CommonUtil();
|
||||||
|
Date validityBeginDate = commonUtil.getValidityStartDate();
|
||||||
|
Date validityEndDate = commonUtil.getValidityEndDate();
|
||||||
|
|
||||||
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
|
||||||
|
try {
|
||||||
|
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(
|
||||||
|
ConfigurationUtil.RSA, ConfigurationUtil.PROVIDER);
|
||||||
|
keyPairGenerator.initialize(ConfigurationUtil.RSA_KEY_LENGTH, new SecureRandom());
|
||||||
|
KeyPair pair = keyPairGenerator.generateKeyPair();
|
||||||
|
X500Principal principal = new X500Principal(ConfigurationUtil.DEFAULT_PRINCIPAL);
|
||||||
|
BigInteger serial = BigInteger.valueOf(System.currentTimeMillis());
|
||||||
|
|
||||||
|
X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(
|
||||||
|
principal, serial, validityBeginDate, validityEndDate,
|
||||||
|
principal, pair.getPublic());
|
||||||
|
ContentSigner contentSigner = new JcaContentSignerBuilder(ConfigurationUtil.SHA256_RSA)
|
||||||
|
.setProvider(ConfigurationUtil.PROVIDER).build(
|
||||||
|
pair.getPrivate());
|
||||||
|
X509Certificate certificate = new JcaX509CertificateConverter()
|
||||||
|
.setProvider(ConfigurationUtil.PROVIDER).getCertificate(
|
||||||
|
certificateBuilder.build(contentSigner));
|
||||||
|
|
||||||
|
// cert.checkValidity();
|
||||||
|
|
||||||
|
certificate.verify(certificate.getPublicKey());
|
||||||
|
|
||||||
|
return certificate;
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
String errorMsg = "No such algorithm found when generating certificate";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (NoSuchProviderException e) {
|
||||||
|
String errorMsg = "No such provider found when generating certificate";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (OperatorCreationException e) {
|
||||||
|
String errorMsg = "Issue in operator creation when generating certificate";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CertificateExpiredException e) {
|
||||||
|
String errorMsg = "Certificate expired after generating certificate";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CertificateNotYetValidException e) {
|
||||||
|
String errorMsg = "Certificate not yet valid when generating certificate";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CertificateException e) {
|
||||||
|
String errorMsg = "Certificate issue occurred when generating certificate";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (InvalidKeyException e) {
|
||||||
|
String errorMsg = "Invalid key used when generating certificate";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (SignatureException e) {
|
||||||
|
String errorMsg = "Signature related issue occurred when generating certificate";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPKIMessage(InputStream inputStream) throws KeystoreException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
CMSSignedData signedData = new CMSSignedData(inputStream);
|
||||||
|
Store reqStore = signedData.getCertificates();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Collection<X509CertificateHolder> reqCerts = reqStore.getMatches(null);
|
||||||
|
|
||||||
|
KeyStoreReader keyStoreReader = new KeyStoreReader();
|
||||||
|
PrivateKey privateKeyRA = keyStoreReader.getRAPrivateKey();
|
||||||
|
PrivateKey privateKeyCA = keyStoreReader.getCAPrivateKey();
|
||||||
|
X509Certificate certRA = (X509Certificate) keyStoreReader.getRACertificate();
|
||||||
|
X509Certificate certCA = (X509Certificate) keyStoreReader.getCACertificate();
|
||||||
|
|
||||||
|
CertificateFactory certificateFactory = CertificateFactory.getInstance(ConfigurationUtil.X_509);
|
||||||
|
X509CertificateHolder holder = reqCerts.iterator().next();
|
||||||
|
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(holder.getEncoded());
|
||||||
|
X509Certificate reqCert = (X509Certificate) certificateFactory.generateCertificate(byteArrayInputStream);
|
||||||
|
|
||||||
|
PkcsPkiEnvelopeDecoder envelopeDecoder = new PkcsPkiEnvelopeDecoder(certRA, privateKeyRA);
|
||||||
|
PkiMessageDecoder messageDecoder = new PkiMessageDecoder(reqCert, envelopeDecoder);
|
||||||
|
PkiMessage<?> pkiMessage = messageDecoder.decode(signedData);
|
||||||
|
Object msgData = pkiMessage.getMessageData();
|
||||||
|
|
||||||
|
Nonce senderNonce = Nonce.nextNonce();
|
||||||
|
TransactionId transId = pkiMessage.getTransactionId();
|
||||||
|
Nonce recipientNonce = pkiMessage.getSenderNonce();
|
||||||
|
CertRep certRep;
|
||||||
|
|
||||||
|
PKCS10CertificationRequest certRequest = (PKCS10CertificationRequest) msgData;
|
||||||
|
X509Certificate generatedCert = generateCertificateFromCSR(
|
||||||
|
privateKeyCA, certRequest, certCA.getIssuerX500Principal().getName());
|
||||||
|
|
||||||
|
List<X509Certificate> issued = new ArrayList<X509Certificate>();
|
||||||
|
issued.add(generatedCert);
|
||||||
|
|
||||||
|
if (issued.size() == 0) {
|
||||||
|
certRep = new CertRep(transId, senderNonce, recipientNonce, FailInfo.badCertId);
|
||||||
|
} else {
|
||||||
|
CMSSignedData messageData = getMessageData(issued);
|
||||||
|
certRep = new CertRep(transId, senderNonce, recipientNonce, messageData);
|
||||||
|
}
|
||||||
|
|
||||||
|
PkcsPkiEnvelopeEncoder envEncoder = new PkcsPkiEnvelopeEncoder(reqCert, ConfigurationUtil.DES_EDE);
|
||||||
|
PkiMessageEncoder encoder = new PkiMessageEncoder(privateKeyRA, certRA, envEncoder);
|
||||||
|
CMSSignedData cmsSignedData = encoder.encode(certRep);
|
||||||
|
|
||||||
|
return cmsSignedData.getEncoded();
|
||||||
|
|
||||||
|
} catch (CertificateException e) {
|
||||||
|
String errorMsg = "Certificate issue occurred when generating getPKIMessage";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (MessageEncodingException e) {
|
||||||
|
String errorMsg = "Message encoding issue occurred when generating getPKIMessage";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
String errorMsg = "Input output issue occurred when generating getPKIMessage";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (MessageDecodingException e) {
|
||||||
|
String errorMsg = "Message decoding issue occurred when generating getPKIMessage";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CMSException e) {
|
||||||
|
String errorMsg = "CMS issue occurred when generating getPKIMessage";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static X509Certificate generateCertificateFromCSR(PrivateKey privateKey,
|
||||||
|
PKCS10CertificationRequest request,
|
||||||
|
String issueSubject)
|
||||||
|
throws KeystoreException {
|
||||||
|
|
||||||
|
CommonUtil commonUtil = new CommonUtil();
|
||||||
|
Date validityBeginDate = commonUtil.getValidityStartDate();
|
||||||
|
Date validityEndDate = commonUtil.getValidityEndDate();
|
||||||
|
|
||||||
|
X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(
|
||||||
|
new X500Name(issueSubject), BigInteger.valueOf(System.currentTimeMillis()),
|
||||||
|
validityBeginDate, validityEndDate, request.getSubject(), request.getSubjectPublicKeyInfo());
|
||||||
|
|
||||||
|
ContentSigner sigGen;
|
||||||
|
X509Certificate issuedCert;
|
||||||
|
try {
|
||||||
|
certificateBuilder.addExtension(X509Extension.keyUsage, true, new KeyUsage(
|
||||||
|
KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
|
||||||
|
sigGen = new JcaContentSignerBuilder(ConfigurationUtil.SHA256_RSA)
|
||||||
|
.setProvider(ConfigurationUtil.PROVIDER).build(privateKey);
|
||||||
|
issuedCert = new JcaX509CertificateConverter().setProvider(
|
||||||
|
ConfigurationUtil.PROVIDER).getCertificate(
|
||||||
|
certificateBuilder.build(sigGen));
|
||||||
|
} catch (CertIOException e) {
|
||||||
|
String errorMsg = "Certificate Input output issue occurred when generating generateCertificateFromCSR";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (OperatorCreationException e) {
|
||||||
|
String errorMsg = "Operator creation issue occurred when generating generateCertificateFromCSR";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CertificateException e) {
|
||||||
|
String errorMsg = "Certificate issue occurred when generating generateCertificateFromCSR";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return issuedCert;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CMSSignedData getMessageData(final List<X509Certificate> certs) throws KeystoreException {
|
||||||
|
|
||||||
|
CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
|
||||||
|
JcaCertStore store;
|
||||||
|
try {
|
||||||
|
store = new JcaCertStore(certs);
|
||||||
|
generator.addCertificates(store);
|
||||||
|
|
||||||
|
return generator.generate(new CMSAbsentContent());
|
||||||
|
} catch (CertificateEncodingException e) {
|
||||||
|
String errorMsg = "Certificate encoding issue occurred when generating getMessageData";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CMSException e) {
|
||||||
|
String errorMsg = "Message decoding issue occurred when generating getMessageData";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PrivateKey getSignerKey(String signerPrivateKeyPath) throws KeystoreException {
|
||||||
|
|
||||||
|
File file = new File(signerPrivateKeyPath);
|
||||||
|
FileInputStream fis;
|
||||||
|
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream(file);
|
||||||
|
DataInputStream dis = new DataInputStream(fis);
|
||||||
|
byte[] keyBytes = new byte[(int) file.length()];
|
||||||
|
dis.readFully(keyBytes);
|
||||||
|
dis.close();
|
||||||
|
|
||||||
|
String temp = new String(keyBytes);
|
||||||
|
String privateKeyPEM = temp.replace(
|
||||||
|
ConfigurationUtil.RSA_PRIVATE_KEY_BEGIN_TEXT, ConfigurationUtil.EMPTY_TEXT);
|
||||||
|
privateKeyPEM = privateKeyPEM
|
||||||
|
.replace(ConfigurationUtil.RSA_PRIVATE_KEY_END_TEXT, ConfigurationUtil.EMPTY_TEXT);
|
||||||
|
|
||||||
|
byte[] decoded = Base64.decodeBase64(privateKeyPEM);
|
||||||
|
PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(decoded);
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance(ConfigurationUtil.RSA);
|
||||||
|
|
||||||
|
return keyFactory.generatePrivate(encodedKeySpec);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
String errorMsg = "Private key file not found in getSignerKey";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
String errorMsg = "Input output issue in getSignerKey";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
String errorMsg = "Algorithm not not found in getSignerKey";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (InvalidKeySpecException e) {
|
||||||
|
String errorMsg = "Invalid key found in getSignerKey";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private X509Certificate getSigner(String signerCertificatePath) throws KeystoreException {
|
||||||
|
|
||||||
|
X509Certificate certificate;
|
||||||
|
try {
|
||||||
|
CertificateFactory certificateFactory = CertificateFactory.getInstance(ConfigurationUtil.X_509);
|
||||||
|
certificate = (X509Certificate) certificateFactory.generateCertificate(
|
||||||
|
new FileInputStream(signerCertificatePath));
|
||||||
|
|
||||||
|
return certificate;
|
||||||
|
} catch (CertificateException e) {
|
||||||
|
String errorMsg = "Certificate related issue occurred in getSigner";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
String errorMsg = "Signer certificate path not found in getSigner";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCEPResponse getCACert() throws KeystoreException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
SCEPResponse scepResponse = new SCEPResponse();
|
||||||
|
KeyStoreReader keyStoreReader = new KeyStoreReader();
|
||||||
|
|
||||||
|
byte[] caBytes = keyStoreReader.getCACertificate().getEncoded();
|
||||||
|
byte[] raBytes = keyStoreReader.getRACertificate().getEncoded();
|
||||||
|
|
||||||
|
final List<X509Certificate> certs = getRootCertificates(caBytes, raBytes);
|
||||||
|
|
||||||
|
byte[] bytes;
|
||||||
|
if (certs.size() == 0) {
|
||||||
|
scepResponse.setResultCriteria(CAStatus.CA_CERT_FAILED);
|
||||||
|
bytes = new byte[0];
|
||||||
|
} else if (certs.size() == 1) {
|
||||||
|
scepResponse.setResultCriteria(CAStatus.CA_CERT_RECEIVED);
|
||||||
|
bytes = certs.get(0).getEncoded();
|
||||||
|
} else {
|
||||||
|
scepResponse.setResultCriteria(CAStatus.CA_RA_CERT_RECEIVED);
|
||||||
|
CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
|
||||||
|
JcaCertStore store = new JcaCertStore(certs);
|
||||||
|
generator.addCertificates(store);
|
||||||
|
CMSSignedData degenerateSd = generator.generate(new CMSAbsentContent());
|
||||||
|
bytes = degenerateSd.getEncoded();
|
||||||
|
}
|
||||||
|
scepResponse.setEncodedResponse(bytes);
|
||||||
|
|
||||||
|
return scepResponse;
|
||||||
|
} catch (CertificateEncodingException e) {
|
||||||
|
String errorMsg = "Certificate encoding issue occurred in getCACert";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CMSException e) {
|
||||||
|
String errorMsg = "CMS issue occurred in getCACert";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
String errorMsg = "Input output issue occurred in getCACert";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (KeystoreException e) {
|
||||||
|
String errorMsg = "Keystore reading error occurred when handling profile request";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,186 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.certificate.mgt.core.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.security.KeyStore;
|
||||||
|
import java.security.KeyStoreException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.UnrecoverableKeyException;
|
||||||
|
import java.security.cert.Certificate;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
|
||||||
|
public class KeyStoreReader {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(KeyStoreReader.class);
|
||||||
|
|
||||||
|
private KeyStore loadKeyStore(String configEntryKeyStoreType, String configEntryKeyStorePath,
|
||||||
|
String configEntryKeyStorePassword) throws KeystoreException {
|
||||||
|
|
||||||
|
InputStream inputStream = null;
|
||||||
|
KeyStore keystore;
|
||||||
|
|
||||||
|
try {
|
||||||
|
keystore = KeyStore.getInstance(ConfigurationUtil.getConfigEntry(configEntryKeyStoreType));
|
||||||
|
inputStream = new FileInputStream(ConfigurationUtil.getConfigEntry(configEntryKeyStorePath));
|
||||||
|
keystore.load(inputStream, ConfigurationUtil.getConfigEntry(configEntryKeyStorePassword).toCharArray());
|
||||||
|
|
||||||
|
} catch (KeyStoreException e) {
|
||||||
|
String errorMsg = "KeyStore issue occurred when loading KeyStore";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
String errorMsg = "KeyStore file not found when loading KeyStore";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
String errorMsg = "Algorithm not found when loading KeyStore";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (CertificateException e) {
|
||||||
|
String errorMsg = "Certificate expired when loading KeyStore";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
String errorMsg = "Input output issue occurred when loading KeyStore";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Error closing KeyStore input stream", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return keystore;
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyStore loadMDMKeyStore() throws KeystoreException {
|
||||||
|
return loadKeyStore(ConfigurationUtil.CERTIFICATE_KEYSTORE, ConfigurationUtil.PATH_CERTIFICATE_KEYSTORE,
|
||||||
|
ConfigurationUtil.CERTIFICATE_KEYSTORE_PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Certificate getCACertificate() throws KeystoreException {
|
||||||
|
|
||||||
|
KeyStore keystore = loadMDMKeyStore();
|
||||||
|
Certificate caCertificate;
|
||||||
|
|
||||||
|
try {
|
||||||
|
caCertificate = keystore.getCertificate(ConfigurationUtil.getConfigEntry(ConfigurationUtil.CA_CERT_ALIAS));
|
||||||
|
} catch (KeyStoreException e) {
|
||||||
|
String errorMsg = "KeyStore issue occurred when loading KeyStore";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caCertificate == null) {
|
||||||
|
throw new KeystoreException("CA certificate not found in KeyStore");
|
||||||
|
}
|
||||||
|
|
||||||
|
return caCertificate;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrivateKey getCAPrivateKey() throws KeystoreException {
|
||||||
|
|
||||||
|
KeyStore keyStore = loadMDMKeyStore();
|
||||||
|
PrivateKey caPrivateKey;
|
||||||
|
try {
|
||||||
|
caPrivateKey = (PrivateKey) (keyStore.getKey(
|
||||||
|
ConfigurationUtil.getConfigEntry(ConfigurationUtil.CA_CERT_ALIAS),
|
||||||
|
ConfigurationUtil.getConfigEntry(ConfigurationUtil.KEYSTORE_CA_CERT_PRIV_PASSWORD).toCharArray()));
|
||||||
|
} catch (UnrecoverableKeyException e) {
|
||||||
|
String errorMsg = "Key is unrecoverable when retrieving CA private key";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (KeyStoreException e) {
|
||||||
|
String errorMsg = "KeyStore issue occurred when retrieving CA private key";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
String errorMsg = "Algorithm not found when retrieving CA private key";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caPrivateKey == null) {
|
||||||
|
throw new KeystoreException("CA private key not found in KeyStore");
|
||||||
|
}
|
||||||
|
|
||||||
|
return caPrivateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Certificate getRACertificate() throws KeystoreException {
|
||||||
|
|
||||||
|
KeyStore keystore = loadMDMKeyStore();
|
||||||
|
Certificate raCertificate;
|
||||||
|
try {
|
||||||
|
raCertificate = keystore.getCertificate(ConfigurationUtil.getConfigEntry(ConfigurationUtil.RA_CERT_ALIAS));
|
||||||
|
} catch (KeyStoreException e) {
|
||||||
|
String errorMsg = "KeyStore issue occurred when retrieving RA private key";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (raCertificate == null) {
|
||||||
|
throw new KeystoreException("RA certificate not found in KeyStore");
|
||||||
|
}
|
||||||
|
|
||||||
|
return raCertificate;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrivateKey getRAPrivateKey() throws KeystoreException {
|
||||||
|
|
||||||
|
KeyStore keystore = loadMDMKeyStore();
|
||||||
|
PrivateKey raPrivateKey;
|
||||||
|
try {
|
||||||
|
raPrivateKey = (PrivateKey) (keystore.getKey(
|
||||||
|
ConfigurationUtil.getConfigEntry(ConfigurationUtil.RA_CERT_ALIAS),
|
||||||
|
ConfigurationUtil.getConfigEntry(ConfigurationUtil.KEYSTORE_RA_CERT_PRIV_PASSWORD).toCharArray()));
|
||||||
|
} catch (UnrecoverableKeyException e) {
|
||||||
|
String errorMsg = "Key is unrecoverable when retrieving RA private key";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (KeyStoreException e) {
|
||||||
|
String errorMsg = "KeyStore issue occurred when retrieving RA private key";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
String errorMsg = "Algorithm not found when retrieving RA private key";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new KeystoreException(errorMsg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (raPrivateKey == null) {
|
||||||
|
throw new KeystoreException("RA private key not found in KeyStore");
|
||||||
|
}
|
||||||
|
|
||||||
|
return raPrivateKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.certificate.mgt.core.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementServiceImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.certificate.mgt" immediate="true"
|
||||||
|
*/
|
||||||
|
public class CertificateManagementServiceComponent {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(CertificateManagementServiceComponent.class);
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
protected void activate(ComponentContext componentContext) {
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initializing certificate management core bundle");
|
||||||
|
}
|
||||||
|
|
||||||
|
BundleContext bundleContext = componentContext.getBundleContext();
|
||||||
|
bundleContext.registerService(CertificateManagementServiceImpl.class.getName(),
|
||||||
|
CertificateManagementServiceImpl.getInstance(), null);
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Certificate management core bundle has been successfully initialized");
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Error occurred while initializing certificate management core bundle", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
protected void deactivate(ComponentContext componentContext) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.certificate.mgt.core.service;
|
||||||
|
|
||||||
|
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.cert.Certificate;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CertificateManagementService {
|
||||||
|
|
||||||
|
Certificate getCACertificate() throws KeystoreException;
|
||||||
|
|
||||||
|
Certificate getRACertificate() throws KeystoreException;
|
||||||
|
|
||||||
|
public List<X509Certificate> getRootCertificates(byte[] ca, byte[] ra) throws KeystoreException;
|
||||||
|
|
||||||
|
public X509Certificate generateX509Certificate() throws KeystoreException;
|
||||||
|
|
||||||
|
public SCEPResponse getCACertSCEP() throws KeystoreException;
|
||||||
|
|
||||||
|
public byte[] getCACapsSCEP();
|
||||||
|
|
||||||
|
public byte[] getPKIMessageSCEP(InputStream inputStream) throws KeystoreException;
|
||||||
|
|
||||||
|
public X509Certificate generateCertificateFromCSR(PrivateKey privateKey,
|
||||||
|
PKCS10CertificationRequest request,
|
||||||
|
String issueSubject) throws KeystoreException;
|
||||||
|
}
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.certificate.mgt.core.service;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.impl.CertificateGenerator;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.impl.KeyStoreReader;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.cert.Certificate;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CertificateManagementServiceImpl implements CertificateManagementService {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(CertificateManagementServiceImpl.class);
|
||||||
|
private static CertificateManagementServiceImpl certificateManagementServiceImpl;
|
||||||
|
private static KeyStoreReader keyStoreReader;
|
||||||
|
private static CertificateGenerator certificateGenerator;
|
||||||
|
|
||||||
|
private CertificateManagementServiceImpl() {}
|
||||||
|
|
||||||
|
public static CertificateManagementServiceImpl getInstance() {
|
||||||
|
|
||||||
|
if (certificateManagementServiceImpl == null) {
|
||||||
|
certificateManagementServiceImpl = new CertificateManagementServiceImpl();
|
||||||
|
keyStoreReader = new KeyStoreReader();
|
||||||
|
certificateGenerator = new CertificateGenerator();
|
||||||
|
}
|
||||||
|
return certificateManagementServiceImpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Certificate getCACertificate() throws KeystoreException {
|
||||||
|
return keyStoreReader.getCACertificate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Certificate getRACertificate() throws KeystoreException {
|
||||||
|
return keyStoreReader.getRACertificate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<X509Certificate> getRootCertificates(byte[] ca, byte[] ra) throws KeystoreException {
|
||||||
|
return certificateGenerator.getRootCertificates(ca, ra);
|
||||||
|
}
|
||||||
|
|
||||||
|
public X509Certificate generateX509Certificate() throws KeystoreException {
|
||||||
|
return certificateGenerator.generateX509Certificate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SCEPResponse getCACertSCEP() throws KeystoreException {
|
||||||
|
return certificateGenerator.getCACert();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getCACapsSCEP() {
|
||||||
|
return ConfigurationUtil.POST_BODY_CA_CAPS.getBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPKIMessageSCEP(InputStream inputStream) throws KeystoreException {
|
||||||
|
return certificateGenerator.getPKIMessage(inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public X509Certificate generateCertificateFromCSR(PrivateKey privateKey,
|
||||||
|
PKCS10CertificationRequest request,
|
||||||
|
String issueSubject) throws KeystoreException {
|
||||||
|
return certificateGenerator.generateCertificateFromCSR(privateKey, request, issueSubject);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.certificate.mgt.core.util;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class CommonUtil {
|
||||||
|
|
||||||
|
public Date getValidityStartDate() {
|
||||||
|
Date targetDate = new Date();
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(targetDate);
|
||||||
|
calendar.add(Calendar.DATE, -2);
|
||||||
|
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getValidityEndDate() {
|
||||||
|
Date targetDate = new Date();
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(targetDate);
|
||||||
|
calendar.add(Calendar.YEAR, 100);
|
||||||
|
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.certificate.mgt.core.util;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ConfigurationUtil {
|
||||||
|
|
||||||
|
public static final String PATH_CERTIFICATE_KEYSTORE = "CertificateKeystoreLocation";
|
||||||
|
public static final String CERTIFICATE_KEYSTORE_PASSWORD = "CertificateKeystorePassword";
|
||||||
|
public static final String KEYSTORE_CA_CERT_PRIV_PASSWORD = "CAPrivateKeyPassword";
|
||||||
|
public static final String KEYSTORE_RA_CERT_PRIV_PASSWORD = "RAPrivateKeyPassword";
|
||||||
|
public static final String CA_CERT_ALIAS = "CACertAlias";
|
||||||
|
public static final String RA_CERT_ALIAS = "RACertAlias";
|
||||||
|
public static final String SIGNATUREALGO = "SHA1withRSA";
|
||||||
|
public static final String PROVIDER = "BC";
|
||||||
|
public static final String KEYSTORE = "Type";
|
||||||
|
public static final String CERTIFICATE_KEYSTORE = "CertificateKeystoreType";
|
||||||
|
public static final String RSA = "RSA";
|
||||||
|
public static final String UTF_8 = "UTF-8";
|
||||||
|
public static final String SHA256_RSA = "SHA256WithRSAEncryption";
|
||||||
|
public static final String X_509 = "X.509";
|
||||||
|
public static final String POST_BODY_CA_CAPS = "POSTPKIOperation\nSHA-1\nDES3\n";
|
||||||
|
public static final String DES_EDE = "DESede";
|
||||||
|
public static final String CONF_LOCATION = "conf.location";
|
||||||
|
private static final String CARBON_HOME = "carbon.home";
|
||||||
|
private static final String CERTIFICATE_CONFIG_XML = "certificate-config.xml";
|
||||||
|
private static final String CARBON_HOME_ENTRY = "${carbon.home}";
|
||||||
|
public static final String DEFAULT_PRINCIPAL = "O=WSO2, OU=Mobile, C=LK";
|
||||||
|
public static final String RSA_PRIVATE_KEY_BEGIN_TEXT = "-----BEGIN RSA PRIVATE KEY-----\n";
|
||||||
|
public static final String RSA_PRIVATE_KEY_END_TEXT = "-----END RSA PRIVATE KEY-----";
|
||||||
|
public static final String EMPTY_TEXT = "";
|
||||||
|
public static final int RSA_KEY_LENGTH = 1024;
|
||||||
|
|
||||||
|
|
||||||
|
private static ConfigurationUtil configurationUtil;
|
||||||
|
private static final String[] emmConfigEntryNames = { CA_CERT_ALIAS, RA_CERT_ALIAS,
|
||||||
|
CERTIFICATE_KEYSTORE, PATH_CERTIFICATE_KEYSTORE, CERTIFICATE_KEYSTORE_PASSWORD,
|
||||||
|
KEYSTORE_CA_CERT_PRIV_PASSWORD, KEYSTORE_RA_CERT_PRIV_PASSWORD };
|
||||||
|
|
||||||
|
private static Map<String, String> configMap;
|
||||||
|
|
||||||
|
private static Map<String, String> readEMMConfigurations() throws KeystoreException {
|
||||||
|
|
||||||
|
String emmConfLocation = System.getProperty(CONF_LOCATION) + File.separator + CERTIFICATE_CONFIG_XML;
|
||||||
|
|
||||||
|
if (configurationUtil == null || configMap == null) {
|
||||||
|
|
||||||
|
configurationUtil = new ConfigurationUtil();
|
||||||
|
configMap = new HashMap<String, String>();
|
||||||
|
|
||||||
|
Document document;
|
||||||
|
try {
|
||||||
|
File fXmlFile = new File(emmConfLocation);
|
||||||
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||||
|
document = documentBuilder.parse(fXmlFile);
|
||||||
|
} catch (ParserConfigurationException e) {
|
||||||
|
throw new KeystoreException("Error parsing configuration in ios-config.xml file");
|
||||||
|
} catch (SAXException e) {
|
||||||
|
throw new KeystoreException("SAX exception in ios-config.xml file");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new KeystoreException("Error reading ios-config.xml file");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String configEntry : emmConfigEntryNames) {
|
||||||
|
NodeList elements = document.getElementsByTagName(configEntry);
|
||||||
|
if (elements != null && elements.getLength() > 0) {
|
||||||
|
configMap.put(configEntry, elements.item(0).getTextContent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String emmKeyStoreLocation = replaceCarbonHomeEnvEntry(configMap.get(PATH_CERTIFICATE_KEYSTORE));
|
||||||
|
if (emmKeyStoreLocation != null) {
|
||||||
|
configMap.put(PATH_CERTIFICATE_KEYSTORE, emmKeyStoreLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return configMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getConfigEntry(final String entry) throws KeystoreException {
|
||||||
|
|
||||||
|
Map<String, String> configurationMap = readEMMConfigurations();
|
||||||
|
String configValue = configurationMap.get(entry);
|
||||||
|
|
||||||
|
if (configValue == null) {
|
||||||
|
throw new KeystoreException(String.format("Configuration entry %s not available", entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
return configValue.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String replaceCarbonHomeEnvEntry(String entry) {
|
||||||
|
if (entry != null && entry.toLowerCase().contains(CARBON_HOME_ENTRY)) {
|
||||||
|
return entry.replace(CARBON_HOME_ENTRY, System.getProperty(CARBON_HOME));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigurationUtil getInstance() {
|
||||||
|
if (configurationUtil == null) {
|
||||||
|
synchronized (ConfigurationUtil.class) {
|
||||||
|
if (configurationUtil == null) {
|
||||||
|
configurationUtil = new ConfigurationUtil();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return configurationUtil;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
package org.wso2.carbon.certificate.mgt.core.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CertificateGeneratorTestSuite {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(CertificateGeneratorTestSuite.class);
|
||||||
|
private static final String CA_CERT_PEM = "src/test/resources/ca_cert.pem";
|
||||||
|
private static final String RA_CERT_PEM = "src/test/resources/ra_cert.pem";
|
||||||
|
private static final String CA_PRIVATE_KEY_PATH = "src/test/resources/ca_private.key";
|
||||||
|
private final CertificateGenerator certificateGenerator = new CertificateGenerator();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetRootCertificates() {
|
||||||
|
try {
|
||||||
|
File caPemFile = new File(CA_CERT_PEM);
|
||||||
|
File raPemFile = new File(RA_CERT_PEM);
|
||||||
|
|
||||||
|
byte[] ca = FileUtils.readFileToByteArray(caPemFile);
|
||||||
|
byte[] ra = FileUtils.readFileToByteArray(raPemFile);
|
||||||
|
|
||||||
|
List<X509Certificate> rootCertificates = certificateGenerator.getRootCertificates(ca, ra);
|
||||||
|
Assert.assertNotNull(rootCertificates, "Root certificates retrieved");
|
||||||
|
|
||||||
|
Assert.assertEquals(rootCertificates.get(0).getType(), ConfigurationUtil.X_509);
|
||||||
|
Assert.assertEquals(rootCertificates.get(1).getType(), ConfigurationUtil.X_509);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Assert.fail("Error reading byte streams for CA and RA ", e);
|
||||||
|
} catch (KeystoreException e) {
|
||||||
|
Assert.fail("Error retrieving root certificates ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateX509Certificate() {
|
||||||
|
try {
|
||||||
|
X509Certificate certificate = certificateGenerator.generateX509Certificate();
|
||||||
|
|
||||||
|
Assert.assertNotNull(certificate, "Certificate received");
|
||||||
|
Assert.assertEquals(certificate.getType(), ConfigurationUtil.X_509);
|
||||||
|
} catch (KeystoreException e) {
|
||||||
|
Assert.fail("Error occurred while generating X509 certificate ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
// public void testGetPKIMessage() {
|
||||||
|
// try {
|
||||||
|
// byte[] pkiMessage = certificateGenerator.getPKIMessage(null);
|
||||||
|
// } catch (IOSEnrollmentException e) {
|
||||||
|
// Assert.fail("Error occurred while retrieving PKI Message ", e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateCertificateFromCSR() {
|
||||||
|
try {
|
||||||
|
X509Certificate certificate = certificateGenerator.generateX509Certificate();
|
||||||
|
|
||||||
|
Assert.assertNotNull(certificate, "Certificate received");
|
||||||
|
Assert.assertEquals(certificate.getType(), ConfigurationUtil.X_509);
|
||||||
|
} catch (KeystoreException e) {
|
||||||
|
Assert.fail("Error occurred while generating certificate ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
// public void testGetSignerKey() {
|
||||||
|
// try {
|
||||||
|
// PrivateKey privateKey = certificateGenerator.getSignerKey(CA_PRIVATE_KEY_PATH);
|
||||||
|
//
|
||||||
|
// Assert.assertNotNull(privateKey, "Private key received");
|
||||||
|
// Assert.assertEquals(privateKey.getAlgorithm(), ConfigurationUtil.RSA);
|
||||||
|
// } catch (KeystoreException e) {
|
||||||
|
// Assert.fail("Error occurred while generating certificate ", e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// public void testGetSigner() {
|
||||||
|
// try {
|
||||||
|
// X509Certificate certificate = certificateGenerator.getSigner(CA_CERT_PEM);
|
||||||
|
//
|
||||||
|
// Assert.assertNotNull(certificate, "Certificate received");
|
||||||
|
// Assert.assertEquals(certificate.getType(), ConfigurationUtil.X_509);
|
||||||
|
// } catch (KeystoreException e) {
|
||||||
|
// Assert.fail("Error while retrieving certificate ", e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package org.wso2.carbon.certificate.mgt.core.util;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class CommonUtilTestSuite {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(CommonUtilTestSuite.class);
|
||||||
|
private final CommonUtil commonUtil = new CommonUtil();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidityStartDate() {
|
||||||
|
Date validityStartDate = commonUtil.getValidityStartDate();
|
||||||
|
|
||||||
|
if(validityStartDate == null) {
|
||||||
|
Assert.fail("Validity start date is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Date todayDate = new Date();
|
||||||
|
Assert.assertTrue(validityStartDate.before(todayDate), "Validity start date is valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidityEndDate() {
|
||||||
|
Date validityEndDate = commonUtil.getValidityEndDate();
|
||||||
|
|
||||||
|
if(validityEndDate == null) {
|
||||||
|
Assert.fail("Validity end date is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Date todayDate = new Date();
|
||||||
|
Assert.assertTrue(validityEndDate.after(todayDate), "Validity end date is valid");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIF+zCCA+OgAwIBAgIJAJE458QXNuiLMA0GCSqGSIb3DQEBBQUAMIGLMQswCQYD
|
||||||
|
VQQGEwJVUzENMAsGA1UECBMEVGVzdDENMAsGA1UEBxMEVGVzdDERMA8GA1UEChMI
|
||||||
|
VGVzdCBPcmcxFjAUBgNVBAsTDVRlc3Qgb3JnIHVuaXQxFTATBgNVBAMTDFdTTzIg
|
||||||
|
Um9vdCBDQTEcMBoGCSqGSIb3DQEJARYNcm9vdEB3c28yLmNvbTAeFw0xNTAxMjcx
|
||||||
|
MjUxMjRaFw0xNzEwMjMxMjUxMjRaMIGLMQswCQYDVQQGEwJVUzENMAsGA1UECBME
|
||||||
|
VGVzdDENMAsGA1UEBxMEVGVzdDERMA8GA1UEChMIVGVzdCBPcmcxFjAUBgNVBAsT
|
||||||
|
DVRlc3Qgb3JnIHVuaXQxFTATBgNVBAMTDFdTTzIgUm9vdCBDQTEcMBoGCSqGSIb3
|
||||||
|
DQEJARYNcm9vdEB3c28yLmNvbTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoC
|
||||||
|
ggIBANJ756zjlkNKJf9O80qwFWxlwr4vOa80oaGXaO8Luj8ZNb7zyGATppTmZi2b
|
||||||
|
rRVfNPGHhN/0REb5+Gcf0xvk1b5Wp4E+JoDKfZMwOVQsMVmKYHqopgiiE28L/YoN
|
||||||
|
d0XmZA0J03nfQ4rzYggwQX7oRsW/AptkdURV4i8xD3SsqDGDZyYxQVDkj55nrweE
|
||||||
|
d5FWOnYvvpdbFJ4WanJmGe1WRtLMJ0jFi7tw9Wc7W/5+fvIA9bvHDHoG1VlfyjQU
|
||||||
|
SvTLlAN7Ui0ztXTcOZuN3HI0putMQRyaAD7Ljl7E1ROiqMhN/z80Bck8Yi7ELOmq
|
||||||
|
+cJOir/4CAamj8SugZ0iXo922slrSemWL9tjNT7MFmjFXmgIfVmaJF7OxKyxHhO8
|
||||||
|
gJKTlU2KSJJH2CzMwnGdRFrDlsAotVjGLYFWHUN4HW2uA2crEEmk+UduwnVMazqU
|
||||||
|
wBFxv+INf0U55bsXTv7C3L06IUaTBvxhxKQmzj9BeQGwWAC2Co4s5riT2ttivSRl
|
||||||
|
XijPIEDTfmvE/fjj4KfQQOTY3+EejacMe6gb/qVsCZ1g9Tbk7WLgjYHBuOQSAz3l
|
||||||
|
wPPqPY+6CakeL29wWyPg7pGzR6lMcYItUdHJuNsTijs0x6Xi1O5iIuL2o0vl8FRH
|
||||||
|
+tZFm3ujtCIHprjUgcn6aOR9Ms/NkUJCziKKAb4KoohNFgr/AgMBAAGjYDBeMB0G
|
||||||
|
A1UdDgQWBBSDhLDYVCYhJsxvK1ZNV05qGGVajjAfBgNVHSMEGDAWgBSDhLDYVCYh
|
||||||
|
JsxvK1ZNV05qGGVajjAPBgNVHRMBAf8EBTADAQH/MAsGA1UdDwQEAwIBhjANBgkq
|
||||||
|
hkiG9w0BAQUFAAOCAgEAykqOsxHV43Bx24+7DfxLNYyafBayHacQ4uwtldwexyQB
|
||||||
|
fIyJKjhzZUSvl37zhFPhJRJHogFIds+FoqaQsF8PvI/YSKs3UYRhje2mJan79lEA
|
||||||
|
rCd+3zDGmzQhmutVo7C1bCQuujV8YLIJGvvcnMcHnMLpc5CfjzmI2C6qMZ5XgpHx
|
||||||
|
/Mhindllqr0ZVvqRive0A2svW1k47XWB7BIfx/aoZ1viPHDNYVuYZ6j/NAFv8/Fu
|
||||||
|
3n/TfYOJ5rz0NPGHYXnmFcgGxtYTu5u6Q9YVdDLZv9lqYbMRSdiQ8SVDzwxft9N5
|
||||||
|
g6/VoXLoMpCS7/6jR3J0GbG2r/vr024QMOHDZHQDjkAVUBni6/bRHqj389RnOXhQ
|
||||||
|
+TSlx/hGgtdTpZRv63PjAqTCdDAhazWAgG/W+dxUhAywiOYHeXincuuDER0ypkfG
|
||||||
|
caUvbN9/mWtGJvtW+L9OlTj3LQlXD2ORehz5itS3eV0DVkscCOLzzkVLtIJeew1o
|
||||||
|
RmiADNOUe5A6V0cW5HIFi9F7Recqv9lGphwQeq+2cmvUKkSPcx+Z/SHTT/nIOioq
|
||||||
|
xxafJhci5dAEsPgtzxnA6QqPQtxOj46aZxQh5+hzZ/1CQq3UThDdQreJL51c+NOS
|
||||||
|
ZFQh6YVpJH6ZdSldBJnHjbS7RL/bv2kl1Pmv808T+iG+GpDw2XljwsI6TL8ACok=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIJKgIBAAKCAgEA0nvnrOOWQ0ol/07zSrAVbGXCvi85rzShoZdo7wu6Pxk1vvPI
|
||||||
|
YBOmlOZmLZutFV808YeE3/RERvn4Zx/TG+TVvlangT4mgMp9kzA5VCwxWYpgeqim
|
||||||
|
CKITbwv9ig13ReZkDQnTed9DivNiCDBBfuhGxb8Cm2R1RFXiLzEPdKyoMYNnJjFB
|
||||||
|
UOSPnmevB4R3kVY6di++l1sUnhZqcmYZ7VZG0swnSMWLu3D1Zztb/n5+8gD1u8cM
|
||||||
|
egbVWV/KNBRK9MuUA3tSLTO1dNw5m43ccjSm60xBHJoAPsuOXsTVE6KoyE3/PzQF
|
||||||
|
yTxiLsQs6ar5wk6Kv/gIBqaPxK6BnSJej3bayWtJ6ZYv22M1PswWaMVeaAh9WZok
|
||||||
|
Xs7ErLEeE7yAkpOVTYpIkkfYLMzCcZ1EWsOWwCi1WMYtgVYdQ3gdba4DZysQSaT5
|
||||||
|
R27CdUxrOpTAEXG/4g1/RTnluxdO/sLcvTohRpMG/GHEpCbOP0F5AbBYALYKjizm
|
||||||
|
uJPa22K9JGVeKM8gQNN+a8T9+OPgp9BA5Njf4R6Npwx7qBv+pWwJnWD1NuTtYuCN
|
||||||
|
gcG45BIDPeXA8+o9j7oJqR4vb3BbI+DukbNHqUxxgi1R0cm42xOKOzTHpeLU7mIi
|
||||||
|
4vajS+XwVEf61kWbe6O0IgemuNSByfpo5H0yz82RQkLOIooBvgqiiE0WCv8CAwEA
|
||||||
|
AQKCAgBAyt+AOvawdAzKULVX0mhl29Vc0hDBvEPdCEzG+Sc18T64LzcJTENFJr9h
|
||||||
|
XsCjCZG0n/DpN7ok1yH+LK/BsGmTk/0wLb+QecS6IGglXw058PzOBUhG9A1ja596
|
||||||
|
dba3j7pQwSuWIoIaLd2Jg8FFnZ7blHbq+ruWc5GS0Vleox+LTlXcTeE7U4BaVLRu
|
||||||
|
bfqYhKCubPgQg3sPRvsxh/iHNL3MegfFwPnIk3cXdhBVgP725BDA4v8WOTBHuNL3
|
||||||
|
wR9px5kikT20qGw9MuWQ2tR3W3neiLSqZ0WYDvUeexzUVIf8UPY3sH3vemUG3GCu
|
||||||
|
9XC4vZC8k091LKSo+MbxZfkR1JZ4R2CEMcFJaz/jc6VN2bTOWuWWczReOzq0Xx7P
|
||||||
|
GbsmcQNBhY8qBoz+cOWifxBWZzKSWfcNMgwnNyAKlDrOehpp+gZ1yH7dk9fL/wrE
|
||||||
|
jSEEnhq4SVDeGEOo7gEi17Px8/256PKwQB4wELPBwODBslPzJ0PPDKk4mxBq3JQP
|
||||||
|
EJKnBhu15KGJuoUZ42GcYSn55Zu/Rujqhn9cWbwhq0KrExwVI3EWnd89dYv360Mu
|
||||||
|
RskqPTuEpAUOUCQPIUT0p3f1PBgML6L5HxjJDUt6n2N8Y1xT8sKF6FKnbvdizcqz
|
||||||
|
v0+xdBk0xpSoazHzH1lnia3fZ6EPzMPHbLrz4ga0eUdaGwbSEQKCAQEA6sUljKKH
|
||||||
|
7EsKsXaQ6igqQ2TkZWTu+xqRlFjb2tTmyHt99O4w3L45ae0la7ApygTRFHs3z9XB
|
||||||
|
ws12bVkXdA35txKk97SNmWDrZbxpswHmTSnrOLGD2VFD4J/YifuBkT8K7PEJno9U
|
||||||
|
Ewi70RHGQEFfL3VL1TOa2WnJELOLkzoCkBL/NaVawtbK7O7KIrCu3jFCq3zu+uku
|
||||||
|
XVHTzXi+gr+uknGraxKcyLhCu6/7Uot+uYrtCzFsk4vTs2bovWuL2KLi/MAP8x3K
|
||||||
|
FcNNj2SPr+PzwzlqthiW/rtZjg7MFMdN9RAhImjbIJt3svzWsB4nr7VQxHYStfFJ
|
||||||
|
xIwbFp233qFKjQKCAQEA5YSK9L9o4LRDilwCz3p1tZ1tgY9tMUbG2wx0dG9xrETY
|
||||||
|
4yGwTPAc++Tp3aOnbO544ZpnGLBoQTgtOc1p4jyj/Md2CwlP8UfbYhEdYEN9Gn5H
|
||||||
|
ylu1b0cRwHeO4Bfnekqk8EL0rl3KUUsAk2uKEwCBwsuxjFurMDasyoA5T5gcsa4p
|
||||||
|
EhEF5D7t5sJb7f8hP+vMBa2yUKQT9dflF8xN7iHvxhun1qipX1AzZ341H94QbgRb
|
||||||
|
rYdfxzBr4aa5UZe5Ls9ofQf0S3zXVEXah/Pg+3o0BppdIrtLXTWcI/yeE6L8/Ebr
|
||||||
|
jMXLiTzd4bwWjbTijEJ/MKb/UsPQqbZsXNzMiyxuuwKCAQEAvs0xQkYJr+ohK6+Q
|
||||||
|
AS5ZguJpmVpZu6yRKn65V/V2BvQOn1RCU/Up1kQNCKNooy4c+sdVyc0RJ5AyspYY
|
||||||
|
sJJ3I+m8NzD/b+tMBSgGw5xEnuv1puLmpGUehF2E8Ed+uxwAdidDySD1lG6hrj4C
|
||||||
|
4NAAWyK6WfER5abK6Y7yXdpkoNE/p0rXI8jLrZo4n872n9BrPdJQq419yAwr1i9O
|
||||||
|
rha4+330chXzZFIUslNJL4H9oTAejN1DP/sBOCnn96KDSrK/RemWTOEmD1/mFicF
|
||||||
|
fE8IGt78Mjhz510+YGz4Qd7lJclRFJUhmjOgKdDBbutjF7OFi9XmSQZsDJhNn6jY
|
||||||
|
+dAeNQKCAQEAsAFpUfCq644xMRwIJ7VAKQrVnAIx+RTOj9JIR7XilPmi3OLLwORt
|
||||||
|
RZmw4f+K99UUK+Vs5Bj7ifAbdnUYmp5oHwOSeTol7OBu0xBO17BJcpSeVwbm5rO4
|
||||||
|
YEEO9rg+EaDGRV0DJ+fSq255vZM9Kf88gvYTbJArgeibrxqPWINMldD5u9oEC5la
|
||||||
|
dJhdSPBaPhuDtGMUGBULHX73Nr28kT3DEsfIeKuUXvwwv0+gS5TOQp/i8fqbLzPp
|
||||||
|
tvxUpsZUAxqYhTEhXPYaZoy+3Xze7dozpVCg1W6Nh6gB2fLyAhr+KDP2lFhmEhL0
|
||||||
|
EBRds0Oga3De+p9FsuFo1YyIItpLnPpw2wKCAQEArUQM9k0Qprczx9sKf/YF+ulx
|
||||||
|
tiiGyRUV7kAcrQiQAjB88wPoB/ovnW4VCI4y/mNeZGvyCWeQx9g+Ntc5BJlIlJYi
|
||||||
|
wviyQ5Lq1OlOWQlWIkKCI2Z+s5uYKTSgZRp7VLnvKswHnxBy2Bxq3i9taP6QYlZz
|
||||||
|
3ff/plfK3ZM6moc89wl/aQgdhWsV/WV7bKcnncM9K2N7dpKzRcZ+6iuJt9PNKo5V
|
||||||
|
6GUYEvn04twumzgqGtYQbiq63YfHe8QLvX/j8ffGH8O0rUAIrQnrNl0n0SoE9ECU
|
||||||
|
lUCVCXzypT+MKAeHfI4aFeWG48sdfnHPWOkyRHXWFLAwkHUVnqmYhXLpmJBtMw==
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<CertificateConfigurations>
|
||||||
|
<CertificateKeystore>
|
||||||
|
<!-- Certificate Keystore file location-->
|
||||||
|
<CertificateKeystoreLocation>${carbon.home}/repository/resources/security/wso2certs.jks</CertificateKeystoreLocation>
|
||||||
|
<!-- Certificate Keystore type (JKS/PKCS12 etc.)-->
|
||||||
|
<CertificateKeystoreType>JKS</CertificateKeystoreType>
|
||||||
|
<!-- Certificate Keystore password-->
|
||||||
|
<CertificateKeystorePassword>wso2carbon</CertificateKeystorePassword>
|
||||||
|
<!-- Certificate authority certificate alias -->
|
||||||
|
<CACertAlias>cacert</CACertAlias>
|
||||||
|
<!-- Certificate authority private key password -->
|
||||||
|
<CAPrivateKeyPassword>cacert</CAPrivateKeyPassword>
|
||||||
|
<!-- Registration authority certificate alias -->
|
||||||
|
<RACertAlias>racert</RACertAlias>
|
||||||
|
<!-- Registration authority private key password -->
|
||||||
|
<RAPrivateKeyPassword>racert</RAPrivateKeyPassword>
|
||||||
|
</CertificateKeystore>
|
||||||
|
</CertificateConfigurations>
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2015 WSO2, Inc. (http://wso2.com)
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# This is the log4j configuration file used by WSO2 Carbon
|
||||||
|
#
|
||||||
|
# IMPORTANT : Please do not remove or change the names of any
|
||||||
|
# of the Appenders defined here. The layout pattern & log file
|
||||||
|
# can be changed using the WSO2 Carbon Management Console, and those
|
||||||
|
# settings will override the settings in this file.
|
||||||
|
#
|
||||||
|
|
||||||
|
log4j.rootLogger=INFO, STD_OUT
|
||||||
|
|
||||||
|
# Redirect log messages to console
|
||||||
|
log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.STD_OUT.Target=System.out
|
||||||
|
log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIFqDCCA5CgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx
|
||||||
|
DTALBgNVBAgTBFRlc3QxDTALBgNVBAcTBFRlc3QxETAPBgNVBAoTCFRlc3QgT3Jn
|
||||||
|
MRYwFAYDVQQLEw1UZXN0IG9yZyB1bml0MRUwEwYDVQQDEwxXU08yIFJvb3QgQ0Ex
|
||||||
|
HDAaBgkqhkiG9w0BCQEWDXJvb3RAd3NvMi5jb20wHhcNMTUwMTI3MTI1MzAxWhcN
|
||||||
|
MTcxMDIzMTI1MzAxWjCBgzELMAkGA1UEBhMCVVMxGTAXBgNVBAgTEFRlc3QgUkEg
|
||||||
|
UHJvdmluY2UxFTATBgNVBAcTDFRlc3QgUkEgQ2l0eTEUMBIGA1UEChMLVGVzdCBS
|
||||||
|
QSBPcmcxGTAXBgNVBAsTEFRlc3QgUkEgb3JnIHVuaXQxETAPBgNVBAMTCFdTTzIg
|
||||||
|
UkEgMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAtUMgUlYYU3/TPfEe
|
||||||
|
zNAvBaiOi/jUjfZ9IbxvMl7obDT17/5vU68TCGkZRjyfYUEiGNBisUEFWjSk/sGL
|
||||||
|
/ofYKUAxw33cd456FLMjaJX/4Zk4y8eYB1m1GGlHejoDyjPhq8S6GDmy+PXbJr8n
|
||||||
|
lSTROR2mQHkGwYrCreWeU4AYWzdctIFk7U2DKeIvZYSidIIjfSpDXURxrt9LPvig
|
||||||
|
fMzr5l/WkZfjvk5S+W7rgMtpllxlEPgyDc07pNAdNSq5FB990oaUsVX8o6l6wdCw
|
||||||
|
grYz83edPOKwZa04fsVztz2oF3ZYSGGjD3lwh0KS/jUL+awRyhMx5p/O1hySg6PP
|
||||||
|
pJjeqRuobNTuwSAXxp3nsNSY0DkGW04pSxWoDQqhnpaqBbAf71l6ya2e3so1SHm/
|
||||||
|
jouWSYTHncq5bmGE4AN7ZGVGZvfx84+UR8fNxJxxLo+DFFE0oJNzpPGNxILpHxgT
|
||||||
|
V7IOII6mhfkrQk+AFQiW2Y5FXLVYv8r+SPXW8pYsjaWl971XZeM/HC3L9IZkCrrr
|
||||||
|
a0ID5oT6vt+xTmdo4yiBqIP5TBYm+1a9YzMAy7XGtPih9k6cufMLcfzvUZdOXw9x
|
||||||
|
3T05nM5ZtcDq0gHvUzQ7sfHTguWVnuHVEdb2ox4x2L5NzEA475fbSdXpMok9z/z7
|
||||||
|
Xa71vIZi28InDAFBQehUlJnFtf0CAwEAAaMdMBswDAYDVR0TBAUwAwEB/zALBgNV
|
||||||
|
HQ8EBAMCBaAwDQYJKoZIhvcNAQEFBQADggIBAAO0TwnQBMJvL8wbfsnTqAGCCHM4
|
||||||
|
x1cpW+KgTmflPEliYGOn/dJYDz/dUowCgoj5mrSxjQ3G1/qL+9Y7E33h0tyw37vH
|
||||||
|
YDL1p2Tn+fwmXRHrk+CHoPHNcImEfSIDWbbG7ehBR6erVfbQSZjmj4fwPkItp8rP
|
||||||
|
nyUtXHOLpfFYoAxYkNP9+C8vpC9W/H1pj3rzmQFA1z+EZAKVV7vDAxbe6sun84nf
|
||||||
|
YAaMSIzHx1B+XLHokgChmnZr3wV7EypBEmmKp4ITvJqK7WsIG9t1M6hI7OTPCURR
|
||||||
|
mdy+DJtIoIUbZxHyIyC9nPcVJFkdBusnfXq4uMb0KMaWYCU8ESqZPySukF2qZ5KA
|
||||||
|
acB+0ZhY+EGQ6QF/hB6iiUj96BlQ7XAPXFU6xUt6nRjDiJmb3vW1IEv0hpbs7PRl
|
||||||
|
UMlbOwQk37rXpFqQc6ZW7lsxI2RmfkD4DOkQIGH3q5foVr+PEp0uSPWrFX62eBet
|
||||||
|
1S4c/opVv6BcuUgilYABHTYxb45GfYwJAI9Qw2uQWT8DmhtVbcYu6GLYGlnRyaOC
|
||||||
|
EPzc0z0KQTjhsgHWzi60IYBBh+fy+Z7w5X1rTTvhFOoU5J7kedGEqiBatIZmhF5t
|
||||||
|
UFbT0u350ET5a0Kg83gu5aLwXdoIP9o7bp3XzLBMVNny2RX3tOHUA2HBe/p0h0OU
|
||||||
|
Ggt3G6oD0gBe9pZI
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
|
|
||||||
|
<suite name="iOS-MDM-Tests">
|
||||||
|
<test name="Operatoin Bean validation tests" preserve-order="true">
|
||||||
|
<classes>
|
||||||
|
<class name="org.wso2.carbon.certificate.mgt.core.impl.CertificateGeneratorTestSuite"/>
|
||||||
|
<class name="org.wso2.carbon.certificate.mgt.core.util.CommonUtil"/>
|
||||||
|
</classes>
|
||||||
|
</test>
|
||||||
|
</suite>
|
||||||
Binary file not shown.
60
components/certificate-mgt/pom.xml
Normal file
60
components/certificate-mgt/pom.xml
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>certificate-mgt</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>WSO2 Carbon - Certificate Management Component</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>org.wso2.carbon.certificate.mgt.core</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-scr-plugin</artifactId>
|
||||||
|
<version>1.7.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>generate-scr-scrdescriptor</id>
|
||||||
|
<goals>
|
||||||
|
<goal>scr</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@ -19,9 +19,12 @@ package org.wso2.carbon.device.mgt.common;
|
|||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Device {
|
public class Device implements Serializable{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1998101711L;
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
|
|||||||
@ -18,7 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.common;
|
package org.wso2.carbon.device.mgt.common;
|
||||||
|
|
||||||
public class EnrolmentInfo {
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class EnrolmentInfo implements Serializable{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1998101712L;
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED, DISENROLLMENT_REQUESTED
|
CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED, DISENROLLMENT_REQUESTED
|
||||||
@ -28,6 +32,7 @@ public class EnrolmentInfo {
|
|||||||
BYOD, COPE
|
BYOD, COPE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int id;
|
||||||
private Device device;
|
private Device device;
|
||||||
private Long dateOfEnrolment;
|
private Long dateOfEnrolment;
|
||||||
private Long dateOfLastUpdate;
|
private Long dateOfLastUpdate;
|
||||||
@ -44,6 +49,14 @@ public class EnrolmentInfo {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getDateOfEnrolment() {
|
public Long getDateOfEnrolment() {
|
||||||
return dateOfEnrolment;
|
return dateOfEnrolment;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.wso2.carbon.device.mgt.common.configuration.mgt;
|
||||||
|
|
||||||
|
public class ConfigurationManagementException extends Exception {
|
||||||
|
private static final long serialVersionUID = -3151279311929070299L;
|
||||||
|
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationManagementException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationManagementException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
setErrorMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationManagementException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
setErrorMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationManagementException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationManagementException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.wso2.carbon.device.mgt.common.configuration.mgt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This represents the tenant configuration management functionality which should be implemented by
|
||||||
|
* the device type plugins.
|
||||||
|
*/
|
||||||
|
public interface TenantConfigurationManagementService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to add a operation to a device or a set of devices.
|
||||||
|
*
|
||||||
|
* @param tenantConfiguration Operation to be added.
|
||||||
|
* @param resourcePath Registry resource path.
|
||||||
|
* @throws org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException If some unusual behaviour is observed while adding the
|
||||||
|
* configuration.
|
||||||
|
*/
|
||||||
|
public boolean saveConfiguration(TenantConfiguration tenantConfiguration, String resourcePath) throws ConfigurationManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to retrieve the list of general tenant configurations.
|
||||||
|
*
|
||||||
|
* @param resourcePath Registry resource path.
|
||||||
|
* @throws org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException If some unusual behaviour is observed while fetching the
|
||||||
|
* operation list.
|
||||||
|
*/
|
||||||
|
public TenantConfiguration getConfiguration(String resourcePath) throws ConfigurationManagementException;
|
||||||
|
|
||||||
|
}
|
||||||
@ -61,6 +61,7 @@
|
|||||||
org.apache.commons.logging,
|
org.apache.commons.logging,
|
||||||
javax.naming,
|
javax.naming,
|
||||||
javax.xml.*,
|
javax.xml.*,
|
||||||
|
javax.servlet.*,
|
||||||
org.xml.sax,
|
org.xml.sax,
|
||||||
javax.sql.*,
|
javax.sql.*,
|
||||||
org.wso2.carbon.context,
|
org.wso2.carbon.context,
|
||||||
@ -71,13 +72,19 @@
|
|||||||
org.wso2.carbon.user.api,
|
org.wso2.carbon.user.api,
|
||||||
org.wso2.carbon.user.core.*,
|
org.wso2.carbon.user.core.*,
|
||||||
org.wso2.carbon.registry.core.service,
|
org.wso2.carbon.registry.core.service,
|
||||||
|
org.wso2.carbon.registry.core,
|
||||||
|
org.wso2.carbon.registry.core.exceptions,
|
||||||
|
org.wso2.carbon.registry.core.session,
|
||||||
|
org.wso2.carbon.registry.api,
|
||||||
org.w3c.dom,
|
org.w3c.dom,
|
||||||
org.wso2.carbon.identity.oauth.stub,
|
org.wso2.carbon.identity.oauth.stub,
|
||||||
org.wso2.carbon.identity.oauth.stub.dto,
|
org.wso2.carbon.identity.oauth.stub.dto,
|
||||||
org.wso2.carbon.ndatasource.core,
|
org.wso2.carbon.ndatasource.core,
|
||||||
org.wso2.carbon.apimgt.impl,
|
org.wso2.carbon.apimgt.impl,
|
||||||
org.wso2.carbon.ndatasource.core,
|
org.wso2.carbon.ndatasource.core,
|
||||||
org.apache.axis2.transport.mail
|
org.apache.axis2.transport.mail,
|
||||||
|
org.apache.catalina,
|
||||||
|
org.apache.catalina.core
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
<Export-Package>
|
<Export-Package>
|
||||||
!org.wso2.carbon.device.mgt.core.internal,
|
!org.wso2.carbon.device.mgt.core.internal,
|
||||||
|
|||||||
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.wso2.carbon.device.mgt.core.config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class holds the constants used throughout the configuration manager.
|
||||||
|
*/
|
||||||
|
public class ConfigurationManagerConstants {
|
||||||
|
|
||||||
|
public static final class ContentTypes {
|
||||||
|
private ContentTypes() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String CONTENT_TYPE_ANY = "*/*";
|
||||||
|
public static final String MEDIA_TYPE_XML = "application/xml";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class CharSets {
|
||||||
|
private CharSets() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String CHARSET_UTF8 = "UTF8";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.device.mgt.core.config.permission;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
@XmlRootElement(name = "Permission")
|
||||||
|
public class Permission{
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "name", required = true)
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "path", required = true)
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.device.mgt.core.config.permission;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@XmlRootElement(name = "PermissionConfiguration")
|
||||||
|
public class PermissionConfiguration {
|
||||||
|
|
||||||
|
private List<Permission> permissions;
|
||||||
|
|
||||||
|
public List<Permission> getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "Permission", required = true)
|
||||||
|
public void setPermissions(List<Permission> permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.device.mgt.core.config.permission;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class will add, update custom permissions defined in permission.xml in webapps.
|
||||||
|
*/
|
||||||
|
public class PermissionManager {
|
||||||
|
|
||||||
|
private static PermissionManager permissionManager;
|
||||||
|
|
||||||
|
public static PermissionManager getInstance() {
|
||||||
|
if (permissionManager == null) {
|
||||||
|
synchronized (PermissionManager.class) {
|
||||||
|
if (permissionManager == null) {
|
||||||
|
permissionManager = new PermissionManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return permissionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addPermission(Permission permission) throws DeviceManagementException {
|
||||||
|
try {
|
||||||
|
return PermissionUtils.putPermission(permission);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
throw new DeviceManagementException("Error occurred while adding the permission : " +
|
||||||
|
permission.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addPermissions(List<Permission> permissions) throws DeviceManagementException{
|
||||||
|
for(Permission permission:permissions){
|
||||||
|
this.addPermission(permission);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializePermissions(InputStream permissionStream) throws DeviceManagementException {
|
||||||
|
try {
|
||||||
|
if(permissionStream != null){
|
||||||
|
/* Un-marshaling Device Management configuration */
|
||||||
|
JAXBContext cdmContext = JAXBContext.newInstance(PermissionConfiguration.class);
|
||||||
|
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
||||||
|
PermissionConfiguration permissionConfiguration = (PermissionConfiguration)
|
||||||
|
unmarshaller.unmarshal(permissionStream);
|
||||||
|
if((permissionConfiguration != null) && (permissionConfiguration.getPermissions() != null)){
|
||||||
|
this.addPermissions(permissionConfiguration.getPermissions());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
throw new DeviceManagementException("Error occurred while initializing Data Source config", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.device.mgt.core.config.permission;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.registry.api.RegistryException;
|
||||||
|
import org.wso2.carbon.registry.api.Resource;
|
||||||
|
import org.wso2.carbon.registry.core.Registry;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class which holds necessary utility methods required for persisting permissions in
|
||||||
|
* registry.
|
||||||
|
*/
|
||||||
|
public class PermissionUtils {
|
||||||
|
|
||||||
|
public static String ADMIN_PERMISSION_REGISTRY_PATH = "/permission/admin";
|
||||||
|
public static String PERMISSION_PROPERTY_NAME = "name";
|
||||||
|
|
||||||
|
public static Registry getGovernanceRegistry() throws DeviceManagementException {
|
||||||
|
try {
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
return DeviceManagementDataHolder.getInstance().getRegistryService()
|
||||||
|
.getGovernanceSystemRegistry(
|
||||||
|
tenantId);
|
||||||
|
} catch (RegistryException e) {
|
||||||
|
throw new DeviceManagementException(
|
||||||
|
"Error in retrieving governance registry instance: " +
|
||||||
|
e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Permission getPermission(String path) throws DeviceManagementException {
|
||||||
|
try {
|
||||||
|
Resource resource = PermissionUtils.getGovernanceRegistry().get(path);
|
||||||
|
Permission permission = new Permission();
|
||||||
|
permission.setName(resource.getProperty(PERMISSION_PROPERTY_NAME));
|
||||||
|
permission.setPath(resource.getPath());
|
||||||
|
return permission;
|
||||||
|
} catch (RegistryException e) {
|
||||||
|
throw new DeviceManagementException("Error in retrieving registry resource : " +
|
||||||
|
e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean putPermission(Permission permission)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
boolean status;
|
||||||
|
try {
|
||||||
|
Resource resource = PermissionUtils.getGovernanceRegistry().newCollection();
|
||||||
|
resource.addProperty(PERMISSION_PROPERTY_NAME, permission.getName());
|
||||||
|
PermissionUtils.getGovernanceRegistry().beginTransaction();
|
||||||
|
PermissionUtils.getGovernanceRegistry().put(ADMIN_PERMISSION_REGISTRY_PATH +
|
||||||
|
permission.getPath(), resource);
|
||||||
|
PermissionUtils.getGovernanceRegistry().commitTransaction();
|
||||||
|
status = true;
|
||||||
|
} catch (RegistryException e) {
|
||||||
|
throw new DeviceManagementException(
|
||||||
|
"Error occurred while persisting permission : " +
|
||||||
|
permission.getName(), e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkPermissionExistance(Permission permission)
|
||||||
|
throws DeviceManagementException,
|
||||||
|
org.wso2.carbon.registry.core.exceptions.RegistryException {
|
||||||
|
return PermissionUtils.getGovernanceRegistry().resourceExists(permission.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Document convertToDocument(File file) throws DeviceManagementException {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
factory.setNamespaceAware(true);
|
||||||
|
try {
|
||||||
|
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||||
|
return docBuilder.parse(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DeviceManagementException("Error occurred while parsing file, while converting " +
|
||||||
|
"to a org.w3c.dom.Document", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.device.mgt.core.config.permission.lifecycle;
|
||||||
|
|
||||||
|
import org.apache.catalina.Lifecycle;
|
||||||
|
import org.apache.catalina.LifecycleEvent;
|
||||||
|
import org.apache.catalina.LifecycleListener;
|
||||||
|
import org.apache.catalina.core.StandardContext;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.permission.PermissionManager;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class WebAppDeploymentLifecycleListener implements LifecycleListener {
|
||||||
|
|
||||||
|
private static final String PERMISSION_CONFIG_PATH = "META-INF" + File.separator + "permissions.xml";
|
||||||
|
private static final Log log = LogFactory.getLog(WebAppDeploymentLifecycleListener.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lifecycleEvent(LifecycleEvent lifecycleEvent) {
|
||||||
|
if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType())) {
|
||||||
|
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
|
||||||
|
ServletContext servletContext = context.getServletContext();
|
||||||
|
try {
|
||||||
|
PermissionManager.getInstance().initializePermissions(servletContext.getResourceAsStream(PERMISSION_CONFIG_PATH));
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Exception occurred while adding the permissions from webapp : "
|
||||||
|
+ servletContext.getContextPath(),e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -24,34 +24,64 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||||||
@XmlRootElement(name = "PolicyConfiguration")
|
@XmlRootElement(name = "PolicyConfiguration")
|
||||||
public class PolicyConfiguration {
|
public class PolicyConfiguration {
|
||||||
|
|
||||||
private String monitoringClass;
|
private String monitoringClass;
|
||||||
private int maxRetries;
|
private boolean monitoringEnable;
|
||||||
private int minRetriesToMarkUnreachable;
|
private int monitoringFrequency;
|
||||||
|
private int maxRetries;
|
||||||
|
private int minRetriesToMarkUnreachable;
|
||||||
|
private int minRetriesToMarkInactive;
|
||||||
|
|
||||||
@XmlElement(name = "monitoringClass", required = true)
|
@XmlElement(name = "monitoringClass", required = true)
|
||||||
public String getMonitoringClass() {
|
public String getMonitoringClass() {
|
||||||
return monitoringClass;
|
return monitoringClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMonitoringClass(String monitoringClass) {
|
public void setMonitoringClass(String monitoringClass) {
|
||||||
this.monitoringClass = monitoringClass;
|
this.monitoringClass = monitoringClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "maxRetries", required = true)
|
@XmlElement(name = "maxRetries", required = true)
|
||||||
public int getMaxRetries() {
|
public int getMaxRetries() {
|
||||||
return maxRetries;
|
return maxRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxRetries(int maxRetries) {
|
public void setMaxRetries(int maxRetries) {
|
||||||
this.maxRetries = maxRetries;
|
this.maxRetries = maxRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "minRetriesToMarkUnreachable", required = true)
|
@XmlElement(name = "minRetriesToMarkUnreachable", required = true)
|
||||||
public int getMinRetriesToMarkUnreachable() {
|
public int getMinRetriesToMarkUnreachable() {
|
||||||
return minRetriesToMarkUnreachable;
|
return minRetriesToMarkUnreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMinRetriesToMarkUnreachable(int minRetriesToMarkUnreachable) {
|
public void setMinRetriesToMarkUnreachable(int minRetriesToMarkUnreachable) {
|
||||||
this.minRetriesToMarkUnreachable = minRetriesToMarkUnreachable;
|
this.minRetriesToMarkUnreachable = minRetriesToMarkUnreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "monitoringEnable", required = true)
|
||||||
|
public boolean getMonitoringEnable() {
|
||||||
|
return monitoringEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMonitoringEnable(boolean monitoringEnable) {
|
||||||
|
this.monitoringEnable = monitoringEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "minRetriesToMarkInactive", required = true)
|
||||||
|
public int getMinRetriesToMarkInactive() {
|
||||||
|
return minRetriesToMarkInactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinRetriesToMarkInactive(int minRetriesToMarkInactive) {
|
||||||
|
this.minRetriesToMarkInactive = minRetriesToMarkInactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "monitoringFrequency", required = true)
|
||||||
|
public int getMonitoringFrequency() {
|
||||||
|
return monitoringFrequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMonitoringFrequency(int monitoringFrequency) {
|
||||||
|
this.monitoringFrequency = monitoringFrequency;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.wso2.carbon.device.mgt.core.config.tenant;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfigurationManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.ConfigurationManagerConstants;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.util.ConfigurationManagerUtil;
|
||||||
|
import org.wso2.carbon.registry.api.Resource;
|
||||||
|
import org.wso2.carbon.registry.api.RegistryException;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.bind.Marshaller;
|
||||||
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class implements all the functionality exposed as part of the TenantConfigurationManagementService. Main usage of
|
||||||
|
* this module is, saving/retrieving tenant configurations to the registry.
|
||||||
|
*/
|
||||||
|
public class TenantConfigurationManagementServiceImpl
|
||||||
|
implements TenantConfigurationManagementService {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(TenantConfigurationManagementServiceImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean saveConfiguration(TenantConfiguration tenantConfiguration, String resourcePath)
|
||||||
|
throws ConfigurationManagementException {
|
||||||
|
boolean status;
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Persisting tenant configurations in Registry");
|
||||||
|
}
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||||
|
Marshaller marshaller = context.createMarshaller();
|
||||||
|
marshaller.marshal(tenantConfiguration, writer);
|
||||||
|
|
||||||
|
Resource resource = ConfigurationManagerUtil.getConfigurationRegistry().newResource();
|
||||||
|
resource.setContent(writer.toString());
|
||||||
|
resource.setMediaType(ConfigurationManagerConstants.ContentTypes.MEDIA_TYPE_XML);
|
||||||
|
ConfigurationManagerUtil.putRegistryResource(resourcePath, resource);
|
||||||
|
status = true;
|
||||||
|
} catch (RegistryException e) {
|
||||||
|
throw new ConfigurationManagementException(
|
||||||
|
"Error occurred while persisting the Registry resource of Tenant Configuration : " + e.getMessage(), e);
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
throw new ConfigurationManagementException(
|
||||||
|
"Error occurred while parsing the Tenant configuration : " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TenantConfiguration getConfiguration(String resourcePath)
|
||||||
|
throws ConfigurationManagementException {
|
||||||
|
Resource resource;
|
||||||
|
try {
|
||||||
|
resource = ConfigurationManagerUtil.getRegistryResource(resourcePath);
|
||||||
|
if(resource != null){
|
||||||
|
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||||
|
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||||
|
return (TenantConfiguration) unmarshaller.unmarshal(
|
||||||
|
new StringReader(new String((byte[]) resource.getContent(), Charset
|
||||||
|
.forName(ConfigurationManagerConstants.CharSets.CHARSET_UTF8))));
|
||||||
|
}
|
||||||
|
return new TenantConfiguration();
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
throw new ConfigurationManagementException(
|
||||||
|
"Error occurred while parsing the Tenant configuration : " + e.getMessage(), e);
|
||||||
|
} catch (RegistryException e) {
|
||||||
|
throw new ConfigurationManagementException(
|
||||||
|
"Error occurred while retrieving the Registry resource of Tenant Configuration : " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.wso2.carbon.device.mgt.core.config.util;
|
||||||
|
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.wso2.carbon.registry.api.RegistryException;
|
||||||
|
import org.wso2.carbon.registry.api.Resource;
|
||||||
|
import org.wso2.carbon.registry.core.Registry;
|
||||||
|
|
||||||
|
public class ConfigurationManagerUtil {
|
||||||
|
|
||||||
|
public static Registry getConfigurationRegistry() throws ConfigurationManagementException {
|
||||||
|
try {
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
return DeviceManagementDataHolder.getInstance().getRegistryService()
|
||||||
|
.getConfigSystemRegistry(
|
||||||
|
tenantId);
|
||||||
|
} catch (RegistryException e) {
|
||||||
|
throw new ConfigurationManagementException(
|
||||||
|
"Error in retrieving governance registry instance: " +
|
||||||
|
e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Resource getRegistryResource(String path) throws ConfigurationManagementException {
|
||||||
|
try {
|
||||||
|
if(ConfigurationManagerUtil.getConfigurationRegistry().resourceExists(path)){
|
||||||
|
return ConfigurationManagerUtil.getConfigurationRegistry().get(path);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (RegistryException e) {
|
||||||
|
throw new ConfigurationManagementException("Error in retrieving registry resource : " +
|
||||||
|
e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean putRegistryResource(String path,
|
||||||
|
Resource resource)
|
||||||
|
throws ConfigurationManagementException {
|
||||||
|
boolean status;
|
||||||
|
try {
|
||||||
|
ConfigurationManagerUtil.getConfigurationRegistry().beginTransaction();
|
||||||
|
ConfigurationManagerUtil.getConfigurationRegistry().put(path, resource);
|
||||||
|
ConfigurationManagerUtil.getConfigurationRegistry().commitTransaction();
|
||||||
|
status = true;
|
||||||
|
} catch (RegistryException e) {
|
||||||
|
throw new ConfigurationManagementException(
|
||||||
|
"Error occurred while persisting registry resource : " +
|
||||||
|
e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -111,7 +111,7 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
||||||
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
||||||
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
||||||
"AND TENANT_ID = ?";
|
"AND TENANT_ID = ?";
|
||||||
@ -206,8 +206,8 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
||||||
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, d.ID, d.DESCRIPTION, " +
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, " +
|
||||||
"d.NAME, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
|
"d.ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
|
||||||
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " +
|
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " +
|
||||||
"WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? AND e.OWNER = ?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? AND e.OWNER = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
@ -468,6 +468,7 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
|
|
||||||
private EnrolmentInfo loadEnrolment(ResultSet rs) throws SQLException {
|
private EnrolmentInfo loadEnrolment(ResultSet rs) throws SQLException {
|
||||||
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setId(rs.getInt("ENROLMENT_ID"));
|
||||||
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
||||||
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
||||||
enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime());
|
enrolmentInfo.setDateOfEnrolment(rs.getTimestamp("DATE_OF_ENROLMENT").getTime());
|
||||||
@ -486,9 +487,9 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|||||||
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
||||||
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||||
"e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
|
"e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
|
||||||
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " +
|
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " +
|
||||||
"AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_ID = e.DEVICE_ID " +
|
"WHERE TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
|
||||||
"AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
|
"WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setString(2, status.toString());
|
stmt.setString(2, status.toString());
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import org.osgi.service.component.ComponentContext;
|
|||||||
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfigurationManagementService;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
@ -36,6 +37,7 @@ import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfiguration
|
|||||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.tenant.TenantConfigurationManagementServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||||
@ -171,6 +173,11 @@ public class DeviceManagementServiceComponent {
|
|||||||
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
|
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
|
||||||
bundleContext.registerService(DeviceManagementProviderService.class.getName(), deviceManagementProvider, null);
|
bundleContext.registerService(DeviceManagementProviderService.class.getName(), deviceManagementProvider, null);
|
||||||
|
|
||||||
|
/* Registering Tenant Configuration Management Service */
|
||||||
|
TenantConfigurationManagementService
|
||||||
|
tenantConfiguration = new TenantConfigurationManagementServiceImpl();
|
||||||
|
bundleContext.registerService(TenantConfigurationManagementService.class.getName(), tenantConfiguration, null);
|
||||||
|
|
||||||
/* Registering App Management service */
|
/* Registering App Management service */
|
||||||
try {
|
try {
|
||||||
AppManagementConfigurationManager.getInstance().initConfig();
|
AppManagementConfigurationManager.getInstance().initConfig();
|
||||||
|
|||||||
@ -42,6 +42,8 @@ public class Policy implements Comparable<Policy>, Serializable {
|
|||||||
private String ownershipType; // Ownership type (COPE, BYOD, CPE)
|
private String ownershipType; // Ownership type (COPE, BYOD, CPE)
|
||||||
private List<Device> devices; // Individual devices this policy should be applied
|
private List<Device> devices; // Individual devices this policy should be applied
|
||||||
private List<String> users;
|
private List<String> users;
|
||||||
|
private boolean active;
|
||||||
|
private boolean updated;
|
||||||
|
|
||||||
|
|
||||||
/* Compliance data*/
|
/* Compliance data*/
|
||||||
@ -53,19 +55,6 @@ public class Policy implements Comparable<Policy>, Serializable {
|
|||||||
|
|
||||||
private List<PolicyCriterion> policyCriterias;
|
private List<PolicyCriterion> policyCriterias;
|
||||||
|
|
||||||
/*These are related to time based policies*/
|
|
||||||
|
|
||||||
// private int startTime; // Start time to apply the policy.
|
|
||||||
// private int endTime; // After this time policy will not be applied
|
|
||||||
// private Date startDate; // Start date to apply the policy
|
|
||||||
// private Date endDate; // After this date policy will not be applied.
|
|
||||||
|
|
||||||
|
|
||||||
/*These are related to location based policies*/
|
|
||||||
|
|
||||||
// private String latitude; // Latitude
|
|
||||||
// private String longitude; // Longitude
|
|
||||||
//
|
|
||||||
private int tenantId;
|
private int tenantId;
|
||||||
private int profileId;
|
private int profileId;
|
||||||
|
|
||||||
@ -163,6 +152,24 @@ public class Policy implements Comparable<Policy>, Serializable {
|
|||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActive(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public boolean isUpdated() {
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdated(boolean updated) {
|
||||||
|
this.updated = updated;
|
||||||
|
}
|
||||||
|
|
||||||
@XmlElement
|
@XmlElement
|
||||||
public List<PolicyCriterion> getPolicyCriterias() {
|
public List<PolicyCriterion> getPolicyCriterias() {
|
||||||
return policyCriterias;
|
return policyCriterias;
|
||||||
@ -172,6 +179,7 @@ public class Policy implements Comparable<Policy>, Serializable {
|
|||||||
this.policyCriterias = policyCriterias;
|
this.policyCriterias = policyCriterias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
public String getCompliance() {
|
public String getCompliance() {
|
||||||
return Compliance;
|
return Compliance;
|
||||||
}
|
}
|
||||||
@ -180,59 +188,6 @@ public class Policy implements Comparable<Policy>, Serializable {
|
|||||||
Compliance = compliance;
|
Compliance = compliance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public int getStartTime() {
|
|
||||||
// return startTime;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setStartTime(int startTime) {
|
|
||||||
// this.startTime = startTime;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @XmlElement
|
|
||||||
// public int getEndTime() {
|
|
||||||
// return endTime;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setEndTime(int endTime) {
|
|
||||||
// this.endTime = endTime;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @XmlElement
|
|
||||||
// public Date getStartDate() {
|
|
||||||
// return startDate;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setStartDate(Date startDate) {
|
|
||||||
// this.startDate = startDate;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @XmlElement
|
|
||||||
// public Date getEndDate() {
|
|
||||||
// return endDate;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setEndDate(Date endDate) {
|
|
||||||
// this.endDate = endDate;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @XmlElement
|
|
||||||
// public String getLatitude() {
|
|
||||||
// return latitude;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setLatitude(String latitude) {
|
|
||||||
// this.latitude = latitude;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @XmlElement
|
|
||||||
// public String getLongitude() {
|
|
||||||
// return longitude;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setLongitude(String longitude) {
|
|
||||||
// this.longitude = longitude;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@XmlElement
|
@XmlElement
|
||||||
public Map<String, Object> getAttributes() {
|
public Map<String, Object> getAttributes() {
|
||||||
return attributes;
|
return attributes;
|
||||||
@ -252,18 +207,6 @@ public class Policy implements Comparable<Policy>, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* static final Comparator<Policy> PRIORITY_ORDER =
|
|
||||||
new Comparator<Policy>() {
|
|
||||||
public int compare(Policy p1, Policy p2) {
|
|
||||||
int dateCmp = new Integer(p2.getId()).compareTo(new Integer(p1.getId()));
|
|
||||||
if (dateCmp != 0)
|
|
||||||
return dateCmp;
|
|
||||||
|
|
||||||
return (p1.getId() < p2.getId() ? -1 :
|
|
||||||
(p1.getId() == p2.getId() ? 0 : 1));
|
|
||||||
}
|
|
||||||
};*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Policy o) {
|
public int compareTo(Policy o) {
|
||||||
if (this.priorityId == o.priorityId)
|
if (this.priorityId == o.priorityId)
|
||||||
|
|||||||
@ -40,9 +40,15 @@ public interface PolicyAdministratorPoint {
|
|||||||
|
|
||||||
boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException;
|
boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException;
|
||||||
|
|
||||||
|
void activatePolicy(int policyId) throws PolicyManagementException;
|
||||||
|
|
||||||
|
void inactivatePolicy(int policyId) throws PolicyManagementException;
|
||||||
|
|
||||||
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
boolean deletePolicy(Policy policy) throws PolicyManagementException;
|
||||||
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
||||||
|
|
||||||
|
void publishChanges() throws PolicyManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method adds a policy per device which should be implemented by the related plugins.
|
* This method adds a policy per device which should be implemented by the related plugins.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -23,6 +23,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface PolicyFilter {
|
public interface PolicyFilter {
|
||||||
|
|
||||||
|
List<Policy> filterActivePolicies(List<Policy> policies);
|
||||||
|
|
||||||
List<Policy> filterRolesBasedPolicies(String roles[], List<Policy> policies);
|
List<Policy> filterRolesBasedPolicies(String roles[], List<Policy> policies);
|
||||||
|
|
||||||
List<Policy> filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies);
|
List<Policy> filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies);
|
||||||
|
|||||||
@ -55,8 +55,6 @@
|
|||||||
<Bundle-Description>Policy Management Core Bundle</Bundle-Description>
|
<Bundle-Description>Policy Management Core Bundle</Bundle-Description>
|
||||||
<Private-Package>org.wso2.carbon.policy.mgt.core.internal</Private-Package>
|
<Private-Package>org.wso2.carbon.policy.mgt.core.internal</Private-Package>
|
||||||
<Import-Package>
|
<Import-Package>
|
||||||
org.apache.axis2.*;
|
|
||||||
version="${axis2.osgi.version.range}",
|
|
||||||
org.osgi.framework,
|
org.osgi.framework,
|
||||||
org.osgi.service.component,
|
org.osgi.service.component,
|
||||||
org.apache.commons.logging,
|
org.apache.commons.logging,
|
||||||
@ -144,6 +142,15 @@
|
|||||||
<artifactId>org.wso2.carbon.ntask.core</artifactId>
|
<artifactId>org.wso2.carbon.ntask.core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Registry dependencies-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.registry.api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.registry.core</artifactId>
|
||||||
|
</dependency>
|
||||||
<!-- Policy Management Dependencies-->
|
<!-- Policy Management Dependencies-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
|||||||
@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.core.cache;
|
package org.wso2.carbon.policy.mgt.core.cache;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.policy.mgt.policy.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -29,7 +30,9 @@ public interface PolicyCacheManager {
|
|||||||
|
|
||||||
void updateAllPolicies(List<Policy> policies);
|
void updateAllPolicies(List<Policy> policies);
|
||||||
|
|
||||||
List<Policy> getAllPolicies();
|
List<Policy> getAllPolicies() throws PolicyManagementException;
|
||||||
|
|
||||||
|
void rePopulateCache() throws PolicyManagementException;
|
||||||
|
|
||||||
void removeAllPolicies();
|
void removeAllPolicies();
|
||||||
|
|
||||||
@ -37,9 +40,11 @@ public interface PolicyCacheManager {
|
|||||||
|
|
||||||
void updatePolicy(Policy policy);
|
void updatePolicy(Policy policy);
|
||||||
|
|
||||||
|
void updatePolicy(int policyId) throws PolicyManagementException;
|
||||||
|
|
||||||
void removePolicy(int policyId);
|
void removePolicy(int policyId);
|
||||||
|
|
||||||
Policy getPolicy(int policyId);
|
Policy getPolicy(int policyId) throws PolicyManagementException;
|
||||||
|
|
||||||
void addPolicyToDevice(int deviceId, int policyId);
|
void addPolicyToDevice(int deviceId, int policyId);
|
||||||
|
|
||||||
|
|||||||
@ -19,51 +19,145 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.core.cache.impl;
|
package org.wso2.carbon.policy.mgt.core.cache.impl;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.policy.mgt.policy.Policy;
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager;
|
import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class PolicyCacheManagerImpl implements PolicyCacheManager {
|
public class PolicyCacheManagerImpl implements PolicyCacheManager {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(PolicyCacheManagerImpl.class);
|
||||||
|
|
||||||
|
private static HashMap<Integer, HashMap<Integer, Policy>> tenantedPolicyMap = new HashMap<>();
|
||||||
|
|
||||||
|
private static PolicyCacheManagerImpl policyCacheManager;
|
||||||
|
|
||||||
|
private PolicyCacheManagerImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PolicyCacheManager getInstance() {
|
||||||
|
if (policyCacheManager == null) {
|
||||||
|
synchronized (PolicyCacheManagerImpl.class) {
|
||||||
|
if (policyCacheManager == null) {
|
||||||
|
policyCacheManager = new PolicyCacheManagerImpl();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return policyCacheManager;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addAllPolicies(List<Policy> policies) {
|
public void addAllPolicies(List<Policy> policies) {
|
||||||
|
HashMap<Integer, Policy> map = this.getTenantRelatedMap();
|
||||||
|
if (map.isEmpty()) {
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
map.put(policy.getId(), policy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateAllPolicies(List<Policy> policies) {
|
public void updateAllPolicies(List<Policy> policies) {
|
||||||
|
HashMap<Integer, Policy> map = this.getTenantRelatedMap();
|
||||||
|
map.clear();
|
||||||
|
if (map.isEmpty()) {
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
map.put(policy.getId(), policy);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Policy> getAllPolicies() {
|
public List<Policy> getAllPolicies() throws PolicyManagementException {
|
||||||
return null;
|
HashMap<Integer, Policy> map = this.getTenantRelatedMap();
|
||||||
|
if (map.isEmpty()) {
|
||||||
|
PolicyManager policyManager = new PolicyManagerImpl();
|
||||||
|
this.addAllPolicies(policyManager.getPolicies());
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies stored in the cache .. : " + map.size());
|
||||||
|
|
||||||
|
Set<Integer> keySet = map.keySet();
|
||||||
|
for (Integer x : keySet) {
|
||||||
|
log.debug("Policy id in maps .. : " + map.get(x).getId() + " policy name : " + map.get(x).
|
||||||
|
getPolicyName() + " Activated : " + map.get(x).isActive());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ArrayList<>(map.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rePopulateCache() throws PolicyManagementException {
|
||||||
|
|
||||||
|
this.removeAllPolicies();
|
||||||
|
this.getAllPolicies();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllPolicies() {
|
public void removeAllPolicies() {
|
||||||
|
HashMap<Integer, Policy> map = this.getTenantRelatedMap();
|
||||||
|
map.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPolicy(Policy policy) {
|
public void addPolicy(Policy policy) {
|
||||||
|
HashMap<Integer, Policy> map = this.getTenantRelatedMap();
|
||||||
|
if (!map.containsKey(policy.getId())) {
|
||||||
|
map.put(policy.getId(), policy);
|
||||||
|
} else {
|
||||||
|
log.warn("Policy id (" + policy.getId() + ") already exist in the map. hence not attempted to store.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePolicy(Policy policy) {
|
public void updatePolicy(Policy policy) {
|
||||||
|
HashMap<Integer, Policy> map = this.getTenantRelatedMap();
|
||||||
|
if (map.containsKey(policy.getId())) {
|
||||||
|
map.remove(policy.getId());
|
||||||
|
map.put(policy.getId(), policy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePolicy(int policyId) throws PolicyManagementException {
|
||||||
|
HashMap<Integer, Policy> map = this.getTenantRelatedMap();
|
||||||
|
if (map.containsKey(policyId)) {
|
||||||
|
this.removePolicy(policyId);
|
||||||
|
}
|
||||||
|
PolicyManager policyManager = new PolicyManagerImpl();
|
||||||
|
Policy policy = policyManager.getPolicy(policyId);
|
||||||
|
map.put(policyId, policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removePolicy(int policyId) {
|
public void removePolicy(int policyId) {
|
||||||
|
HashMap<Integer, Policy> map = this.getTenantRelatedMap();
|
||||||
|
if (map.containsKey(policyId)) {
|
||||||
|
map.remove(policyId);
|
||||||
|
} else {
|
||||||
|
log.warn("Policy id (" + policyId + ") does not exist in the cache. Hence not removed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getPolicy(int policyId) {
|
public Policy getPolicy(int policyId) throws PolicyManagementException {
|
||||||
return null;
|
HashMap<Integer, Policy> map = this.getTenantRelatedMap();
|
||||||
|
if (!map.containsKey(policyId)) {
|
||||||
|
this.removeAllPolicies();
|
||||||
|
this.getAllPolicies();
|
||||||
|
}
|
||||||
|
return map.get(policyId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -80,4 +174,14 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager {
|
|||||||
public int getPolicyIdOfDevice(int deviceId) {
|
public int getPolicyIdOfDevice(int deviceId) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashMap<Integer, Policy> getTenantRelatedMap(){
|
||||||
|
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
if(!tenantedPolicyMap.containsKey(tenantId)){
|
||||||
|
HashMap<Integer, Policy> policyMap = new HashMap<>();
|
||||||
|
tenantedPolicyMap.put(tenantId, policyMap);
|
||||||
|
}
|
||||||
|
return tenantedPolicyMap.get(tenantId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,16 @@ public interface PolicyDAO {
|
|||||||
|
|
||||||
boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagerDAOException;
|
boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void activatePolicy(int policyId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void activatePolicies(List<Integer> policyIds) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void markPoliciesAsUpdated(List<Integer> policyIds) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void inactivatePolicy(int policyId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
HashMap<Integer, Integer> getUpdatedPolicyIdandDeviceTypeId() throws PolicyManagerDAOException;
|
||||||
|
|
||||||
Criterion addCriterion(Criterion criteria) throws PolicyManagerDAOException;
|
Criterion addCriterion(Criterion criteria) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
Criterion updateCriterion(Criterion criteria) throws PolicyManagerDAOException;
|
Criterion updateCriterion(Criterion criteria) throws PolicyManagerDAOException;
|
||||||
@ -64,6 +74,12 @@ public interface PolicyDAO {
|
|||||||
|
|
||||||
Policy updatePolicy(Policy policy) throws PolicyManagerDAOException;
|
Policy updatePolicy(Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void recordUpdatedPolicy(Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void recordUpdatedPolicies(List<Policy> policies) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void removeRecordsAboutUpdatedPolicies() throws PolicyManagerDAOException;
|
||||||
|
|
||||||
Policy getPolicy(int policyId) throws PolicyManagerDAOException;
|
Policy getPolicy(int policyId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
Policy getPolicyByProfileID(int profileId) throws PolicyManagerDAOException;
|
Policy getPolicyByProfileID(int profileId) throws PolicyManagerDAOException;
|
||||||
@ -90,21 +106,23 @@ public interface PolicyDAO {
|
|||||||
|
|
||||||
List<String> getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException;
|
List<String> getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
void addEffectivePolicyToDevice(int deviceId, Policy policy)
|
void addEffectivePolicyToDevice(int deviceId, int enrolmentId, Policy policy)
|
||||||
throws PolicyManagerDAOException;
|
throws PolicyManagerDAOException;
|
||||||
|
|
||||||
void setPolicyApplied(int deviceId) throws PolicyManagerDAOException;
|
void setPolicyApplied(int deviceId, int enrollmentId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
void updateEffectivePolicyToDevice(int deviceId, Policy policy)
|
void updateEffectivePolicyToDevice(int deviceId, int enrolmentId, Policy policy)
|
||||||
throws PolicyManagerDAOException;
|
throws PolicyManagerDAOException;
|
||||||
|
|
||||||
boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException;
|
boolean checkPolicyAvailable(int deviceId, int enrollmentId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
int getPolicyCount() throws PolicyManagerDAOException;
|
int getPolicyCount() throws PolicyManagerDAOException;
|
||||||
|
|
||||||
int getAppliedPolicyId(int deviceId) throws PolicyManagerDAOException;
|
int getAppliedPolicyId(int deviceId, int enrollmentId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
Policy getAppliedPolicy(int deviceId) throws PolicyManagerDAOException;
|
Policy getAppliedPolicy(int deviceId, int enrollmentId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
HashMap<Integer, Integer> getAppliedPolicyIds(List<Integer> deviceIds) throws PolicyManagerDAOException;
|
HashMap<Integer, Integer> getAppliedPolicyIds(List<Integer> deviceIds) throws PolicyManagerDAOException;
|
||||||
}
|
|
||||||
|
HashMap<Integer, Integer> getAppliedPolicyIdsDeviceIds() throws PolicyManagerDAOException;
|
||||||
|
}
|
||||||
|
|||||||
@ -119,17 +119,22 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "INSERT INTO DM_DEVICE_POLICY (DEVICE_ID, POLICY_ID) VALUES (?, ?)";
|
String query = "INSERT INTO DM_DEVICE_POLICY (DEVICE_ID, POLICY_ID, ENROLMENT_ID, DEVICE) VALUES (?, ?, " +
|
||||||
|
"?, ?)";
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
stmt.setInt(1, device.getId());
|
stmt.setInt(1, device.getId());
|
||||||
stmt.setInt(2, policy.getId());
|
stmt.setInt(2, policy.getId());
|
||||||
|
stmt.setInt(3, device.getEnrolmentInfo().getId());
|
||||||
|
stmt.setBytes(4, PolicyManagerUtil.getBytes(device));
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
}
|
}
|
||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PolicyManagerDAOException("Error occurred while adding the device ids with policy to " +
|
throw new PolicyManagerDAOException("Error occurred while adding the device ids with policy to " +
|
||||||
"database", e);
|
"database", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new PolicyManagerDAOException("Error occurred while getting the byte array from device.", e);
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
@ -144,13 +149,14 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "UPDATE DM_POLICY SET PRIORITY = ? WHERE ID = ? AND TENANT_ID = ?";
|
String query = "UPDATE DM_POLICY SET PRIORITY = ?, UPDATED = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
|
|
||||||
for (Policy policy : policies) {
|
for (Policy policy : policies) {
|
||||||
stmt.setInt(1, policy.getPriorityId());
|
stmt.setInt(1, policy.getPriorityId());
|
||||||
stmt.setInt(2, policy.getId());
|
stmt.setInt(2, 1);
|
||||||
stmt.setInt(3, tenantId);
|
stmt.setInt(3, policy.getId());
|
||||||
|
stmt.setInt(4, tenantId);
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
}
|
}
|
||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
@ -162,6 +168,137 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activatePolicy(int policyId) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "UPDATE DM_POLICY SET UPDATED = ?, ACTIVE = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, 1);
|
||||||
|
stmt.setInt(2, 1);
|
||||||
|
stmt.setInt(3, policyId);
|
||||||
|
stmt.setInt(4, tenantId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyManagerDAOException("Error occurred while updating policy id (" + policyId +
|
||||||
|
") in database", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activatePolicies(List<Integer> policyIds) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "UPDATE DM_POLICY SET UPDATED = ?, ACTIVE = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
for (int policyId : policyIds) {
|
||||||
|
stmt.setInt(1, 1);
|
||||||
|
stmt.setInt(2, 1);
|
||||||
|
stmt.setInt(3, policyId);
|
||||||
|
stmt.setInt(4, tenantId);
|
||||||
|
stmt.addBatch();
|
||||||
|
}
|
||||||
|
stmt.executeBatch();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyManagerDAOException("Error occurred while updating all the updated in database", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markPoliciesAsUpdated(List<Integer> policyIds) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "UPDATE DM_POLICY SET UPDATED = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
for (int policyId : policyIds) {
|
||||||
|
stmt.setInt(1, 0);
|
||||||
|
stmt.setInt(2, policyId);
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.addBatch();
|
||||||
|
}
|
||||||
|
stmt.executeBatch();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyManagerDAOException("Error occurred while updating all the updated in database", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void inactivatePolicy(int policyId) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "UPDATE DM_POLICY SET ACTIVE = ?, UPDATED = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, 0);
|
||||||
|
stmt.setInt(2, 1);
|
||||||
|
stmt.setInt(3, policyId);
|
||||||
|
stmt.setInt(4, tenantId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyManagerDAOException("Error occurred while updating policy id (" + policyId +
|
||||||
|
") in database", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<Integer, Integer> getUpdatedPolicyIdandDeviceTypeId() throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
HashMap<Integer, Integer> map = new HashMap<>();
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "SELECT * FROM DM_POLICY_CHANGE_MGT WHERE TENANT_ID = ?";
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
map.put(resultSet.getInt("POLICY_ID"), resultSet.getInt("DEVICE_TYPE_ID"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyManagerDAOException("Error occurred while reading the changed policies form database.", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Criterion addCriterion(Criterion criteria) throws PolicyManagerDAOException {
|
public Criterion addCriterion(Criterion criteria) throws PolicyManagerDAOException {
|
||||||
@ -477,15 +614,16 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "UPDATE DM_POLICY SET NAME= ?, PROFILE_ID = ?, PRIORITY = ?, COMPLIANCE = ?" +
|
String query = "UPDATE DM_POLICY SET NAME = ?, PROFILE_ID = ?, PRIORITY = ?, COMPLIANCE = ?," +
|
||||||
" WHERE ID = ? AND TENANT_ID = ?";
|
" UPDATED = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setString(1, policy.getPolicyName());
|
stmt.setString(1, policy.getPolicyName());
|
||||||
stmt.setInt(2, policy.getProfile().getProfileId());
|
stmt.setInt(2, policy.getProfile().getProfileId());
|
||||||
stmt.setInt(3, policy.getPriorityId());
|
stmt.setInt(3, policy.getPriorityId());
|
||||||
stmt.setString(4, policy.getCompliance());
|
stmt.setString(4, policy.getCompliance());
|
||||||
stmt.setInt(5, policy.getId());
|
stmt.setInt(5, 1);
|
||||||
stmt.setInt(6, tenantId);
|
stmt.setInt(6, policy.getId());
|
||||||
|
stmt.setInt(7, tenantId);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -497,6 +635,77 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void recordUpdatedPolicy(Policy policy) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "INSERT INTO DM_POLICY_CHANGE_MGT (POLICY_ID, DEVICE_TYPE_ID, TENANT_ID) VALUES (?, ?, ?)";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, policy.getId());
|
||||||
|
stmt.setInt(2, policy.getProfile().getDeviceType().getId());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyManagerDAOException("Error occurred while updating the policy changes in the database for" +
|
||||||
|
" " +
|
||||||
|
"policy name (" + policy.getPolicyName() + ")", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void recordUpdatedPolicies(List<Policy> policies) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "INSERT INTO DM_POLICY_CHANGE_MGT (POLICY_ID, DEVICE_TYPE_ID, TENANT_ID) VALUES (?, ?, ?)";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
stmt.setInt(1, policy.getId());
|
||||||
|
stmt.setInt(2, policy.getProfile().getDeviceType().getId());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.addBatch();
|
||||||
|
}
|
||||||
|
stmt.executeBatch();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyManagerDAOException("Error occurred while updating the policy changes in the database.", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeRecordsAboutUpdatedPolicies() throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "DELETE FROM DM_POLICY_CHANGE_MGT WHERE TENANT_ID = ? ";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyManagerDAOException("Error occurred while deleting the policy changes in the database for" +
|
||||||
|
" " +
|
||||||
|
"tenant id (" + tenantId + ")", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getPolicy(int policyId) throws PolicyManagerDAOException {
|
public Policy getPolicy(int policyId) throws PolicyManagerDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
@ -585,6 +794,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
policy.setPriorityId(resultSet.getInt("PRIORITY"));
|
policy.setPriorityId(resultSet.getInt("PRIORITY"));
|
||||||
policy.setCompliance(resultSet.getString("COMPLIANCE"));
|
policy.setCompliance(resultSet.getString("COMPLIANCE"));
|
||||||
policy.setOwnershipType(resultSet.getString("OWNERSHIP_TYPE"));
|
policy.setOwnershipType(resultSet.getString("OWNERSHIP_TYPE"));
|
||||||
|
policy.setUpdated(PolicyManagerUtil.convertIntToBoolean(resultSet.getInt("UPDATED")));
|
||||||
|
policy.setActive(PolicyManagerUtil.convertIntToBoolean(resultSet.getInt("ACTIVE")));
|
||||||
policies.add(policy);
|
policies.add(policy);
|
||||||
}
|
}
|
||||||
return policies;
|
return policies;
|
||||||
@ -675,7 +886,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addEffectivePolicyToDevice(int deviceId, Policy policy) throws PolicyManagerDAOException {
|
public void addEffectivePolicyToDevice(int deviceId, int enrolmentId, Policy policy) throws
|
||||||
|
PolicyManagerDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||||
@ -683,7 +895,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "INSERT INTO DM_DEVICE_POLICY_APPLIED (DEVICE_ID, POLICY_ID, POLICY_CONTENT, " +
|
String query = "INSERT INTO DM_DEVICE_POLICY_APPLIED (DEVICE_ID, POLICY_ID, POLICY_CONTENT, " +
|
||||||
"CREATED_TIME, UPDATED_TIME, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?)";
|
"CREATED_TIME, UPDATED_TIME, TENANT_ID, ENROLMENT_ID) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setInt(1, deviceId);
|
stmt.setInt(1, deviceId);
|
||||||
stmt.setInt(2, policy.getId());
|
stmt.setInt(2, policy.getId());
|
||||||
@ -691,6 +903,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
stmt.setTimestamp(4, currentTimestamp);
|
stmt.setTimestamp(4, currentTimestamp);
|
||||||
stmt.setTimestamp(5, currentTimestamp);
|
stmt.setTimestamp(5, currentTimestamp);
|
||||||
stmt.setInt(6, tenantId);
|
stmt.setInt(6, tenantId);
|
||||||
|
stmt.setInt(7, enrolmentId);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
} catch (SQLException | IOException e) {
|
} catch (SQLException | IOException e) {
|
||||||
throw new PolicyManagerDAOException("Error occurred while adding the evaluated feature list to device", e);
|
throw new PolicyManagerDAOException("Error occurred while adding the evaluated feature list to device", e);
|
||||||
@ -701,7 +914,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPolicyApplied(int deviceId) throws PolicyManagerDAOException {
|
public void setPolicyApplied(int deviceId, int enrollmentId) throws PolicyManagerDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||||
@ -709,12 +922,13 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET APPLIED_TIME = ?, APPLIED = ? WHERE DEVICE_ID = ? AND" +
|
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET APPLIED_TIME = ?, APPLIED = ? WHERE DEVICE_ID = ? AND" +
|
||||||
" TENANT_ID = ?";
|
" TENANT_ID = ? AND ENROLMENT_ID = ?";
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setTimestamp(1, currentTimestamp);
|
stmt.setTimestamp(1, currentTimestamp);
|
||||||
stmt.setBoolean(2, true);
|
stmt.setBoolean(2, true);
|
||||||
stmt.setInt(3, deviceId);
|
stmt.setInt(3, deviceId);
|
||||||
stmt.setInt(4, tenantId);
|
stmt.setInt(4, tenantId);
|
||||||
|
stmt.setInt(5, enrollmentId);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PolicyManagerDAOException("Error occurred while updating applied policy to device (" +
|
throw new PolicyManagerDAOException("Error occurred while updating applied policy to device (" +
|
||||||
@ -726,7 +940,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEffectivePolicyToDevice(int deviceId, Policy policy) throws PolicyManagerDAOException {
|
public void updateEffectivePolicyToDevice(int deviceId, int enrolmentId, Policy policy) throws
|
||||||
|
PolicyManagerDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||||
@ -734,7 +949,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ?, UPDATED_TIME = ?, " +
|
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ?, UPDATED_TIME = ?, " +
|
||||||
"APPLIED = ? WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
"APPLIED = ? WHERE DEVICE_ID = ? AND TENANT_ID = ? AND ENROLMENT_ID = ?";
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setInt(1, policy.getId());
|
stmt.setInt(1, policy.getId());
|
||||||
stmt.setBytes(2, PolicyManagerUtil.getBytes(policy));
|
stmt.setBytes(2, PolicyManagerUtil.getBytes(policy));
|
||||||
@ -742,6 +957,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
stmt.setBoolean(4, false);
|
stmt.setBoolean(4, false);
|
||||||
stmt.setInt(5, deviceId);
|
stmt.setInt(5, deviceId);
|
||||||
stmt.setInt(6, tenantId);
|
stmt.setInt(6, tenantId);
|
||||||
|
stmt.setInt(7, enrolmentId);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|
||||||
} catch (SQLException | IOException e) {
|
} catch (SQLException | IOException e) {
|
||||||
@ -753,7 +969,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException {
|
public boolean checkPolicyAvailable(int deviceId, int enrollmentId) throws PolicyManagerDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
@ -761,10 +977,12 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ? AND " +
|
||||||
|
"ENROLMENT_ID = ?";
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setInt(1, deviceId);
|
stmt.setInt(1, deviceId);
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.setInt(3, enrollmentId);
|
||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
exist = resultSet.next();
|
exist = resultSet.next();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -884,12 +1102,16 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setInt(1, policyId);
|
stmt.setInt(1, policyId);
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
stmt.executeUpdate();
|
int deleted = stmt.executeUpdate();
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Policy (" + policyId + ") delete from database.");
|
log.debug("Policy (" + policyId + ") delete from database.");
|
||||||
}
|
}
|
||||||
return true;
|
if (deleted > 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PolicyManagerDAOException("Unable to delete the policy (" + policyId + ") from database", e);
|
throw new PolicyManagerDAOException("Unable to delete the policy (" + policyId + ") from database", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -948,8 +1170,9 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE)" +
|
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE," +
|
||||||
" VALUES (?, ?, ?, ?, ?, ?)";
|
" " +
|
||||||
|
"UPDATED, ACTIVE) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||||
|
|
||||||
stmt.setString(1, policy.getPolicyName());
|
stmt.setString(1, policy.getPolicyName());
|
||||||
@ -958,6 +1181,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
stmt.setInt(4, readHighestPriorityOfPolicies());
|
stmt.setInt(4, readHighestPriorityOfPolicies());
|
||||||
stmt.setString(5, policy.getCompliance());
|
stmt.setString(5, policy.getCompliance());
|
||||||
stmt.setString(6, policy.getOwnershipType());
|
stmt.setString(6, policy.getOwnershipType());
|
||||||
|
stmt.setInt(7, 0);
|
||||||
|
stmt.setInt(8, 0);
|
||||||
|
|
||||||
int affectedRows = stmt.executeUpdate();
|
int affectedRows = stmt.executeUpdate();
|
||||||
|
|
||||||
@ -1069,17 +1294,18 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAppliedPolicyId(int deviceId) throws PolicyManagerDAOException {
|
public int getAppliedPolicyId(int deviceId, int enrollmentId) throws PolicyManagerDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ? AND ENROLMENT_ID = ?";
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setInt(1, deviceId);
|
stmt.setInt(1, deviceId);
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.setInt(3, enrollmentId);
|
||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
@ -1094,7 +1320,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getAppliedPolicy(int deviceId) throws PolicyManagerDAOException {
|
public Policy getAppliedPolicy(int deviceId, int enrollmentId) throws PolicyManagerDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
@ -1102,10 +1328,12 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
Policy policy = null;
|
Policy policy = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ?";
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ? AND TENANT_ID = ? AND " +
|
||||||
|
"ENROLMENT_ID = ?";
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setInt(1, deviceId);
|
stmt.setInt(1, deviceId);
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.setInt(3, enrollmentId);
|
||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
@ -1183,4 +1411,31 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
return devicePolicyIds;
|
return devicePolicyIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<Integer, Integer> getAppliedPolicyIdsDeviceIds() throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
HashMap<Integer, Integer> devicePolicyIds = new HashMap<>();
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE TENANT_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
devicePolicyIds.put(resultSet.getInt("DEVICE_ID"), resultSet.getInt("POLICY_ID"));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyManagerDAOException("Error occurred while getting the applied policy", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||||
|
}
|
||||||
|
return devicePolicyIds;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,19 +91,19 @@ public class ProfileDAOImpl implements ProfileDAO {
|
|||||||
|
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet generatedKeys = null;
|
// ResultSet generatedKeys = null;
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "UPDATE DM_PROFILE SET PROFILE_NAME = ? ,TENANT_ID = ?, DEVICE_TYPE_ID = ? , UPDATED_TIME = ? " +
|
String query = "UPDATE DM_PROFILE SET PROFILE_NAME = ? , DEVICE_TYPE_ID = ? , UPDATED_TIME = ? " +
|
||||||
"WHERE ID = ?";
|
"WHERE ID = ? AND TENANT_ID = ?";
|
||||||
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
stmt = conn.prepareStatement(query);
|
||||||
stmt.setString(1, profile.getProfileName());
|
stmt.setString(1, profile.getProfileName());
|
||||||
stmt.setInt(2, tenantId);
|
stmt.setLong(2, profile.getDeviceType().getId());
|
||||||
stmt.setLong(3, profile.getDeviceType().getId());
|
stmt.setTimestamp(3, profile.getUpdatedDate());
|
||||||
stmt.setTimestamp(4, profile.getUpdatedDate());
|
stmt.setInt(4, profile.getProfileId());
|
||||||
stmt.setInt(5, profile.getProfileId());
|
stmt.setInt(5, tenantId);
|
||||||
|
|
||||||
int affectedRows = stmt.executeUpdate();
|
int affectedRows = stmt.executeUpdate();
|
||||||
|
|
||||||
@ -111,22 +111,22 @@ public class ProfileDAOImpl implements ProfileDAO {
|
|||||||
String msg = "No rows are updated on the profile table.";
|
String msg = "No rows are updated on the profile table.";
|
||||||
log.debug(msg);
|
log.debug(msg);
|
||||||
}
|
}
|
||||||
generatedKeys = stmt.getGeneratedKeys();
|
// generatedKeys = stmt.getGeneratedKeys();
|
||||||
|
//
|
||||||
if (generatedKeys.next()) {
|
// if (generatedKeys.next()) {
|
||||||
profile.setProfileId(generatedKeys.getInt(1));
|
// profile.setProfileId(generatedKeys.getInt(1));
|
||||||
}
|
// }
|
||||||
// Checking the profile id here, because profile id could have been passed from the calling method.
|
// // Checking the profile id here, because profile id could have been passed from the calling method.
|
||||||
if (profile.getProfileId() == 0) {
|
// if (profile.getProfileId() == 0) {
|
||||||
throw new RuntimeException("Profile id is 0, this could be an issue.");
|
// throw new RuntimeException("Profile id is 0, this could be an issue.");
|
||||||
}
|
// }
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while updating the profile (" + profile.getProfileName() + ") in database.";
|
String msg = "Error occurred while updating the profile (" + profile.getProfileName() + ") in database.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new ProfileManagerDAOException(msg, e);
|
throw new ProfileManagerDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.policy.mgt.core.enforcement;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.ntask.core.Task;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.cache.impl.PolicyCacheManagerImpl;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class DelegationTask implements Task {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DelegationTask.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProperties(Map<String, String> map) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
PolicyManager policyManager = new PolicyManagerImpl();
|
||||||
|
List<DeviceType> deviceTypes = policyManager.applyChangesMadeToPolicies();
|
||||||
|
|
||||||
|
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Number of device types which policies are changed .......... : " + deviceTypes.size());
|
||||||
|
}
|
||||||
|
if (!deviceTypes.isEmpty()) {
|
||||||
|
DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance()
|
||||||
|
.getDeviceManagementService();
|
||||||
|
List<Device> devices = new ArrayList<>();
|
||||||
|
for (DeviceType deviceType : deviceTypes) {
|
||||||
|
try {
|
||||||
|
devices.addAll(service.getAllDevices(deviceType.getName()));
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
throw new PolicyManagementException("Error occurred while taking the devices", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
|
||||||
|
List<Device> toBeNotified = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Device device : devices) {
|
||||||
|
if (deviceIdPolicy.containsKey(device.getId())) {
|
||||||
|
toBeNotified.add(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!toBeNotified.isEmpty()) {
|
||||||
|
PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified);
|
||||||
|
enforcementDelegator.delegate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
log.error("Error occurred while getting the policies applied to devices.", e);
|
||||||
|
} catch (PolicyDelegationException e) {
|
||||||
|
log.error("Error occurred while running the delegation task.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.policy.mgt.core.enforcement;
|
package org.wso2.carbon.policy.mgt.core.enforcement;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
|
|
||||||
@ -26,6 +25,10 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface PolicyEnforcementDelegator {
|
public interface PolicyEnforcementDelegator {
|
||||||
|
|
||||||
void delegate(Policy policy, List<Device> devices) throws PolicyDelegationException;
|
void delegate() throws PolicyDelegationException;
|
||||||
|
|
||||||
|
Policy getEffectivePolicy(DeviceIdentifier identifier) throws PolicyDelegationException;
|
||||||
|
|
||||||
|
void addPolicyOperation(List<DeviceIdentifier> deviceIdentifiers, Policy policy) throws PolicyDelegationException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,33 +18,93 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.policy.mgt.core.enforcement;
|
package org.wso2.carbon.policy.mgt.core.enforcement;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegator {
|
public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegator{
|
||||||
|
|
||||||
private OperationManager operationManager = new OperationManagerImpl();
|
private static final Log log = LogFactory.getLog(PolicyEnforcementDelegatorImpl.class);
|
||||||
|
|
||||||
|
private List<Device> devices;
|
||||||
|
|
||||||
|
public PolicyEnforcementDelegatorImpl(List<Device> devices) {
|
||||||
|
|
||||||
|
log.info("Policy re-enforcing stared due to change of the policies.");
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
for (Device device : devices) {
|
||||||
|
log.debug("Policy re-enforcing for device :" + device.getDeviceIdentifier() + " - Type : "
|
||||||
|
+ device.getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.devices = devices;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delegate(Policy policy, List<Device> devices) throws PolicyDelegationException {
|
public void delegate() throws PolicyDelegationException {
|
||||||
try {
|
|
||||||
List<DeviceIdentifier> deviceIds = new ArrayList<>();
|
for (Device device : devices) {
|
||||||
for (Device device : devices) {
|
DeviceIdentifier identifier = new DeviceIdentifier();
|
||||||
deviceIds.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
identifier.setId(device.getDeviceIdentifier());
|
||||||
|
identifier.setType(device.getType());
|
||||||
|
|
||||||
|
Policy policy = this.getEffectivePolicy(identifier);
|
||||||
|
|
||||||
|
if (policy != null) {
|
||||||
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||||
|
deviceIdentifiers.add(identifier);
|
||||||
|
this.addPolicyOperation(deviceIdentifiers, policy);
|
||||||
}
|
}
|
||||||
operationManager.addOperation(PolicyManagerUtil.transformPolicy(policy), deviceIds);
|
|
||||||
} catch (OperationManagementException e) {
|
|
||||||
throw new PolicyDelegationException("Error occurred while delegating policy information to " +
|
|
||||||
"the respective enforcement points", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Policy getEffectivePolicy(DeviceIdentifier identifier) throws PolicyDelegationException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
PolicyManagerService policyManagerService = new PolicyManagerServiceImpl();
|
||||||
|
return policyManagerService.getPEP().getEffectivePolicy(identifier);
|
||||||
|
//return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().getEffectivePolicy(identifier);
|
||||||
|
} catch (PolicyEvaluationException e) {
|
||||||
|
String msg = "Error occurred while retrieving the effective policy for devices.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyDelegationException(msg, e);
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String msg = "Error occurred while retrieving the effective policy for devices.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyDelegationException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addPolicyOperation(List<DeviceIdentifier> deviceIdentifiers, Policy policy) throws
|
||||||
|
PolicyDelegationException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
OperationManager operationManager = new OperationManagerImpl();
|
||||||
|
operationManager.addOperation(PolicyManagerUtil.transformPolicy(policy), deviceIdentifiers);
|
||||||
|
} catch (OperationManagementException e) {
|
||||||
|
String msg = "Error occurred while adding the operation to device.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyDelegationException(msg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -166,10 +166,8 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (OperationManagementException e) {
|
} catch (OperationManagementException e) {
|
||||||
String msg = "Error occurred while re-enforcing the policy to device " + deviceIdentifier.getId() + " - " +
|
throw new PolicyComplianceException("Error occurred while re-enforcing the policy to device " + deviceIdentifier.getId() + " - " +
|
||||||
deviceIdentifier.getType();
|
deviceIdentifier.getType(), e);
|
||||||
log.error(msg, e);
|
|
||||||
throw new PolicyComplianceException(msg, e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,24 +20,27 @@ package org.wso2.carbon.policy.mgt.core.impl;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
import org.wso2.carbon.ntask.common.TaskException;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.ntask.core.TaskInfo;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
import org.wso2.carbon.ntask.core.TaskManager;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
|
import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.enforcement.PolicyDelegationException;
|
import org.wso2.carbon.policy.mgt.core.cache.impl.PolicyCacheManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.enforcement.PolicyEnforcementDelegator;
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
import org.wso2.carbon.policy.mgt.core.enforcement.PolicyEnforcementDelegatorImpl;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.FeatureManagerImpl;
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.FeatureManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.ProfileManagerImpl;
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.ProfileManagerImpl;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
||||||
|
|
||||||
@ -46,13 +49,15 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
private PolicyManager policyManager;
|
private PolicyManager policyManager;
|
||||||
private ProfileManager profileManager;
|
private ProfileManager profileManager;
|
||||||
private FeatureManager featureManager;
|
private FeatureManager featureManager;
|
||||||
private PolicyEnforcementDelegator delegator;
|
private PolicyCacheManager cacheManager;
|
||||||
|
// private PolicyEnforcementDelegator delegator;
|
||||||
|
|
||||||
public PolicyAdministratorPointImpl() {
|
public PolicyAdministratorPointImpl() {
|
||||||
this.policyManager = new PolicyManagerImpl();
|
this.policyManager = new PolicyManagerImpl();
|
||||||
this.profileManager = new ProfileManagerImpl();
|
this.profileManager = new ProfileManagerImpl();
|
||||||
this.featureManager = new FeatureManagerImpl();
|
this.featureManager = new FeatureManagerImpl();
|
||||||
this.delegator = new PolicyEnforcementDelegatorImpl();
|
this.cacheManager = PolicyCacheManagerImpl.getInstance();
|
||||||
|
// this.delegator = new PolicyEnforcementDelegatorImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -63,6 +68,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
// } catch (PolicyDelegationException e) {
|
// } catch (PolicyDelegationException e) {
|
||||||
// throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
|
// throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
|
||||||
// }
|
// }
|
||||||
|
PolicyCacheManagerImpl.getInstance().addPolicy(resultantPolicy);
|
||||||
return resultantPolicy;
|
return resultantPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,42 +80,148 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
// } catch (PolicyDelegationException e) {
|
// } catch (PolicyDelegationException e) {
|
||||||
// throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
|
// throw new PolicyManagementException("Error occurred while delegating policy operation to the devices", e);
|
||||||
// }
|
// }
|
||||||
|
PolicyCacheManagerImpl.getInstance().updatePolicy(resultantPolicy);
|
||||||
return resultantPolicy;
|
return resultantPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
|
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
|
||||||
return policyManager.updatePolicyPriorities(policies);
|
boolean bool = policyManager.updatePolicyPriorities(policies);
|
||||||
|
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
||||||
|
return bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activatePolicy(int policyId) throws PolicyManagementException {
|
||||||
|
policyManager.activatePolicy(policyId);
|
||||||
|
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void inactivatePolicy(int policyId) throws PolicyManagementException {
|
||||||
|
policyManager.inactivatePolicy(policyId);
|
||||||
|
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
public boolean deletePolicy(Policy policy) throws PolicyManagementException {
|
||||||
return policyManager.deletePolicy(policy);
|
boolean bool = policyManager.deletePolicy(policy);
|
||||||
|
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
||||||
|
return bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deletePolicy(int policyId) throws PolicyManagementException {
|
public boolean deletePolicy(int policyId) throws PolicyManagementException {
|
||||||
return policyManager.deletePolicy(policyId);
|
boolean bool =policyManager.deletePolicy(policyId);
|
||||||
|
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
||||||
|
return bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws PolicyManagementException {
|
public void publishChanges() throws PolicyManagementException {
|
||||||
return policyManager.addPolicyToDevice(deviceIdentifierList, policy);
|
|
||||||
|
try {
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
||||||
|
taskService.registerTaskType(PolicyManagementConstants.DELEGATION_TASK_TYPE);
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Policy delegations task is started for the tenant id " + tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.DELEGATION_TASK_TYPE);
|
||||||
|
|
||||||
|
TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo();
|
||||||
|
|
||||||
|
triggerInfo.setIntervalMillis(0);
|
||||||
|
triggerInfo.setRepeatCount(1);
|
||||||
|
|
||||||
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
properties.put(PolicyManagementConstants.TENANT_ID, String.valueOf(tenantId));
|
||||||
|
|
||||||
|
String taskName = PolicyManagementConstants.DELEGATION_TASK_NAME + "_" + String.valueOf(tenantId);
|
||||||
|
|
||||||
|
if (!taskManager.isTaskScheduled(taskName)) {
|
||||||
|
|
||||||
|
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.DELEGATION_TASK_CLAZZ,
|
||||||
|
properties, triggerInfo);
|
||||||
|
|
||||||
|
taskManager.registerTask(taskInfo);
|
||||||
|
taskManager.rescheduleTask(taskInfo.getName());
|
||||||
|
} else {
|
||||||
|
throw new PolicyManagementException("There is a task already running for policy changes. Please try " +
|
||||||
|
"to apply " +
|
||||||
|
"changes after few minutes.");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (TaskException e) {
|
||||||
|
String msg = "Error occurred while creating the policy delegation task for tenant " +
|
||||||
|
PrivilegedCarbonContext.
|
||||||
|
getThreadLocalCarbonContext().getTenantId();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagementException(msg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// List<DeviceType> deviceTypes = policyManager.applyChangesMadeToPolicies();
|
||||||
|
//
|
||||||
|
// if(log.isDebugEnabled()) {
|
||||||
|
// log.debug("Number of device types which policies are changed .......... : " + deviceTypes.size() );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!deviceTypes.isEmpty()) {
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// DeviceManagementProviderService service = PolicyManagementDataHolder.getInstance()
|
||||||
|
// .getDeviceManagementService();
|
||||||
|
// List<Device> devices = new ArrayList<>();
|
||||||
|
// for (DeviceType deviceType : deviceTypes) {
|
||||||
|
// try {
|
||||||
|
// devices.addAll(service.getAllDevices(deviceType.getName()));
|
||||||
|
// } catch (DeviceManagementException e) {
|
||||||
|
// throw new PolicyManagementException("Error occurred while taking the devices", e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// HashMap<Integer, Integer> deviceIdPolicy = policyManager.getAppliedPolicyIdsDeviceIds();
|
||||||
|
// List<Device> toBeNotified = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// for (Device device : devices) {
|
||||||
|
// if (deviceIdPolicy.containsKey(device.getId())) {
|
||||||
|
// toBeNotified.add(device);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (!toBeNotified.isEmpty()) {
|
||||||
|
//
|
||||||
|
// // ExecutorService executorService = getExecutor();
|
||||||
|
// // PolicyEnforcementDelegator enforcementDelegator = new PolicyEnforcementDelegatorImpl(toBeNotified);
|
||||||
|
//// Thread thread = new Thread(new PolicyEnforcementDelegatorImpl(toBeNotified));
|
||||||
|
//// thread.start();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws
|
||||||
|
PolicyManagementException {
|
||||||
|
policy = policyManager.addPolicyToDevice(deviceIdentifierList, policy);
|
||||||
|
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
||||||
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagementException {
|
public Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagementException {
|
||||||
return policyManager.addPolicyToRole(roleNames, policy);
|
policy = policyManager.addPolicyToRole(roleNames, policy);
|
||||||
|
PolicyCacheManagerImpl.getInstance().rePopulateCache();
|
||||||
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Policy> getPolicies() throws PolicyManagementException {
|
public List<Policy> getPolicies() throws PolicyManagementException {
|
||||||
return policyManager.getPolicies();
|
return PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getPolicy(int policyId) throws PolicyManagementException {
|
public Policy getPolicy(int policyId) throws PolicyManagementException {
|
||||||
return policyManager.getPolicy(policyId);
|
return PolicyCacheManagerImpl.getInstance().getPolicy(policyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -185,7 +297,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
try {
|
try {
|
||||||
return profileManager.getProfile(profileId);
|
return profileManager.getProfile(profileId);
|
||||||
} catch (ProfileManagementException e) {
|
} catch (ProfileManagementException e) {
|
||||||
String msg = "Error occurred while retriving profile";
|
String msg = "Error occurred while retrieving profile";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new PolicyManagementException(msg, e);
|
throw new PolicyManagementException(msg, e);
|
||||||
}
|
}
|
||||||
@ -220,7 +332,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPolicyCount() throws PolicyManagementException {
|
public int getPolicyCount() throws PolicyManagementException {
|
||||||
return policyManager.getPolicyCount();
|
return PolicyCacheManagerImpl.getInstance().getAllPolicies().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,14 +32,56 @@ public class PolicyFilterImpl implements PolicyFilter {
|
|||||||
|
|
||||||
private static final Log log = LogFactory.getLog(PolicyFilterImpl.class);
|
private static final Log log = LogFactory.getLog(PolicyFilterImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Policy> filterActivePolicies(List<Policy> policies) {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies went in to filterActivePolicies : " + policies.size());
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
log.debug("Names of policy went in to filterActivePolicies : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Policy> temp = new ArrayList<Policy>();
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
if (policy.isActive()) {
|
||||||
|
temp.add(policy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies returned from filterActivePolicies :" + policies.size());
|
||||||
|
for (Policy policy : temp) {
|
||||||
|
log.debug("Names of policy filtered in filterActivePolicies : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Policy> filterRolesBasedPolicies(String roles[], List<Policy> policies) {
|
public List<Policy> filterRolesBasedPolicies(String roles[], List<Policy> policies) {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies went in to filterRolesBasedPolicies : " + policies.size());
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
log.debug("Names of policy went in to filterRolesBasedPolicies : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
log.debug("Roles passed to match.");
|
||||||
|
for(String role : roles){
|
||||||
|
log.debug("Role name passed : " + role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<Policy> temp = new ArrayList<Policy>();
|
List<Policy> temp = new ArrayList<Policy>();
|
||||||
for (Policy policy : policies) {
|
for (Policy policy : policies) {
|
||||||
|
|
||||||
List<String> tempRoles = policy.getRoles();
|
List<String> tempRoles = policy.getRoles();
|
||||||
if (tempRoles.isEmpty()) {
|
if (tempRoles.isEmpty()) {
|
||||||
|
|
||||||
|
if(log.isDebugEnabled()) {
|
||||||
|
log.debug("Roles list is empty.");
|
||||||
|
}
|
||||||
temp.add(policy);
|
temp.add(policy);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -57,12 +99,28 @@ public class PolicyFilterImpl implements PolicyFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies returned from filterRolesBasedPolicies : " + policies.size());
|
||||||
|
for (Policy policy : temp) {
|
||||||
|
log.debug("Names of policy filtered in filterRolesBasedPolicies : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Policy> filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies) {
|
public List<Policy> filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies) {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies went in to filterOwnershipTypeBasedPolicies : " + policies.size());
|
||||||
|
log.debug("Ownership type : " + ownershipType);
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
log.debug("Names of policy went in to filterOwnershipTypeBasedPolicies : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<Policy> temp = new ArrayList<Policy>();
|
List<Policy> temp = new ArrayList<Policy>();
|
||||||
for (Policy policy : policies) {
|
for (Policy policy : policies) {
|
||||||
if (ownershipType.equalsIgnoreCase(policy.getOwnershipType()) ||
|
if (ownershipType.equalsIgnoreCase(policy.getOwnershipType()) ||
|
||||||
@ -70,22 +128,56 @@ public class PolicyFilterImpl implements PolicyFilter {
|
|||||||
temp.add(policy);
|
temp.add(policy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (log.isDebugEnabled()) {
|
||||||
public List<Policy> filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies) {
|
log.debug("No of policies returned from filterOwnershipTypeBasedPolicies : " + policies.size());
|
||||||
List<Policy> temp = new ArrayList<Policy>();
|
for (Policy policy : temp) {
|
||||||
for (Policy policy : policies) {
|
log.debug("Names of policy filtered in filterOwnershipTypeBasedPolicies : " + policy.getPolicyName());
|
||||||
if (deviceType.equalsIgnoreCase(policy.getProfile().getDeviceType().getName())) {
|
|
||||||
temp.add(policy);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Policy> filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies) {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies went in to filterDeviceTypeBasedPolicies : " + policies.size());
|
||||||
|
log.debug("Device type : " + deviceType);
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
log.debug("Names of policy went in to filterDeviceTypeBasedPolicies : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
List<Policy> temp = new ArrayList<Policy>();
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
if (deviceType.equalsIgnoreCase(policy.getProfile().getDeviceType().getName())) {
|
||||||
|
temp.add(policy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies returned from filterDeviceTypeBasedPolicies : " + policies.size());
|
||||||
|
for (Policy policy : temp) {
|
||||||
|
log.debug("Names of policy filtered in filterDeviceTypeBasedPolicies : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Policy> filterUserBasedPolicies(String username, List<Policy> policies) {
|
public List<Policy> filterUserBasedPolicies(String username, List<Policy> policies) {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies went in to filterUserBasedPolicies : " + policies.size());
|
||||||
|
log.debug("User name : " + username);
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
log.debug("Names of policy went in to filterUserBasedPolicies : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<Policy> temp = new ArrayList<Policy>();
|
List<Policy> temp = new ArrayList<Policy>();
|
||||||
|
|
||||||
for (Policy policy : policies) {
|
for (Policy policy : policies) {
|
||||||
@ -106,6 +198,14 @@ public class PolicyFilterImpl implements PolicyFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies returned from filterUserBasedPolicies : " + policies.size());
|
||||||
|
for (Policy policy : temp) {
|
||||||
|
log.debug("Names of policy filtered in filterUserBasedPolicies : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,13 +27,16 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
import org.wso2.carbon.policy.mgt.common.*;
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.FeatureManagerImpl;
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.FeatureManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
||||||
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -58,26 +61,36 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
|
|||||||
@Override
|
@Override
|
||||||
public PIPDevice getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
public PIPDevice getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||||
PIPDevice pipDevice = new PIPDevice();
|
PIPDevice pipDevice = new PIPDevice();
|
||||||
org.wso2.carbon.device.mgt.common.Device device;
|
Device device;
|
||||||
|
|
||||||
DeviceType deviceType = new DeviceType();
|
DeviceType deviceType = new DeviceType();
|
||||||
deviceType.setName(deviceIdentifier.getType());
|
deviceType.setName(deviceIdentifier.getType());
|
||||||
deviceManagementService = getDeviceManagementService();
|
DeviceManagementProviderService deviceManagementService = new DeviceManagementProviderServiceImpl();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
device = deviceManagementService.getDevice(deviceIdentifier);
|
device = deviceManagementService.getDevice(deviceIdentifier);
|
||||||
/*deviceManagementService.getDeviceType(deviceIdentifier.getType());*/
|
Thread.currentThread();
|
||||||
pipDevice.setDevice(device);
|
|
||||||
pipDevice.setRoles(getRoleOfDevice(device));
|
|
||||||
pipDevice.setDeviceType(deviceType);
|
|
||||||
pipDevice.setDeviceIdentifier(deviceIdentifier);
|
|
||||||
pipDevice.setUserId(device.getEnrolmentInfo().getOwner());
|
|
||||||
pipDevice.setOwnershipType(device.getEnrolmentInfo().getOwnership().toString());
|
|
||||||
|
|
||||||
// TODO : Find a way to retrieve the timestamp and location (lat, long) of the device
|
if (device != null) {
|
||||||
// pipDevice.setLongitude();
|
/*deviceManagementService.getDeviceType(deviceIdentifier.getType());*/
|
||||||
// pipDevice.setAltitude();
|
pipDevice.setDevice(device);
|
||||||
// pipDevice.setTimestamp();
|
pipDevice.setRoles(getRoleOfDevice(device));
|
||||||
|
pipDevice.setDeviceType(deviceType);
|
||||||
|
pipDevice.setDeviceIdentifier(deviceIdentifier);
|
||||||
|
pipDevice.setUserId(device.getEnrolmentInfo().getOwner());
|
||||||
|
pipDevice.setOwnershipType(device.getEnrolmentInfo().getOwnership().toString());
|
||||||
|
|
||||||
|
// TODO : Find a way to retrieve the timestamp and location (lat, long) of the device
|
||||||
|
// pipDevice.setLongitude();
|
||||||
|
// pipDevice.setAltitude();
|
||||||
|
// pipDevice.setTimestamp();
|
||||||
|
} else {
|
||||||
|
// Remove this
|
||||||
|
for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
|
||||||
|
log.debug("StackTraceElement : " + ste);
|
||||||
|
}
|
||||||
|
throw new PolicyManagementException("Device details cannot be null.");
|
||||||
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred when retrieving the data related to device from the database.";
|
String msg = "Error occurred when retrieving the data related to device from the database.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
@ -93,6 +106,16 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
|
|||||||
List<Policy> policies = policyManager.getPoliciesOfDeviceType(pipDevice.getDeviceType().getName());
|
List<Policy> policies = policyManager.getPoliciesOfDeviceType(pipDevice.getDeviceType().getName());
|
||||||
PolicyFilter policyFilter = new PolicyFilterImpl();
|
PolicyFilter policyFilter = new PolicyFilterImpl();
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies for the device type : " + pipDevice.getDeviceType().getName() + " : " +
|
||||||
|
policies.size());
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
log.debug("Names of policy for above device type : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
policies = policyFilter.filterActivePolicies(policies);
|
||||||
|
|
||||||
if (pipDevice.getDeviceType() != null) {
|
if (pipDevice.getDeviceType() != null) {
|
||||||
policies = policyFilter.filterDeviceTypeBasedPolicies(pipDevice.getDeviceType().getName(), policies);
|
policies = policyFilter.filterDeviceTypeBasedPolicies(pipDevice.getDeviceType().getName(), policies);
|
||||||
}
|
}
|
||||||
@ -106,6 +129,14 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
|
|||||||
policies = policyFilter.filterUserBasedPolicies(pipDevice.getUserId(), policies);
|
policies = policyFilter.filterUserBasedPolicies(pipDevice.getUserId(), policies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("No of policies selected for the device type : " + pipDevice.getDeviceType().getName() + " : " +
|
||||||
|
policies.size());
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
log.debug("Names of selected policy for above device type : " + policy.getPolicyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return policies;
|
return policies;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,12 +148,14 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
|
|||||||
|
|
||||||
private String[] getRoleOfDevice(Device device) throws PolicyManagementException {
|
private String[] getRoleOfDevice(Device device) throws PolicyManagementException {
|
||||||
try {
|
try {
|
||||||
return CarbonContext.getThreadLocalCarbonContext().getUserRealm().
|
UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
|
||||||
getUserStoreManager().getRoleListOfUser(device.getEnrolmentInfo().getOwner());
|
if (userRealm != null) {
|
||||||
|
return userRealm.getUserStoreManager().getRoleListOfUser(device.getEnrolmentInfo().getOwner());
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred when retrieving roles related to user name.";
|
throw new PolicyManagementException("Error occurred when retrieving roles related to user name.", e);
|
||||||
log.error(msg, e);
|
|
||||||
throw new PolicyManagementException(msg, e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,12 +172,11 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalPolicies;
|
return finalPolicies;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DeviceManagementProviderService getDeviceManagementService() {
|
private DeviceManagementProviderService getDeviceManagementService() {
|
||||||
return PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
return new DeviceManagementProviderServiceImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,8 @@ package org.wso2.carbon.policy.mgt.core.internal;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.ntask.core.service.TaskService;
|
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||||
@ -31,6 +33,8 @@ import org.wso2.carbon.policy.mgt.core.config.PolicyConfigurationManager;
|
|||||||
import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig;
|
import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig;
|
||||||
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
|
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleServiceImpl;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,6 +86,13 @@ public class PolicyManagementServiceComponent {
|
|||||||
componentContext.getBundleContext().registerService(
|
componentContext.getBundleContext().registerService(
|
||||||
PolicyManagerService.class.getName(), new PolicyManagerServiceImpl(), null);
|
PolicyManagerService.class.getName(), new PolicyManagerServiceImpl(), null);
|
||||||
|
|
||||||
|
PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||||
|
getDeviceManagementConfigRepository().getPolicyConfiguration();
|
||||||
|
if(policyConfiguration.getMonitoringEnable()) {
|
||||||
|
TaskScheduleService taskScheduleService = new TaskScheduleServiceImpl();
|
||||||
|
taskScheduleService.startTask(policyConfiguration.getMonitoringFrequency());
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error("Error occurred while initializing the Policy management core.", t);
|
log.error("Error occurred while initializing the Policy management core.", t);
|
||||||
}
|
}
|
||||||
@ -160,7 +171,7 @@ public class PolicyManagementServiceComponent {
|
|||||||
|
|
||||||
protected void setPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
|
protected void setPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Setting Policy Monitoring Service");
|
log.debug("Setting Policy Monitoring Service for " + policyMonitoringService.getType());
|
||||||
}
|
}
|
||||||
// TODO: FIX THE device type by taking from properties
|
// TODO: FIX THE device type by taking from properties
|
||||||
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(policyMonitoringService.getType(),
|
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(policyMonitoringService.getType(),
|
||||||
@ -169,7 +180,7 @@ public class PolicyManagementServiceComponent {
|
|||||||
|
|
||||||
protected void unsetPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
|
protected void unsetPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Removing the Policy Monitoring Service");
|
log.debug("Removing the Policy Monitoring Service for " + policyMonitoringService.getType());
|
||||||
}
|
}
|
||||||
// TODO: FIX THE device type by taking from properties
|
// TODO: FIX THE device type by taking from properties
|
||||||
PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService(policyMonitoringService.getType());
|
PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService(policyMonitoringService.getType());
|
||||||
|
|||||||
@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.core.mgt;
|
|||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
|
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||||
@ -39,4 +40,6 @@ public interface MonitoringManager {
|
|||||||
|
|
||||||
void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException;
|
void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException;
|
||||||
|
|
||||||
|
List<DeviceType> getDeviceTypes() throws PolicyComplianceException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,10 +19,12 @@ package org.wso2.carbon.policy.mgt.core.mgt;
|
|||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PolicyManager {
|
public interface PolicyManager {
|
||||||
@ -37,6 +39,10 @@ public interface PolicyManager {
|
|||||||
|
|
||||||
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
||||||
|
|
||||||
|
void activatePolicy(int policyId) throws PolicyManagementException;
|
||||||
|
|
||||||
|
void inactivatePolicy(int policyId) throws PolicyManagementException;
|
||||||
|
|
||||||
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws
|
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws
|
||||||
PolicyManagementException;
|
PolicyManagementException;
|
||||||
|
|
||||||
@ -63,6 +69,8 @@ public interface PolicyManager {
|
|||||||
void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, Policy policy)
|
void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, Policy policy)
|
||||||
throws PolicyManagementException;
|
throws PolicyManagementException;
|
||||||
|
|
||||||
|
List<DeviceType> applyChangesMadeToPolicies() throws PolicyManagementException;
|
||||||
|
|
||||||
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException;
|
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||||
@ -72,4 +80,6 @@ public interface PolicyManager {
|
|||||||
int getPolicyCount() throws PolicyManagementException;
|
int getPolicyCount() throws PolicyManagementException;
|
||||||
|
|
||||||
Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||||
|
|
||||||
|
HashMap<Integer, Integer> getAppliedPolicyIdsDeviceIds() throws PolicyManagementException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,55 +21,62 @@ package org.wso2.carbon.policy.mgt.core.mgt.impl;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfigRepository;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceDecisionPoint;
|
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceDecisionPoint;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
|
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAO;
|
import org.wso2.carbon.policy.mgt.core.dao.*;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAOException;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.impl.ComplianceDecisionPointImpl;
|
import org.wso2.carbon.policy.mgt.core.impl.ComplianceDecisionPointImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class MonitoringManagerImpl implements MonitoringManager {
|
public class MonitoringManagerImpl implements MonitoringManager {
|
||||||
|
|
||||||
private PolicyDAO policyDAO;
|
private PolicyDAO policyDAO;
|
||||||
private DeviceDAO deviceDAO;
|
// private DeviceDAO deviceDAO;
|
||||||
|
private DeviceTypeDAO deviceTypeDAO;
|
||||||
private MonitoringDAO monitoringDAO;
|
private MonitoringDAO monitoringDAO;
|
||||||
private ComplianceDecisionPoint complianceDecisionPoint;
|
private ComplianceDecisionPoint complianceDecisionPoint;
|
||||||
|
private PolicyConfiguration policyConfiguration;
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class);
|
private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class);
|
||||||
private static final String OPERATION_MONITOR = "MONITOR";
|
private static final String OPERATION_MONITOR = "MONITOR";
|
||||||
|
|
||||||
public MonitoringManagerImpl() {
|
public MonitoringManagerImpl() {
|
||||||
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
|
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
|
||||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
// this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||||
|
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
this.monitoringDAO = PolicyManagementDAOFactory.getMonitoringDAO();
|
this.monitoringDAO = PolicyManagementDAOFactory.getMonitoringDAO();
|
||||||
this.complianceDecisionPoint = new ComplianceDecisionPointImpl();
|
this.complianceDecisionPoint = new ComplianceDecisionPointImpl();
|
||||||
|
this.policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||||
|
getDeviceManagementConfigRepository().getPolicyConfiguration();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -81,8 +88,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
|||||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
PolicyManager manager = new PolicyManagerImpl();
|
PolicyManager manager = new PolicyManagerImpl();
|
||||||
Device device = service.getDevice(deviceIdentifier);
|
Device device = service.getDevice(deviceIdentifier);
|
||||||
Policy policy = manager.getAppliedPolicyToDevice(deviceIdentifier); //policyDAO.getAppliedPolicy(device
|
Policy policy = manager.getAppliedPolicyToDevice(deviceIdentifier);
|
||||||
// .getId());
|
|
||||||
if (policy != null) {
|
if (policy != null) {
|
||||||
PolicyMonitoringService monitoringService = PolicyManagementDataHolder.getInstance().
|
PolicyMonitoringService monitoringService = PolicyManagementDataHolder.getInstance().
|
||||||
getPolicyMonitoringService(deviceIdentifier.getType());
|
getPolicyMonitoringService(deviceIdentifier.getType());
|
||||||
@ -110,14 +116,19 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
|||||||
//This was added because update query below that did not return the update table primary key.
|
//This was added because update query below that did not return the update table primary key.
|
||||||
|
|
||||||
if (complianceFeatures != null && !complianceFeatures.isEmpty()) {
|
if (complianceFeatures != null && !complianceFeatures.isEmpty()) {
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
try {
|
||||||
monitoringDAO.setDeviceAsNoneCompliance(device.getId(), policy.getId());
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
if (log.isDebugEnabled()) {
|
monitoringDAO.setDeviceAsNoneCompliance(device.getId(), policy.getId());
|
||||||
log.debug("Compliance status primary key " + complianceData.getId());
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Compliance status primary key " + complianceData.getId());
|
||||||
|
}
|
||||||
|
monitoringDAO.addNoneComplianceFeatures(complianceData.getId(), device.getId(),
|
||||||
|
complianceFeatures);
|
||||||
|
|
||||||
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
// complianceData.setId(cmf.getId());
|
|
||||||
monitoringDAO.addNoneComplianceFeatures(complianceData.getId(), device.getId(), complianceFeatures);
|
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
|
||||||
complianceDecisionPoint.validateDevicePolicyCompliance(deviceIdentifier, complianceData);
|
complianceDecisionPoint.validateDevicePolicyCompliance(deviceIdentifier, complianceData);
|
||||||
List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList();
|
List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList();
|
||||||
for (ComplianceFeature compFeature : complianceFeatures) {
|
for (ComplianceFeature compFeature : complianceFeatures) {
|
||||||
@ -128,11 +139,14 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
try {
|
||||||
monitoringDAO.setDeviceAsCompliance(device.getId(), policy.getId());
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
//complianceData.setId(cmf.getId());
|
monitoringDAO.setDeviceAsCompliance(device.getId(), policy.getId());
|
||||||
monitoringDAO.deleteNoneComplianceData(complianceData.getId());
|
monitoringDAO.deleteNoneComplianceData(complianceData.getId());
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -151,8 +165,6 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
|||||||
PolicyManagementDAOFactory.rollbackTransaction();
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
throw new PolicyComplianceException("Unable to add the none compliance features to database for device " +
|
throw new PolicyComplianceException("Unable to add the none compliance features to database for device " +
|
||||||
deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e);
|
deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e);
|
||||||
} finally {
|
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
|
||||||
}
|
}
|
||||||
return complianceFeatures;
|
return complianceFeatures;
|
||||||
}
|
}
|
||||||
@ -162,7 +174,6 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
|||||||
try {
|
try {
|
||||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
Device device = service.getDevice(deviceIdentifier);
|
Device device = service.getDevice(deviceIdentifier);
|
||||||
//deviceDAO.getDevice(deviceIdentifier, tenantId);
|
|
||||||
PolicyManagementDAOFactory.openConnection();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
ComplianceData complianceData = monitoringDAO.getCompliance(device.getId());
|
ComplianceData complianceData = monitoringDAO.getCompliance(device.getId());
|
||||||
if (complianceData == null || !complianceData.isStatus()) {
|
if (complianceData == null || !complianceData.isStatus()) {
|
||||||
@ -214,28 +225,42 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException {
|
public void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException {
|
||||||
|
|
||||||
|
ComplianceDecisionPoint decisionPoint = new ComplianceDecisionPointImpl();
|
||||||
|
|
||||||
|
//int tenantId = PolicyManagerUtil.getTenantId();
|
||||||
|
Map<Integer, Device> deviceIds = new HashMap<>();
|
||||||
|
List<ComplianceData> complianceDatas;
|
||||||
|
HashMap<Integer, Integer> devicePolicyIdMap;
|
||||||
|
|
||||||
|
for (Device device : devices) {
|
||||||
|
deviceIds.put(device.getId(), device);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Integer> deviceIDs = new ArrayList<>(deviceIds.keySet());
|
||||||
try {
|
try {
|
||||||
ComplianceDecisionPoint decisionPoint = new ComplianceDecisionPointImpl();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
|
complianceDatas = monitoringDAO.getCompliance(deviceIDs);
|
||||||
|
devicePolicyIdMap = policyDAO.getAppliedPolicyIds(deviceIDs);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyComplianceException("SQL error occurred while getting monitoring details.", e);
|
||||||
|
} catch (MonitoringDAOException e) {
|
||||||
|
throw new PolicyComplianceException("SQL error occurred while getting monitoring details.", e);
|
||||||
|
} catch (PolicyManagerDAOException e) {
|
||||||
|
throw new PolicyComplianceException("SQL error occurred while getting policy details.", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
//int tenantId = PolicyManagerUtil.getTenantId();
|
Map<Integer, Device> deviceIdsToAddOperation = new HashMap<>();
|
||||||
Map<Integer, Device> deviceIds = new HashMap<>();
|
Map<Integer, Device> deviceIdsWithExistingOperation = new HashMap<>();
|
||||||
|
Map<Integer, Device> inactiveDeviceIds = new HashMap<>();
|
||||||
for (Device device : devices) {
|
Map<Integer, Device> deviceToMarkUnreachable = new HashMap<>();
|
||||||
deviceIds.put(device.getId(), device);
|
Map<Integer, Integer> firstTimeDeviceIdsWithPolicyIds = new HashMap<>();
|
||||||
}
|
|
||||||
|
|
||||||
List<Integer> deviceIDs = new ArrayList<>(deviceIds.keySet());
|
|
||||||
List<ComplianceData> complianceDatas = monitoringDAO.getCompliance(deviceIDs);
|
|
||||||
HashMap<Integer, Integer> devicePolicyIdMap = policyDAO.getAppliedPolicyIds(deviceIDs);
|
|
||||||
|
|
||||||
Map<Integer, Device> deviceIdsToAddOperation = new HashMap<>();
|
|
||||||
Map<Integer, Device> deviceIdsWithExistingOperation = new HashMap<>();
|
|
||||||
Map<Integer, Device> inactiveDeviceIds = new HashMap<>();
|
|
||||||
Map<Integer, Integer> firstTimeDeviceIdsWithPolicyIds = new HashMap<>();
|
|
||||||
|
|
||||||
Map<Integer, ComplianceData> tempMap = new HashMap<>();
|
|
||||||
|
|
||||||
|
Map<Integer, ComplianceData> tempMap = new HashMap<>();
|
||||||
|
|
||||||
|
try {
|
||||||
if (complianceDatas != null || !complianceDatas.isEmpty()) {
|
if (complianceDatas != null || !complianceDatas.isEmpty()) {
|
||||||
for (ComplianceData complianceData : complianceDatas) {
|
for (ComplianceData complianceData : complianceDatas) {
|
||||||
|
|
||||||
@ -247,8 +272,12 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
|||||||
} else {
|
} else {
|
||||||
deviceIdsWithExistingOperation.put(complianceData.getDeviceId(),
|
deviceIdsWithExistingOperation.put(complianceData.getDeviceId(),
|
||||||
deviceIds.get(complianceData.getDeviceId()));
|
deviceIds.get(complianceData.getDeviceId()));
|
||||||
|
if (complianceData.getAttempts() >= policyConfiguration.getMinRetriesToMarkUnreachable()) {
|
||||||
|
deviceToMarkUnreachable.put(complianceData.getDeviceId(),
|
||||||
|
deviceIds.get(complianceData.getDeviceId()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (complianceData.getAttempts() >= 20) {
|
if (complianceData.getAttempts() >= policyConfiguration.getMinRetriesToMarkInactive()) {
|
||||||
inactiveDeviceIds.put(complianceData.getDeviceId(),
|
inactiveDeviceIds.put(complianceData.getDeviceId(),
|
||||||
deviceIds.get(complianceData.getDeviceId()));
|
deviceIds.get(complianceData.getDeviceId()));
|
||||||
}
|
}
|
||||||
@ -256,7 +285,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
if (!tempMap.containsKey(device.getId())) {
|
if ((!tempMap.containsKey(device.getId())) && (devicePolicyIdMap.containsKey(device.getId()))) {
|
||||||
deviceIdsToAddOperation.put(device.getId(), device);
|
deviceIdsToAddOperation.put(device.getId(), device);
|
||||||
firstTimeDeviceIdsWithPolicyIds.put(device.getId(), devicePolicyIdMap.get(device.getId()));
|
firstTimeDeviceIdsWithPolicyIds.put(device.getId(), devicePolicyIdMap.get(device.getId()));
|
||||||
}
|
}
|
||||||
@ -272,37 +301,59 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
|||||||
PolicyManagementDAOFactory.beginTransaction();
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
|
|
||||||
if (!deviceIdsToAddOperation.isEmpty()) {
|
if (!deviceIdsToAddOperation.isEmpty()) {
|
||||||
this.addMonitoringOperationsToDatabase(new ArrayList<>(deviceIdsToAddOperation.values()));
|
|
||||||
monitoringDAO.addComplianceDetails(firstTimeDeviceIdsWithPolicyIds);
|
monitoringDAO.addComplianceDetails(firstTimeDeviceIdsWithPolicyIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!deviceIdsWithExistingOperation.isEmpty()) {
|
if (!deviceIdsWithExistingOperation.isEmpty()) {
|
||||||
monitoringDAO.updateAttempts(new ArrayList<>(deviceIdsWithExistingOperation.keySet()), false);
|
monitoringDAO.updateAttempts(new ArrayList<>(deviceIdsWithExistingOperation.keySet()), false);
|
||||||
//TODO: Add attempts. This has to be fixed in the get pending operation tables too. This will be
|
|
||||||
// decisionPoint.setDevicesAsUnreachable(this.getDeviceIdentifiersFromDevices(
|
|
||||||
// new ArrayList<>(deviceIdsWithExistingOperation.values())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
|
||||||
} catch (MonitoringDAOException e) {
|
} catch (MonitoringDAOException e) {
|
||||||
PolicyManagementDAOFactory.rollbackTransaction();
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
throw new PolicyComplianceException("Error occurred from monitoring dao.", e);
|
throw new PolicyComplianceException("Error occurred from monitoring dao.", e);
|
||||||
} catch (OperationManagementException e) {
|
|
||||||
PolicyManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new PolicyComplianceException("Error occurred while adding monitoring operation to devices", e);
|
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
PolicyManagementDAOFactory.rollbackTransaction();
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
throw new PolicyComplianceException("Error occurred reading the applied policies to devices.", e);
|
throw new PolicyComplianceException("Error occurred reading the applied policies to devices.", e);
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
PolicyManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new PolicyComplianceException("Error occurred while adding monitoring operation to DB.");
|
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!deviceIdsToAddOperation.isEmpty()) {
|
||||||
|
try {
|
||||||
|
this.addMonitoringOperationsToDatabase(new ArrayList<>(deviceIdsToAddOperation.values()));
|
||||||
|
} catch (OperationManagementException e) {
|
||||||
|
throw new PolicyComplianceException("Error occurred while adding monitoring operation to devices", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO : This should be uncommented, this is to mark the device as unreachable, But given the current implementation
|
||||||
|
// we are not able to do so.
|
||||||
|
|
||||||
|
// if(!deviceToMarkUnreachable.isEmpty()) {
|
||||||
|
// decisionPoint.setDevicesAsUnreachable(this.getDeviceIdentifiersFromDevices(
|
||||||
|
// new ArrayList<>(deviceToMarkUnreachable.values())));
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceType> getDeviceTypes() throws PolicyComplianceException {
|
||||||
|
|
||||||
|
List<DeviceType> deviceTypes = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
deviceTypes = deviceTypeDAO.getDeviceTypes();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error occurred while getting the device types.", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return deviceTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMonitoringOperationsToDatabase(List<Device> devices)
|
private void addMonitoringOperationsToDatabase(List<Device> devices)
|
||||||
throws PolicyComplianceException, OperationManagementException, DeviceManagementException {
|
throws PolicyComplianceException, OperationManagementException {
|
||||||
|
|
||||||
List<DeviceIdentifier> deviceIdentifiers = this.getDeviceIdentifiersFromDevices(devices);
|
List<DeviceIdentifier> deviceIdentifiers = this.getDeviceIdentifiersFromDevices(devices);
|
||||||
CommandOperation monitoringOperation = new CommandOperation();
|
CommandOperation monitoringOperation = new CommandOperation();
|
||||||
@ -311,9 +362,6 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
|||||||
monitoringOperation.setCode(OPERATION_MONITOR);
|
monitoringOperation.setCode(OPERATION_MONITOR);
|
||||||
|
|
||||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
if (service == null) {
|
|
||||||
throw new DeviceManagementException("Error occurred while retrieving Device Management Service");
|
|
||||||
}
|
|
||||||
service.addOperation(monitoringOperation, deviceIdentifiers);
|
service.addOperation(monitoringOperation, deviceIdentifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,43 +20,39 @@ package org.wso2.carbon.policy.mgt.core.mgt.impl;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
import org.wso2.carbon.policy.mgt.common.*;
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.cache.impl.PolicyCacheManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.*;
|
import org.wso2.carbon.policy.mgt.core.dao.*;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PolicyManagerImpl implements PolicyManager {
|
public class PolicyManagerImpl implements PolicyManager {
|
||||||
|
|
||||||
private PolicyDAO policyDAO;
|
private PolicyDAO policyDAO;
|
||||||
private ProfileDAO profileDAO;
|
private ProfileDAO profileDAO;
|
||||||
private FeatureDAO featureDAO;
|
private FeatureDAO featureDAO;
|
||||||
private DeviceDAO deviceDAO;
|
|
||||||
// private DeviceTypeDAO deviceTypeDAO;
|
|
||||||
private ProfileManager profileManager;
|
private ProfileManager profileManager;
|
||||||
|
private PolicyCacheManager policyCacheManager;
|
||||||
private static Log log = LogFactory.getLog(PolicyManagerImpl.class);
|
private static Log log = LogFactory.getLog(PolicyManagerImpl.class);
|
||||||
|
|
||||||
public PolicyManagerImpl() {
|
public PolicyManagerImpl() {
|
||||||
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
|
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
|
||||||
this.profileDAO = PolicyManagementDAOFactory.getProfileDAO();
|
this.profileDAO = PolicyManagementDAOFactory.getProfileDAO();
|
||||||
this.featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
|
this.featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
|
||||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
||||||
// this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
|
||||||
this.profileManager = new ProfileManagerImpl();
|
this.profileManager = new ProfileManagerImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +68,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
profile.setCreatedDate(currentTimestamp);
|
profile.setCreatedDate(currentTimestamp);
|
||||||
profile.setUpdatedDate(currentTimestamp);
|
profile.setUpdatedDate(currentTimestamp);
|
||||||
|
|
||||||
|
|
||||||
profileDAO.addProfile(profile);
|
profileDAO.addProfile(profile);
|
||||||
featureDAO.addProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId());
|
featureDAO.addProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId());
|
||||||
}
|
}
|
||||||
@ -110,17 +105,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
|
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (policy.getEndDate() != null & policy.getStartDate() != null) {
|
|
||||||
// policyDAO.addDatesToPolicy(policy.getStartDate(), policy.getEndDate(), policy);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (policy.getStartTime() != 0 & policy.getEndTime() != 0) {
|
|
||||||
// policyDAO.addTimesToPolicy(policy.getStartTime(), policy.getEndTime(), policy);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (policy.getLatitude() != null && policy.getLongitude() != null) {
|
|
||||||
// policyDAO.addLocationToPolicy(policy.getLatitude(), policy.getLongitude(), policy);
|
|
||||||
// }
|
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
@ -147,7 +131,13 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
policy = policyDAO.updatePolicy(policy);
|
// This will keep track of the policies updated.
|
||||||
|
policyDAO.recordUpdatedPolicy(policy);
|
||||||
|
|
||||||
|
policyDAO.updatePolicy(policy);
|
||||||
|
profileDAO.updateProfile(policy.getProfile());
|
||||||
|
featureDAO.updateProfileFeatures(policy.getProfile().getProfileFeaturesList(), policy.getProfile()
|
||||||
|
.getProfileId());
|
||||||
policyDAO.deleteAllPolicyRelatedConfigs(policy.getId());
|
policyDAO.deleteAllPolicyRelatedConfigs(policy.getId());
|
||||||
|
|
||||||
if (policy.getUsers() != null) {
|
if (policy.getUsers() != null) {
|
||||||
@ -177,23 +167,20 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
|
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (policy.getEndDate() != null & policy.getStartDate() != null) {
|
|
||||||
// policyDAO.addDatesToPolicy(policy.getStartDate(), policy.getEndDate(), policy);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (policy.getStartTime() != 0 & policy.getEndTime() != 0) {
|
|
||||||
// policyDAO.addTimesToPolicy(policy.getStartTime(), policy.getEndTime(), policy);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (policy.getLatitude() != null && policy.getLongitude() != null) {
|
|
||||||
// policyDAO.addLocationToPolicy(policy.getLatitude(), policy.getLongitude(), policy);
|
|
||||||
// }
|
|
||||||
|
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
PolicyManagementDAOFactory.rollbackTransaction();
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
throw new PolicyManagementException("Error occurred while updating the policy ("
|
throw new PolicyManagementException("Error occurred while updating the policy ("
|
||||||
+ policy.getId() + " - " + policy.getPolicyName() + ")", e);
|
+ policy.getId() + " - " + policy.getPolicyName() + ")", e);
|
||||||
|
} catch (ProfileManagerDAOException e) {
|
||||||
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
|
throw new PolicyManagementException("Error occurred while updating the profile (" +
|
||||||
|
policy.getProfile().getProfileName() + ")", e);
|
||||||
|
} catch (FeatureManagerDAOException e) {
|
||||||
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
|
throw new PolicyManagementException("Error occurred while updating the profile features (" +
|
||||||
|
policy.getProfile().getProfileName() + ")", e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
@ -204,8 +191,21 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
|
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
|
||||||
boolean bool;
|
boolean bool;
|
||||||
try {
|
try {
|
||||||
|
// List<Policy> existingPolicies = this.getPolicies();
|
||||||
|
List<Policy> existingPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
bool = policyDAO.updatePolicyPriorities(policies);
|
bool = policyDAO.updatePolicyPriorities(policies);
|
||||||
|
|
||||||
|
// This logic is added because ui sends only policy id and priority to update priorities.
|
||||||
|
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
for (Policy exPolicy : existingPolicies) {
|
||||||
|
if (policy.getId() == exPolicy.getId()) {
|
||||||
|
policy.setProfile(exPolicy.getProfile());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
policyDAO.recordUpdatedPolicies(policies);
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
PolicyManagementDAOFactory.rollbackTransaction();
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
@ -245,12 +245,13 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deletePolicy(int policyId) throws PolicyManagementException {
|
public boolean deletePolicy(int policyId) throws PolicyManagementException {
|
||||||
|
boolean bool;
|
||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
|
|
||||||
Policy policy = policyDAO.getPolicy(policyId);
|
Policy policy = policyDAO.getPolicy(policyId);
|
||||||
policyDAO.deleteAllPolicyRelatedConfigs(policyId);
|
policyDAO.deleteAllPolicyRelatedConfigs(policyId);
|
||||||
policyDAO.deletePolicy(policyId);
|
bool = policyDAO.deletePolicy(policyId);
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Profile ID: " + policy.getProfileId());
|
log.debug("Profile ID: " + policy.getProfileId());
|
||||||
@ -260,7 +261,7 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
|
|
||||||
profileDAO.deleteProfile(policy.getProfileId());
|
profileDAO.deleteProfile(policy.getProfileId());
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
return true;
|
return bool;
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
PolicyManagementDAOFactory.rollbackTransaction();
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
throw new PolicyManagementException("Error occurred while deleting the policy (" + policyId + ")", e);
|
throw new PolicyManagementException("Error occurred while deleting the policy (" + policyId + ")", e);
|
||||||
@ -277,19 +278,57 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void activatePolicy(int policyId) throws PolicyManagementException {
|
||||||
|
try {
|
||||||
|
Policy policy = this.getPolicy(policyId);
|
||||||
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
|
policyDAO.activatePolicy(policyId);
|
||||||
|
policyDAO.recordUpdatedPolicy(policy);
|
||||||
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (PolicyManagerDAOException e) {
|
||||||
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
|
throw new PolicyManagementException("Error occurred while activating the policy. (Id : " + policyId + ")" +
|
||||||
|
"", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void inactivatePolicy(int policyId) throws PolicyManagementException {
|
||||||
|
try {
|
||||||
|
Policy policy = this.getPolicy(policyId);
|
||||||
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
|
policyDAO.inactivatePolicy(policyId);
|
||||||
|
policyDAO.recordUpdatedPolicy(policy);
|
||||||
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (PolicyManagerDAOException e) {
|
||||||
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
|
throw new PolicyManagementException("Error occurred while inactivating the policy. (Id : " + policyId +
|
||||||
|
")" +
|
||||||
|
"", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList,
|
public Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList,
|
||||||
Policy policy) throws PolicyManagementException {
|
Policy policy) throws PolicyManagementException {
|
||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
|
||||||
if (policy.getId() == 0) {
|
|
||||||
policyDAO.addPolicy(policy);
|
|
||||||
}
|
|
||||||
List<Device> deviceList = new ArrayList<>();
|
List<Device> deviceList = new ArrayList<>();
|
||||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) {
|
for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) {
|
||||||
deviceList.add(service.getDevice(deviceIdentifier));
|
deviceList.add(service.getDevice(deviceIdentifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
|
if (policy.getId() == 0) {
|
||||||
|
policyDAO.addPolicy(policy);
|
||||||
|
}
|
||||||
|
|
||||||
policy = policyDAO.addPolicyToDevice(deviceList, policy);
|
policy = policyDAO.addPolicyToDevice(deviceList, policy);
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
|
||||||
@ -391,17 +430,12 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.openConnection();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
policy = policyDAO.getPolicyByProfileID(profileId);
|
policy = policyDAO.getPolicyByProfileID(profileId);
|
||||||
deviceList = getPolicyAppliedDevicesIds(policy.getId());
|
|
||||||
roleNames = policyDAO.getPolicyAppliedRoles(policy.getId());
|
roleNames = policyDAO.getPolicyAppliedRoles(policy.getId());
|
||||||
// policyDAO.getDatesOfPolicy(policy);
|
|
||||||
// policyDAO.getTimesOfPolicy(policy);
|
|
||||||
// policyDAO.getLocationsOfPolicy(policy);
|
|
||||||
|
|
||||||
profile = profileDAO.getProfile(profileId);
|
profile = profileDAO.getProfile(profileId);
|
||||||
|
|
||||||
policy.setProfile(profile);
|
policy.setProfile(profile);
|
||||||
policy.setRoles(roleNames);
|
policy.setRoles(roleNames);
|
||||||
policy.setDevices(deviceList);
|
|
||||||
|
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
throw new PolicyManagementException("Error occurred while getting the policy related to profile ID (" +
|
throw new PolicyManagementException("Error occurred while getting the policy related to profile ID (" +
|
||||||
@ -414,6 +448,10 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is due to connection close in following method too.
|
||||||
|
deviceList = getPolicyAppliedDevicesIds(policy.getId());
|
||||||
|
policy.setDevices(deviceList);
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,17 +465,13 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.openConnection();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
policy = policyDAO.getPolicy(policyId);
|
policy = policyDAO.getPolicy(policyId);
|
||||||
deviceList = getPolicyAppliedDevicesIds(policyId);
|
|
||||||
roleNames = policyDAO.getPolicyAppliedRoles(policyId);
|
|
||||||
// policyDAO.getDatesOfPolicy(policy);
|
|
||||||
// policyDAO.getTimesOfPolicy(policy);
|
|
||||||
// policyDAO.getLocationsOfPolicy(policy);
|
|
||||||
|
|
||||||
|
roleNames = policyDAO.getPolicyAppliedRoles(policyId);
|
||||||
Profile profile = profileDAO.getProfile(policy.getProfileId());
|
Profile profile = profileDAO.getProfile(policy.getProfileId());
|
||||||
|
|
||||||
policy.setProfile(profile);
|
policy.setProfile(profile);
|
||||||
policy.setRoles(roleNames);
|
policy.setRoles(roleNames);
|
||||||
policy.setDevices(deviceList);
|
|
||||||
|
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
throw new PolicyManagementException("Error occurred while getting the policy related to policy ID (" +
|
throw new PolicyManagementException("Error occurred while getting the policy related to policy ID (" +
|
||||||
@ -450,11 +484,16 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is done because connection close in below method too.
|
||||||
|
deviceList = this.getPolicyAppliedDevicesIds(policyId);
|
||||||
|
policy.setDevices(deviceList);
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Policy> getPolicies() throws PolicyManagementException {
|
public List<Policy> getPolicies() throws PolicyManagementException {
|
||||||
|
|
||||||
List<Policy> policyList;
|
List<Policy> policyList;
|
||||||
List<Profile> profileList;
|
List<Profile> profileList;
|
||||||
try {
|
try {
|
||||||
@ -465,7 +504,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.openConnection();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
policyList = policyDAO.getAllPolicies();
|
policyList = policyDAO.getAllPolicies();
|
||||||
// List<Profile> profileList = profileDAO.getAllProfiles();
|
|
||||||
|
|
||||||
for (Policy policy : policyList) {
|
for (Policy policy : policyList) {
|
||||||
for (Profile profile : profileList) {
|
for (Profile profile : profileList) {
|
||||||
@ -473,13 +511,9 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
policy.setProfile(profile);
|
policy.setProfile(profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
policy.setDevices(getPolicyAppliedDevicesIds(policy.getId()));
|
|
||||||
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
|
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
|
||||||
policy.setUsers(policyDAO.getPolicyAppliedUsers(policy.getId()));
|
policy.setUsers(policyDAO.getPolicyAppliedUsers(policy.getId()));
|
||||||
policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId()));
|
policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId()));
|
||||||
// policyDAO.getDatesOfPolicy(policy);
|
|
||||||
// policyDAO.getTimesOfPolicy(policy);
|
|
||||||
// policyDAO.getLocationsOfPolicy(policy);
|
|
||||||
}
|
}
|
||||||
Collections.sort(policyList);
|
Collections.sort(policyList);
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
@ -489,6 +523,13 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Following is done because connection close has been implemented in every method.
|
||||||
|
|
||||||
|
for (Policy policy : policyList) {
|
||||||
|
policy.setDevices(this.getPolicyAppliedDevicesIds(policy.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
return policyList;
|
return policyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,9 +539,11 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
List<Integer> policyIdList;
|
List<Integer> policyIdList;
|
||||||
List<Policy> policies = new ArrayList<>();
|
List<Policy> policies = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.openConnection();
|
|
||||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
Device device = service.getDevice(deviceIdentifier);
|
Device device = service.getDevice(deviceIdentifier);
|
||||||
|
|
||||||
|
PolicyManagementDAOFactory.openConnection();
|
||||||
policyIdList = policyDAO.getPolicyIdsOfDevice(device);
|
policyIdList = policyDAO.getPolicyIdsOfDevice(device);
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
throw new PolicyManagementException("Error occurred while getting the policies for device identifier (" +
|
throw new PolicyManagementException("Error occurred while getting the policies for device identifier (" +
|
||||||
@ -514,7 +557,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Policy> tempPolicyList = this.getPolicies();
|
// List<Policy> tempPolicyList = this.getPolicies();
|
||||||
|
List<Policy> tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
||||||
|
|
||||||
for (Policy policy : tempPolicyList) {
|
for (Policy policy : tempPolicyList) {
|
||||||
for (Integer i : policyIdList) {
|
for (Integer i : policyIdList) {
|
||||||
@ -531,22 +575,29 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
@Override
|
@Override
|
||||||
public List<Policy> getPoliciesOfDeviceType(String deviceTypeName) throws PolicyManagementException {
|
public List<Policy> getPoliciesOfDeviceType(String deviceTypeName) throws PolicyManagementException {
|
||||||
List<Policy> policies = new ArrayList<>();
|
List<Policy> policies = new ArrayList<>();
|
||||||
try {
|
// try {
|
||||||
List<Profile> profileList = profileManager.getProfilesOfDeviceType(deviceTypeName);
|
// List<Profile> profileList = profileManager.getProfilesOfDeviceType(deviceTypeName);
|
||||||
List<Policy> allPolicies = this.getPolicies();
|
// List<Policy> allPolicies = this.getPolicies();
|
||||||
|
List<Policy> allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
||||||
|
|
||||||
for (Profile profile : profileList) {
|
for (Policy policy : allPolicies) {
|
||||||
for (Policy policy : allPolicies) {
|
if (policy.getProfile().getDeviceType().getName().equalsIgnoreCase(deviceTypeName)) {
|
||||||
if (policy.getProfileId() == profile.getProfileId()) {
|
policies.add(policy);
|
||||||
policy.setProfile(profile);
|
|
||||||
policies.add(policy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Collections.sort(policies);
|
|
||||||
} catch (ProfileManagementException e) {
|
|
||||||
throw new PolicyManagementException("Error occurred while getting all the profile features.", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for (Profile profile : profileList) {
|
||||||
|
// for (Policy policy : allPolicies) {
|
||||||
|
// if (policy.getProfileId() == profile.getProfileId()) {
|
||||||
|
// policy.setProfile(profile);
|
||||||
|
// policies.add(policy);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
Collections.sort(policies);
|
||||||
|
// } catch (ProfileManagementException e) {
|
||||||
|
// throw new PolicyManagementException("Error occurred while getting all the profile features.", e);
|
||||||
|
// }
|
||||||
return policies;
|
return policies;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,7 +619,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Policy> tempPolicyList = this.getPolicies();
|
// List<Policy> tempPolicyList = this.getPolicies();
|
||||||
|
List<Policy> tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
||||||
|
|
||||||
for (Policy policy : tempPolicyList) {
|
for (Policy policy : tempPolicyList) {
|
||||||
for (Integer i : policyIdList) {
|
for (Integer i : policyIdList) {
|
||||||
@ -597,7 +649,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
List<Policy> tempPolicyList = this.getPolicies();
|
// List<Policy> tempPolicyList = this.getPolicies();
|
||||||
|
List<Policy> tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
||||||
|
|
||||||
for (Policy policy : tempPolicyList) {
|
for (Policy policy : tempPolicyList) {
|
||||||
for (Integer i : policyIdList) {
|
for (Integer i : policyIdList) {
|
||||||
@ -612,24 +665,45 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException {
|
public List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException {
|
||||||
|
|
||||||
List<Device> deviceList = new ArrayList<>();
|
List<Device> deviceList = new ArrayList<>();
|
||||||
List<Integer> deviceIds;
|
List<Integer> deviceIds;
|
||||||
try {
|
try {
|
||||||
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
|
List<Device> allDevices = service.getAllDevices();
|
||||||
|
|
||||||
PolicyManagementDAOFactory.openConnection();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
//int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
deviceIds = policyDAO.getPolicyAppliedDevicesIds(policyId);
|
deviceIds = policyDAO.getPolicyAppliedDevicesIds(policyId);
|
||||||
|
|
||||||
|
|
||||||
|
HashMap<Integer, Device> allDeviceMap = new HashMap<>();
|
||||||
|
|
||||||
|
if (!allDevices.isEmpty()) {
|
||||||
|
allDeviceMap = PolicyManagerUtil.covertDeviceListToMap(allDevices);
|
||||||
|
}
|
||||||
|
|
||||||
for (int deviceId : deviceIds) {
|
for (int deviceId : deviceIds) {
|
||||||
//TODO FIX ME
|
|
||||||
deviceList.add(deviceDAO.getDevice(new DeviceIdentifier(Integer.toString(deviceId), ""), tenantId));
|
if (allDeviceMap.containsKey(deviceId)) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Policy Applied device ids .............: " + deviceId + " - Policy Id " + policyId);
|
||||||
|
}
|
||||||
|
deviceList.add(allDeviceMap.get(deviceId));
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO FIX ME -- This is wrong, Device id is not device identifier, so converting is wrong.
|
||||||
|
|
||||||
|
//deviceList.add(deviceDAO.getDevice(new DeviceIdentifier(Integer.toString(deviceId), ""), tenantId));
|
||||||
}
|
}
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
throw new PolicyManagementException("Error occurred while getting the device ids related to policy id (" +
|
throw new PolicyManagementException("Error occurred while getting the device ids related to policy id (" +
|
||||||
policyId + ")", e);
|
policyId + ")", e);
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
throw new PolicyManagementException("Error occurred while getting the devices related to policy id (" +
|
|
||||||
policyId + ")", e);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
throw new PolicyManagementException("Error occurred while getting the devices related to policy id (" +
|
||||||
|
policyId + ")", e);
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
@ -646,11 +720,11 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
deviceId = device.getId();
|
deviceId = device.getId();
|
||||||
|
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
boolean exist = policyDAO.checkPolicyAvailable(deviceId);
|
boolean exist = policyDAO.checkPolicyAvailable(deviceId, device.getEnrolmentInfo().getId());
|
||||||
if (exist) {
|
if (exist) {
|
||||||
policyDAO.updateEffectivePolicyToDevice(deviceId, policy);
|
policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
|
||||||
} else {
|
} else {
|
||||||
policyDAO.addEffectivePolicyToDevice(deviceId, policy);
|
policyDAO.addEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
|
||||||
}
|
}
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
@ -665,6 +739,48 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DeviceType> applyChangesMadeToPolicies() throws PolicyManagementException {
|
||||||
|
|
||||||
|
List<DeviceType> changedDeviceTypes = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
//HashMap<Integer, Integer> map = policyDAO.getUpdatedPolicyIdandDeviceTypeId();
|
||||||
|
List<Policy> updatedPolicies = new ArrayList<>();
|
||||||
|
// List<Policy> activePolicies = new ArrayList<>();
|
||||||
|
// List<Policy> inactivePolicies = new ArrayList<>();
|
||||||
|
List<Integer> updatedPolicyIds = new ArrayList<>();
|
||||||
|
|
||||||
|
// List<Policy> allPolicies = this.getPolicies();
|
||||||
|
List<Policy> allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
|
||||||
|
|
||||||
|
for (Policy policy : allPolicies) {
|
||||||
|
if (policy.isUpdated()) {
|
||||||
|
updatedPolicies.add(policy);
|
||||||
|
updatedPolicyIds.add(policy.getId());
|
||||||
|
if (!changedDeviceTypes.contains(policy.getProfile().getDeviceType())) {
|
||||||
|
changedDeviceTypes.add(policy.getProfile().getDeviceType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if (policy.isActive()) {
|
||||||
|
// activePolicies.add(policy);
|
||||||
|
// } else {
|
||||||
|
// inactivePolicies.add(policy);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
|
policyDAO.markPoliciesAsUpdated(updatedPolicyIds);
|
||||||
|
policyDAO.removeRecordsAboutUpdatedPolicies();
|
||||||
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (PolicyManagerDAOException e) {
|
||||||
|
PolicyManagementDAOFactory.rollbackTransaction();
|
||||||
|
throw new PolicyManagementException("Error occurred while applying the changes to policy operations.", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return changedDeviceTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy)
|
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy)
|
||||||
throws PolicyManagementException {
|
throws PolicyManagementException {
|
||||||
@ -674,17 +790,15 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
Device device = service.getDevice(deviceIdentifier);
|
Device device = service.getDevice(deviceIdentifier);
|
||||||
deviceId = device.getId();
|
deviceId = device.getId();
|
||||||
// boolean exist = policyDAO.checkPolicyAvailable(deviceId);
|
|
||||||
|
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
|
|
||||||
Policy policySaved = policyDAO.getAppliedPolicy(deviceId);
|
Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId());
|
||||||
if (policySaved != null && policySaved.getId() != 0) {
|
if (policySaved != null && policySaved.getId() != 0) {
|
||||||
if (policy.getId() != policySaved.getId()){
|
if (policy.getId() != policySaved.getId()) {
|
||||||
policyDAO.updateEffectivePolicyToDevice(deviceId, policy);
|
policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
policyDAO.addEffectivePolicyToDevice(deviceId, policy);
|
policyDAO.addEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
|
||||||
}
|
}
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
@ -705,10 +819,10 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
|
|
||||||
boolean exist;
|
boolean exist;
|
||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.openConnection();
|
|
||||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
Device device = service.getDevice(deviceIdentifier);
|
Device device = service.getDevice(deviceIdentifier);
|
||||||
exist = policyDAO.checkPolicyAvailable(device.getId());
|
PolicyManagementDAOFactory.openConnection();
|
||||||
|
exist = policyDAO.checkPolicyAvailable(device.getId(), device.getEnrolmentInfo().getId());
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
throw new PolicyManagementException("Error occurred while checking whether device has a policy " +
|
throw new PolicyManagementException("Error occurred while checking whether device has a policy " +
|
||||||
"to apply.", e);
|
"to apply.", e);
|
||||||
@ -726,10 +840,11 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
@Override
|
@Override
|
||||||
public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.openConnection();
|
|
||||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
Device device = service.getDevice(deviceIdentifier);
|
Device device = service.getDevice(deviceIdentifier);
|
||||||
policyDAO.setPolicyApplied(device.getId());
|
|
||||||
|
PolicyManagementDAOFactory.openConnection();
|
||||||
|
policyDAO.setPolicyApplied(device.getId(), device.getEnrolmentInfo().getId());
|
||||||
return true;
|
return true;
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
throw new PolicyManagementException("Error occurred while setting the policy has applied to device (" +
|
throw new PolicyManagementException("Error occurred while setting the policy has applied to device (" +
|
||||||
@ -766,7 +881,7 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
Device device = service.getDevice(deviceIdentifier);
|
Device device = service.getDevice(deviceIdentifier);
|
||||||
//int policyId = policyDAO.getAppliedPolicyId(device.getId());
|
//int policyId = policyDAO.getAppliedPolicyId(device.getId());
|
||||||
PolicyManagementDAOFactory.openConnection();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
policy = policyDAO.getAppliedPolicy(device.getId());
|
policy = policyDAO.getAppliedPolicy(device.getId(), device.getEnrolmentInfo().getId());
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
throw new PolicyManagementException("Error occurred while getting device id.", e);
|
throw new PolicyManagementException("Error occurred while getting device id.", e);
|
||||||
} catch (PolicyManagerDAOException e) {
|
} catch (PolicyManagerDAOException e) {
|
||||||
@ -779,4 +894,18 @@ public class PolicyManagerImpl implements PolicyManager {
|
|||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<Integer, Integer> getAppliedPolicyIdsDeviceIds() throws PolicyManagementException {
|
||||||
|
try {
|
||||||
|
PolicyManagementDAOFactory.openConnection();
|
||||||
|
return policyDAO.getAppliedPolicyIdsDeviceIds();
|
||||||
|
} catch (PolicyManagerDAOException e) {
|
||||||
|
throw new PolicyManagementException("Error occurred while reading the policy applied database.", e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new PolicyManagementException("Error occurred while reading the policy applied database.", e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,13 +42,13 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
private static Log log = LogFactory.getLog(ProfileManagerImpl.class);
|
private static Log log = LogFactory.getLog(ProfileManagerImpl.class);
|
||||||
private ProfileDAO profileDAO;
|
private ProfileDAO profileDAO;
|
||||||
private FeatureDAO featureDAO;
|
private FeatureDAO featureDAO;
|
||||||
private DeviceDAO deviceDAO;
|
// private DeviceDAO deviceDAO;
|
||||||
private DeviceTypeDAO deviceTypeDAO;
|
private DeviceTypeDAO deviceTypeDAO;
|
||||||
|
|
||||||
public ProfileManagerImpl() {
|
public ProfileManagerImpl() {
|
||||||
profileDAO = PolicyManagementDAOFactory.getProfileDAO();
|
profileDAO = PolicyManagementDAOFactory.getProfileDAO();
|
||||||
featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
|
featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
|
||||||
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
// deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||||
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
PolicyManagementDAOFactory.beginTransaction();
|
PolicyManagementDAOFactory.beginTransaction();
|
||||||
profile = profileDAO.updateProfile(profile);
|
profileDAO.updateProfile(profile);
|
||||||
featureDAO.updateProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId());
|
featureDAO.updateProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId());
|
||||||
PolicyManagementDAOFactory.commitTransaction();
|
PolicyManagementDAOFactory.commitTransaction();
|
||||||
} catch (ProfileManagerDAOException e) {
|
} catch (ProfileManagerDAOException e) {
|
||||||
@ -149,35 +149,54 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
PolicyManagementDAOFactory.openConnection();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
profile = profileDAO.getProfile(profileId);
|
profile = profileDAO.getProfile(profileId);
|
||||||
featureList = featureDAO.getFeaturesForProfile(profileId);
|
featureList = featureDAO.getFeaturesForProfile(profileId);
|
||||||
deviceType = deviceTypeDAO.getDeviceType(profile.getDeviceType().getId());
|
|
||||||
|
|
||||||
profile.setProfileFeaturesList(featureList);
|
profile.setProfileFeaturesList(featureList);
|
||||||
profile.setDeviceType(deviceType);
|
|
||||||
|
|
||||||
} catch (ProfileManagerDAOException e) {
|
} catch (ProfileManagerDAOException e) {
|
||||||
throw new ProfileManagementException("Error occurred while getting profile id (" + profileId + ")", e);
|
throw new ProfileManagementException("Error occurred while getting profile id (" + profileId + ")", e);
|
||||||
} catch (FeatureManagerDAOException e) {
|
} catch (FeatureManagerDAOException e) {
|
||||||
throw new ProfileManagementException("Error occurred while getting features related profile id (" +
|
throw new ProfileManagementException("Error occurred while getting features related profile id (" +
|
||||||
profileId + ")", e);
|
profileId + ")", e);
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
throw new ProfileManagementException("Error occurred while getting device type related profile id (" +
|
|
||||||
profileId + ")", e);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new ProfileManagementException("Error occurred while opening a connection to the data source", e);
|
throw new ProfileManagementException("Error occurred while opening a connection to the data source", e);
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
deviceType = deviceTypeDAO.getDeviceType(profile.getDeviceType().getId());
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
throw new ProfileManagementException("Error occurred while getting features related profile id (" +
|
||||||
|
profileId + ")", e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new ProfileManagementException("SQL exception occurred while getting features related profile id (" +
|
||||||
|
profileId + ")", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
profile.setDeviceType(deviceType);
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Profile> getAllProfiles() throws ProfileManagementException {
|
public List<Profile> getAllProfiles() throws ProfileManagementException {
|
||||||
List<Profile> profileList;
|
List<Profile> profileList;
|
||||||
|
List<DeviceType> deviceTypes;
|
||||||
try {
|
try {
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
deviceTypes = deviceTypeDAO.getDeviceTypes();
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
PolicyManagementDAOFactory.openConnection();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
profileList = profileDAO.getAllProfiles();
|
profileList = profileDAO.getAllProfiles();
|
||||||
List<ProfileFeature> featureList = featureDAO.getAllProfileFeatures();
|
List<ProfileFeature> featureList = featureDAO.getAllProfileFeatures();
|
||||||
List<DeviceType> deviceTypes = deviceTypeDAO.getDeviceTypes();
|
|
||||||
for (Profile profile : profileList) {
|
for (Profile profile : profileList) {
|
||||||
|
|
||||||
List<ProfileFeature> list = new ArrayList<ProfileFeature>();
|
List<ProfileFeature> list = new ArrayList<ProfileFeature>();
|
||||||
@ -204,6 +223,7 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
throw new ProfileManagementException("Error occurred while opening a connection to the data source", e);
|
throw new ProfileManagementException("Error occurred while opening a connection to the data source", e);
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
|
// DeviceManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
return profileList;
|
return profileList;
|
||||||
}
|
}
|
||||||
@ -212,9 +232,16 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
public List<Profile> getProfilesOfDeviceType(String deviceTypeName) throws ProfileManagementException {
|
public List<Profile> getProfilesOfDeviceType(String deviceTypeName) throws ProfileManagementException {
|
||||||
List<Profile> profileList;
|
List<Profile> profileList;
|
||||||
List<ProfileFeature> featureList;
|
List<ProfileFeature> featureList;
|
||||||
|
DeviceType deviceType;
|
||||||
try {
|
try {
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
deviceType = deviceTypeDAO.getDeviceType(deviceTypeName);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
PolicyManagementDAOFactory.openConnection();
|
PolicyManagementDAOFactory.openConnection();
|
||||||
DeviceType deviceType = deviceTypeDAO.getDeviceType(deviceTypeName);
|
|
||||||
profileList = profileDAO.getProfilesOfDeviceType(deviceType);
|
profileList = profileDAO.getProfilesOfDeviceType(deviceType);
|
||||||
featureList = featureDAO.getAllProfileFeatures();
|
featureList = featureDAO.getAllProfileFeatures();
|
||||||
|
|
||||||
@ -238,6 +265,7 @@ public class ProfileManagerImpl implements ProfileManager {
|
|||||||
throw new ProfileManagementException("Error occurred while opening a connection to the data source", e);
|
throw new ProfileManagementException("Error occurred while opening a connection to the data source", e);
|
||||||
} finally {
|
} finally {
|
||||||
PolicyManagementDAOFactory.closeConnection();
|
PolicyManagementDAOFactory.closeConnection();
|
||||||
|
|
||||||
}
|
}
|
||||||
return profileList;
|
return profileList;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,11 +23,13 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.ntask.core.Task;
|
import org.wso2.carbon.ntask.core.Task;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||||
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
||||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
|
||||||
@ -62,48 +64,66 @@ public class MonitoringTask implements Task {
|
|||||||
log.debug("Monitoring task started to run.");
|
log.debug("Monitoring task started to run.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MonitoringManager monitoringManager = new MonitoringManagerImpl();
|
||||||
|
|
||||||
|
List<DeviceType> deviceTypes = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
List<DeviceType> deviceTypes = deviceTypeDAO.getDeviceTypes();
|
deviceTypes = monitoringManager.getDeviceTypes();
|
||||||
DeviceManagementProviderService deviceManagementProviderService =
|
} catch (PolicyComplianceException e) {
|
||||||
PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
log.error("Error occurred while getting the device types.");
|
||||||
MonitoringManager monitoringManager = new MonitoringManagerImpl();
|
}
|
||||||
|
|
||||||
for (DeviceType deviceType : deviceTypes) {
|
if (!deviceTypes.isEmpty()) {
|
||||||
PolicyMonitoringService monitoringService =
|
try {
|
||||||
PolicyManagementDataHolder.getInstance().getPolicyMonitoringService(deviceType.getName());
|
|
||||||
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType.getName());
|
|
||||||
if (monitoringService != null && !devices.isEmpty()) {
|
|
||||||
monitoringManager.addMonitoringOperation(devices);
|
|
||||||
|
|
||||||
List<Device> notifiableDevices = new ArrayList<>();
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Removing inactive and blocked devices from the list for the device type : " +
|
DeviceManagementProviderService deviceManagementProviderService =
|
||||||
deviceType);
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
||||||
|
|
||||||
|
for (DeviceType deviceType : deviceTypes) {
|
||||||
|
|
||||||
|
if(log.isDebugEnabled()){
|
||||||
|
log.debug("Running task for device type : " + deviceType.getName() );
|
||||||
}
|
}
|
||||||
for (Device device : devices) {
|
|
||||||
if (device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.INACTIVE) ||
|
PolicyMonitoringService monitoringService =
|
||||||
device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.BLOCKED)) {
|
PolicyManagementDataHolder.getInstance().getPolicyMonitoringService(deviceType.getName());
|
||||||
continue;
|
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType.getName());
|
||||||
} else {
|
if (monitoringService != null && !devices.isEmpty()) {
|
||||||
notifiableDevices.add(device);
|
monitoringManager.addMonitoringOperation(devices);
|
||||||
|
|
||||||
|
List<Device> notifiableDevices = new ArrayList<>();
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Removing inactive and blocked devices from the list for the device type : " +
|
||||||
|
deviceType.getName());
|
||||||
}
|
}
|
||||||
}
|
for (Device device : devices) {
|
||||||
if (log.isDebugEnabled()) {
|
if (device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.INACTIVE) ||
|
||||||
log.debug("Following devices selected to send the notification for " + deviceType);
|
device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.BLOCKED)) {
|
||||||
for (Device device : notifiableDevices) {
|
continue;
|
||||||
log.debug(device.getDeviceIdentifier());
|
} else {
|
||||||
|
notifiableDevices.add(device);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Following devices selected to send the notification for " + deviceType.getName());
|
||||||
|
for (Device device : notifiableDevices) {
|
||||||
|
log.debug(device.getDeviceIdentifier());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
monitoringService.notifyDevices(notifiableDevices);
|
||||||
}
|
}
|
||||||
monitoringService.notifyDevices(notifiableDevices);
|
|
||||||
}
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Monitoring task running completed.");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error occurred while trying to run a task.", e);
|
||||||
}
|
}
|
||||||
if (log.isDebugEnabled()) {
|
} else {
|
||||||
log.debug("Monitoring task running completed.");
|
log.info("No device types registered currently. So did not run the monitoring task.");
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
String msg = "Error occurred while trying to run a task.";
|
|
||||||
log.error(msg, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,8 @@ package org.wso2.carbon.policy.mgt.core.task;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||||
import org.wso2.carbon.ntask.common.TaskException;
|
import org.wso2.carbon.ntask.common.TaskException;
|
||||||
import org.wso2.carbon.ntask.core.TaskInfo;
|
import org.wso2.carbon.ntask.core.TaskInfo;
|
||||||
import org.wso2.carbon.ntask.core.TaskManager;
|
import org.wso2.carbon.ntask.core.TaskManager;
|
||||||
@ -29,7 +31,6 @@ import org.wso2.carbon.ntask.core.service.TaskService;
|
|||||||
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
||||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
||||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
|
||||||
import org.wso2.carbon.ntask.core.TaskInfo.TriggerInfo;
|
import org.wso2.carbon.ntask.core.TaskInfo.TriggerInfo;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -38,63 +39,79 @@ import java.util.Map;
|
|||||||
public class TaskScheduleServiceImpl implements TaskScheduleService {
|
public class TaskScheduleServiceImpl implements TaskScheduleService {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(TaskScheduleServiceImpl.class);
|
private static Log log = LogFactory.getLog(TaskScheduleServiceImpl.class);
|
||||||
|
private PolicyConfiguration policyConfiguration;
|
||||||
|
|
||||||
|
|
||||||
|
public TaskScheduleServiceImpl() {
|
||||||
|
this.policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||||
|
getDeviceManagementConfigRepository().getPolicyConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startTask(int monitoringFrequency) throws PolicyMonitoringTaskException {
|
public void startTask(int monitoringFrequency) throws PolicyMonitoringTaskException {
|
||||||
|
|
||||||
if (monitoringFrequency <= 0) {
|
|
||||||
throw new PolicyMonitoringTaskException("Time interval cannot be 0 or less than 0.");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
|
||||||
taskService.registerTaskType(PolicyManagementConstants.TASK_TYPE);
|
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (policyConfiguration.getMonitoringEnable()) {
|
||||||
log.debug("Monitoring task is started for the tenant id " + tenantId);
|
|
||||||
|
if (monitoringFrequency <= 0) {
|
||||||
|
throw new PolicyMonitoringTaskException("Time interval cannot be 0 or less than 0.");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
||||||
|
taskService.registerTaskType(PolicyManagementConstants.MONITORING_TASK_TYPE);
|
||||||
|
|
||||||
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.TASK_TYPE);
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Monitoring task is started for the tenant id " + tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
TriggerInfo triggerInfo = new TriggerInfo();
|
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
|
||||||
|
|
||||||
triggerInfo.setIntervalMillis(monitoringFrequency);
|
TriggerInfo triggerInfo = new TriggerInfo();
|
||||||
triggerInfo.setRepeatCount(-1);
|
triggerInfo.setIntervalMillis(monitoringFrequency);
|
||||||
|
triggerInfo.setRepeatCount(-1);
|
||||||
|
|
||||||
Map<String, String> properties = new HashMap<>();
|
Map<String, String> properties = new HashMap<>();
|
||||||
properties.put(PolicyManagementConstants.TENANT_ID, String.valueOf(tenantId));
|
properties.put(PolicyManagementConstants.TENANT_ID, String.valueOf(tenantId));
|
||||||
|
|
||||||
String taskName = PolicyManagementConstants.TASK_NAME + "_" + String.valueOf(tenantId);
|
String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId);
|
||||||
|
|
||||||
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.TASK_CLAZZ, properties, triggerInfo);
|
if (!taskManager.isTaskScheduled(taskName)) {
|
||||||
|
|
||||||
taskManager.registerTask(taskInfo);
|
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.MONITORING_TASK_CLAZZ,
|
||||||
taskManager.rescheduleTask(taskInfo.getName());
|
properties, triggerInfo);
|
||||||
|
|
||||||
|
taskManager.registerTask(taskInfo);
|
||||||
|
taskManager.rescheduleTask(taskInfo.getName());
|
||||||
|
} else {
|
||||||
|
throw new PolicyMonitoringTaskException("Monitoring task is already started for this tenant " +
|
||||||
|
tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (TaskException e) {
|
} catch (TaskException e) {
|
||||||
String msg = "Error occurred while creating the task for tenant " + PrivilegedCarbonContext.
|
throw new PolicyMonitoringTaskException("Error occurred while creating the task for tenant " +
|
||||||
getThreadLocalCarbonContext().getTenantId();
|
PrivilegedCarbonContext.
|
||||||
log.error(msg, e);
|
getThreadLocalCarbonContext().getTenantId(), e);
|
||||||
throw new PolicyMonitoringTaskException(msg, e);
|
}
|
||||||
|
} else {
|
||||||
|
throw new PolicyMonitoringTaskException("Policy monitoring is not enabled in the cdm-config.xml.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopTask() throws PolicyMonitoringTaskException {
|
public void stopTask() throws PolicyMonitoringTaskException {
|
||||||
try {
|
try {
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
String taskName = PolicyManagementConstants.TASK_NAME + "_" + String.valueOf(tenantId);
|
String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId);
|
||||||
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
||||||
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.TASK_TYPE);
|
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
|
||||||
taskManager.deleteTask(taskName);
|
taskManager.deleteTask(taskName);
|
||||||
} catch (TaskException e) {
|
} catch (TaskException e) {
|
||||||
String msg = "Error occurred while deleting the task for tenant " + PrivilegedCarbonContext.
|
throw new PolicyMonitoringTaskException("Error occurred while deleting the task for tenant " +
|
||||||
getThreadLocalCarbonContext().getTenantId();
|
PrivilegedCarbonContext.
|
||||||
log.error(msg, e);
|
getThreadLocalCarbonContext().getTenantId(), e);
|
||||||
throw new PolicyMonitoringTaskException(msg, e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,31 +119,34 @@ public class TaskScheduleServiceImpl implements TaskScheduleService {
|
|||||||
public void updateTask(int monitoringFrequency) throws PolicyMonitoringTaskException {
|
public void updateTask(int monitoringFrequency) throws PolicyMonitoringTaskException {
|
||||||
try {
|
try {
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
String taskName = PolicyManagementConstants.TASK_NAME + "_" + String.valueOf(tenantId);
|
String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId);
|
||||||
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
||||||
|
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
|
||||||
|
|
||||||
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.TASK_TYPE);
|
if (taskManager.isTaskScheduled(taskName)) {
|
||||||
|
|
||||||
taskManager.deleteTask(taskName);
|
taskManager.deleteTask(taskName);
|
||||||
|
TriggerInfo triggerInfo = new TriggerInfo();
|
||||||
|
triggerInfo.setIntervalMillis(monitoringFrequency);
|
||||||
|
triggerInfo.setRepeatCount(-1);
|
||||||
|
|
||||||
TriggerInfo triggerInfo = new TriggerInfo();
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
properties.put("tenantId", String.valueOf(tenantId));
|
||||||
|
|
||||||
triggerInfo.setIntervalMillis(monitoringFrequency);
|
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.MONITORING_TASK_CLAZZ, properties,
|
||||||
triggerInfo.setRepeatCount(-1);
|
triggerInfo);
|
||||||
|
|
||||||
Map<String, String> properties = new HashMap<>();
|
taskManager.registerTask(taskInfo);
|
||||||
properties.put("tenantId", String.valueOf(tenantId));
|
taskManager.rescheduleTask(taskInfo.getName());
|
||||||
|
} else {
|
||||||
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.TASK_CLAZZ, properties, triggerInfo);
|
throw new PolicyMonitoringTaskException("Monitoring task has not been started for this tenant " +
|
||||||
|
tenantId + ". Please start the task first.");
|
||||||
taskManager.registerTask(taskInfo);
|
}
|
||||||
taskManager.rescheduleTask(taskInfo.getName());
|
|
||||||
|
|
||||||
} catch (TaskException e) {
|
} catch (TaskException e) {
|
||||||
String msg = "Error occurred while updating the task for tenant " + PrivilegedCarbonContext.
|
throw new PolicyMonitoringTaskException("Error occurred while updating the task for tenant " +
|
||||||
getThreadLocalCarbonContext().getTenantId();
|
PrivilegedCarbonContext.
|
||||||
log.error(msg, e);
|
getThreadLocalCarbonContext().getTenantId(), e);
|
||||||
throw new PolicyMonitoringTaskException(msg, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,14 +32,18 @@ public final class PolicyManagementConstants {
|
|||||||
public static final String BLOCK = "BLOCK";
|
public static final String BLOCK = "BLOCK";
|
||||||
|
|
||||||
|
|
||||||
public static final String TASK_TYPE = "MONITORING_TASK";
|
public static final String MONITORING_TASK_TYPE = "MONITORING_TASK";
|
||||||
public static final String TASK_NAME = "MONITORING";
|
public static final String MONITORING_TASK_NAME = "MONITORING";
|
||||||
public static final String TASK_CLAZZ = "org.wso2.carbon.policy.mgt.core.task.MonitoringTask";
|
public static final String MONITORING_TASK_CLAZZ = "org.wso2.carbon.policy.mgt.core.task.MonitoringTask";
|
||||||
|
|
||||||
|
|
||||||
public static final String DM_CACHE_MANAGER = "DM_CACHE_MANAGER";
|
public static final String DM_CACHE_MANAGER = "DM_CACHE_MANAGER";
|
||||||
public static final String DM_CACHE = "DM_CACHE";
|
public static final String DM_CACHE = "DM_CACHE";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String DELEGATION_TASK_TYPE = "DELEGATION__TASK";
|
||||||
|
public static final String DELEGATION_TASK_NAME = "DELEGATION";
|
||||||
|
public static final String DELEGATION_TASK_CLAZZ = "org.wso2.carbon.policy.mgt.core.enforcement.DelegationTask";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.core.util;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||||
@ -41,6 +42,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -140,9 +142,29 @@ public class PolicyManagerUtil {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean convertIntToBoolean(int x) {
|
||||||
|
|
||||||
public static Cache getCacheManagerImpl(){
|
if (x == 1) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Cache getCacheManagerImpl() {
|
||||||
return Caching.getCacheManagerFactory()
|
return Caching.getCacheManagerFactory()
|
||||||
.getCacheManager(PolicyManagementConstants.DM_CACHE_MANAGER).getCache(PolicyManagementConstants.DM_CACHE);
|
.getCacheManager(PolicyManagementConstants.DM_CACHE_MANAGER).getCache(PolicyManagementConstants
|
||||||
|
.DM_CACHE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static HashMap<Integer, Device> covertDeviceListToMap(List<Device> devices) {
|
||||||
|
|
||||||
|
HashMap<Integer, Device> deviceHashMap = new HashMap<>();
|
||||||
|
for (Device device : devices) {
|
||||||
|
deviceHashMap.put(device.getId(), device);
|
||||||
|
}
|
||||||
|
return deviceHashMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,11 +26,23 @@ import org.testng.annotations.BeforeSuite;
|
|||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
import org.wso2.carbon.base.MultitenantConstants;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
|
import org.wso2.carbon.ntask.common.TaskException;
|
||||||
|
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||||
|
import org.wso2.carbon.ntask.core.service.impl.TaskServiceImpl;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
import org.wso2.carbon.policy.mgt.core.common.DataSourceConfig;
|
import org.wso2.carbon.policy.mgt.core.common.DataSourceConfig;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.services.PolicyMonitoringServiceTest;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.services.SimplePolicyEvaluationTest;
|
||||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@ -50,6 +62,13 @@ public abstract class BasePolicyManagementDAOTest {
|
|||||||
public void setupDataSource() throws Exception {
|
public void setupDataSource() throws Exception {
|
||||||
this.initDatSource();
|
this.initDatSource();
|
||||||
this.initSQLScript();
|
this.initSQLScript();
|
||||||
|
this.initialize();
|
||||||
|
this.initiatePrivilegedCaronContext();
|
||||||
|
DeviceConfigurationManager.getInstance().initConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize() throws TaskException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initDatSource() throws Exception {
|
public void initDatSource() throws Exception {
|
||||||
|
|||||||
@ -29,21 +29,21 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementAdminService;
|
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
|
import org.wso2.carbon.ntask.common.TaskException;
|
||||||
|
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||||
|
import org.wso2.carbon.ntask.core.service.impl.TaskServiceImpl;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||||
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.MonitoringManagerImpl;
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.MonitoringManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.services.PolicyMonitoringServiceTest;
|
import org.wso2.carbon.policy.mgt.core.services.PolicyMonitoringServiceTest;
|
||||||
import org.wso2.carbon.policy.mgt.core.task.MonitoringTask;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -70,20 +70,19 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
|
|||||||
List<Device> devices = service.getAllDevices(ANDROID);
|
List<Device> devices = service.getAllDevices(ANDROID);
|
||||||
|
|
||||||
for (Policy policy : policies) {
|
for (Policy policy : policies) {
|
||||||
log.debug(policy.getPolicyName() + "-----P");
|
log.debug("Policy Name : " + policy.getPolicyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
log.debug(device.getDeviceIdentifier() + " ----- D");
|
log.debug("Device Name : " + device.getDeviceIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
identifier.setType(ANDROID);
|
identifier.setType(ANDROID);
|
||||||
identifier.setId(devices.get(0).getDeviceIdentifier());
|
identifier.setId(devices.get(0).getDeviceIdentifier());
|
||||||
|
|
||||||
PolicyAdministratorPoint administratorPoint = new PolicyAdministratorPointImpl();
|
// PolicyAdministratorPoint administratorPoint = new PolicyAdministratorPointImpl();
|
||||||
|
//
|
||||||
administratorPoint.setPolicyUsed(identifier, policies.get(0));
|
// administratorPoint.setPolicyUsed(identifier, policies.get(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,9 +115,11 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
|
|||||||
|
|
||||||
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
|
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
|
||||||
|
|
||||||
log.debug(policy.getId());
|
if (policy != null) {
|
||||||
log.debug(policy.getPolicyName());
|
log.debug(policy.getId());
|
||||||
log.debug(policy.getCompliance());
|
log.debug(policy.getPolicyName());
|
||||||
|
log.debug(policy.getCompliance());
|
||||||
|
}
|
||||||
|
|
||||||
MonitoringManager monitoringManager = new MonitoringManagerImpl();
|
MonitoringManager monitoringManager = new MonitoringManagerImpl();
|
||||||
|
|
||||||
@ -137,14 +138,13 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
|
|||||||
PolicyComplianceException {
|
PolicyComplianceException {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PolicyMonitoringServiceTest monitoringServiceTest = new PolicyMonitoringServiceTest();
|
PolicyMonitoringServiceTest monitoringServiceTest = new PolicyMonitoringServiceTest();
|
||||||
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(monitoringServiceTest.getType(),
|
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(monitoringServiceTest.getType(),
|
||||||
monitoringServiceTest);
|
monitoringServiceTest);
|
||||||
|
|
||||||
DeviceManagementProviderService adminService = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService adminService = new DeviceManagementProviderServiceImpl();
|
||||||
|
|
||||||
// PolicyManager policyManagerService = new PolicyManagerImpl();
|
// PolicyManager policyManagerService = new PolicyManagerImpl();
|
||||||
|
|
||||||
List<Device> devices = adminService.getAllDevices();
|
List<Device> devices = adminService.getAllDevices();
|
||||||
|
|
||||||
@ -159,14 +159,17 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
|
|||||||
PolicyManager manager = new PolicyManagerImpl();
|
PolicyManager manager = new PolicyManagerImpl();
|
||||||
Policy policy = manager.getAppliedPolicyToDevice(identifier);
|
Policy policy = manager.getAppliedPolicyToDevice(identifier);
|
||||||
|
|
||||||
Object ob = new Object();
|
if(policy != null) {
|
||||||
|
Object ob = new Object();
|
||||||
|
|
||||||
monitoringServiceTest.checkPolicyCompliance(identifier, policy, ob);
|
monitoringServiceTest.checkPolicyCompliance(identifier, policy, ob);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test(dependsOnMethods = ("checkComplianceFromMonitoringService"))
|
@Test(dependsOnMethods = ("checkComplianceFromMonitoringService"))
|
||||||
public void checkCompliance() throws DeviceManagementException, PolicyComplianceException, PolicyManagementException {
|
public void checkCompliance() throws DeviceManagementException, PolicyComplianceException,
|
||||||
|
PolicyManagementException {
|
||||||
|
|
||||||
PolicyMonitoringServiceTest monitoringServiceTest = new PolicyMonitoringServiceTest();
|
PolicyMonitoringServiceTest monitoringServiceTest = new PolicyMonitoringServiceTest();
|
||||||
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(monitoringServiceTest.getType(),
|
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(monitoringServiceTest.getType(),
|
||||||
@ -191,4 +194,5 @@ public class MonitoringTestCase extends BasePolicyManagementDAOTest {
|
|||||||
monitoringManager.checkPolicyCompliance(identifier, ob);
|
monitoringManager.checkPolicyCompliance(identifier, ob);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,12 +32,6 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceIm
|
|||||||
import org.wso2.carbon.policy.mgt.common.*;
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;
|
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;
|
||||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.FeatureManagerImpl;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.ProfileManagerImpl;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.util.*;
|
import org.wso2.carbon.policy.mgt.core.util.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -76,25 +70,16 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
|
|||||||
EnrolmentDAO enrolmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
EnrolmentDAO enrolmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
||||||
DeviceType type = DeviceTypeCreator.getDeviceType();
|
DeviceType type = DeviceTypeCreator.getDeviceType();
|
||||||
devices = DeviceCreator.getDeviceList(type);
|
devices = DeviceCreator.getDeviceList(type);
|
||||||
|
devices.addAll(DeviceCreator.getDeviceList2(type));
|
||||||
|
devices.addAll(DeviceCreator.getDeviceList3(type));
|
||||||
|
devices.addAll(DeviceCreator.getDeviceList4(type));
|
||||||
|
devices.addAll(DeviceCreator.getDeviceList5(type));
|
||||||
|
devices.addAll(DeviceCreator.getDeviceList6(type));
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
int id = deviceDAO.addDevice(type.getId(), device, -1234);
|
int id = deviceDAO.addDevice(type.getId(), device, -1234);
|
||||||
enrolmentDAO.addEnrollment(id, device.getEnrolmentInfo(), -1234);
|
enrolmentDAO.addEnrollment(id, device.getEnrolmentInfo(), -1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Device> devices = deviceDAO.getDevices(-1234);
|
|
||||||
|
|
||||||
log.debug("--- Printing device taken by calling the device dao layer by tenant id.");
|
|
||||||
for (Device device : devices) {
|
|
||||||
log.debug(device.getDeviceIdentifier());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
log.debug("--- Printing device taken by calling the device dao layer by tenant id and device type.");
|
|
||||||
List<Device> devices2 = deviceDAO.getDevices("android", -1234);
|
|
||||||
|
|
||||||
for (Device device : devices2) {
|
|
||||||
log.debug(device.getDeviceIdentifier());
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
|
|
||||||
@ -103,6 +88,7 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
|
|||||||
log.debug("Printing device taken by calling the service layer with device type.");
|
log.debug("Printing device taken by calling the service layer with device type.");
|
||||||
List<Device> devices3 = service.getAllDevices("android");
|
List<Device> devices3 = service.getAllDevices("android");
|
||||||
|
|
||||||
|
log.debug("Device list size ...! " + devices3.size());
|
||||||
for (Device device : devices3) {
|
for (Device device : devices3) {
|
||||||
log.debug(device.getDeviceIdentifier());
|
log.debug(device.getDeviceIdentifier());
|
||||||
}
|
}
|
||||||
@ -112,50 +98,53 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
|
|||||||
@Test(dependsOnMethods = ("addDevice"))
|
@Test(dependsOnMethods = ("addDevice"))
|
||||||
public void addFeatures() throws FeatureManagementException {
|
public void addFeatures() throws FeatureManagementException {
|
||||||
|
|
||||||
FeatureManager featureManager = new FeatureManagerImpl();
|
//This test case was removed because architecture was changed
|
||||||
|
|
||||||
|
// FeatureManager featureManager = new FeatureManagerImpl();
|
||||||
featureList = FeatureCreator.getFeatureList();
|
featureList = FeatureCreator.getFeatureList();
|
||||||
//featureManager.addFeatures(featureList);
|
// featureManager.addFeatures(featureList);
|
||||||
for (Feature feature : featureList) {
|
// for (Feature feature : featureList) {
|
||||||
// featureManager.addFeature(feature);
|
// featureManager.addFeature(feature);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = ("addFeatures"))
|
@Test(dependsOnMethods = ("addFeatures"))
|
||||||
public void addProfileFeatures() throws ProfileManagementException {
|
public void addProfileFeatures() throws ProfileManagementException {
|
||||||
|
|
||||||
ProfileManager profileManager = new ProfileManagerImpl();
|
// ProfileManager profileManager = new ProfileManagerImpl();
|
||||||
profile = ProfileCreator.getProfile(featureList);
|
// Profile profile = ProfileCreator.getProfile2(FeatureCreator.getFeatureList2());
|
||||||
profileManager.addProfile(profile);
|
// profileManager.addProfile(profile);
|
||||||
profileFeatureList = profile.getProfileFeaturesList();
|
// profileFeatureList = profile.getProfileFeaturesList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = ("addProfileFeatures"))
|
@Test(dependsOnMethods = ("addProfileFeatures"))
|
||||||
public void addPolicy() throws PolicyManagementException, ProfileManagementException {
|
public void addPolicy() throws PolicyManagementException, ProfileManagementException {
|
||||||
ProfileManager profileManager = new ProfileManagerImpl();
|
// ProfileManager profileManager = new ProfileManagerImpl();
|
||||||
profile = ProfileCreator.getProfile(featureList);
|
Profile profile = ProfileCreator.getProfile5(FeatureCreator.getFeatureList5());
|
||||||
profileManager.addProfile(profile);
|
// profileManager.addProfile(profile);
|
||||||
PolicyManager policyManager = new PolicyManagerImpl();
|
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
||||||
policy = PolicyCreator.createPolicy(profile);
|
policy = PolicyCreator.createPolicy(profile);
|
||||||
policyManager.addPolicy(policy);
|
policy = pap.addPolicy(policy);
|
||||||
|
pap.activatePolicy(policy.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = ("addPolicy"))
|
@Test(dependsOnMethods = ("addPolicy"))
|
||||||
public void addPolicyToRole() throws PolicyManagementException {
|
public void addPolicyToRole() throws PolicyManagementException {
|
||||||
PolicyManager policyManager = new PolicyManagerImpl();
|
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
||||||
|
|
||||||
List<String> roles = new ArrayList<String>();
|
List<String> roles = new ArrayList<String>();
|
||||||
roles.add("Test_ROLE_01");
|
roles.add("Test_ROLE_01");
|
||||||
roles.add("Test_ROLE_02");
|
roles.add("Test_ROLE_02");
|
||||||
roles.add("Test_ROLE_03");
|
roles.add("Test_ROLE_03");
|
||||||
|
|
||||||
policyManager.addPolicyToRole(roles, policy);
|
pap.addPolicyToRole(roles, policy);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = ("addPolicyToRole"))
|
@Test(dependsOnMethods = ("addPolicyToRole"))
|
||||||
public void addPolicyToDevice() throws PolicyManagementException {
|
public void addPolicyToDevice() throws PolicyManagementException {
|
||||||
PolicyManager policyManager = new PolicyManagerImpl();
|
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
||||||
Device device = DeviceCreator.getSingleDevice();
|
Device device = DeviceCreator.getSingleDevice();
|
||||||
|
|
||||||
List<DeviceIdentifier> deviceIdentifierList = new ArrayList<DeviceIdentifier>();
|
List<DeviceIdentifier> deviceIdentifierList = new ArrayList<DeviceIdentifier>();
|
||||||
@ -164,29 +153,31 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
|
|||||||
deviceIdentifier.setType("android");
|
deviceIdentifier.setType("android");
|
||||||
|
|
||||||
deviceIdentifierList.add(deviceIdentifier);
|
deviceIdentifierList.add(deviceIdentifier);
|
||||||
policyManager.addPolicyToDevice(deviceIdentifierList, policy);
|
pap.addPolicyToDevice(deviceIdentifierList, policy);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = ("addPolicyToDevice"))
|
@Test(dependsOnMethods = ("addPolicyToDevice"))
|
||||||
public void addNewPolicy() throws PolicyManagementException, ProfileManagementException {
|
public void addNewPolicy() throws PolicyManagementException, ProfileManagementException {
|
||||||
ProfileManager profileManager = new ProfileManagerImpl();
|
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
||||||
profile = ProfileCreator.getProfile(featureList);
|
Profile profile = ProfileCreator.getProfile3(FeatureCreator.getFeatureList3());
|
||||||
profileManager.addProfile(profile);
|
//pap.addProfile(profile);
|
||||||
PolicyManager policyManager = new PolicyManagerImpl();
|
// PolicyManager policyManager = new PolicyManagerImpl();
|
||||||
policy = PolicyCreator.createPolicy2(profile);
|
Policy policy = PolicyCreator.createPolicy2(profile);
|
||||||
policyManager.addPolicy(policy);
|
policy = pap.addPolicy(policy);
|
||||||
|
pap.activatePolicy(policy.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test(dependsOnMethods = ("addPolicyToDevice"))
|
@Test(dependsOnMethods = ("addPolicyToDevice"))
|
||||||
public void addThirdPolicy() throws PolicyManagementException, ProfileManagementException {
|
public void addThirdPolicy() throws PolicyManagementException, ProfileManagementException {
|
||||||
ProfileManager profileManager = new ProfileManagerImpl();
|
//ProfileManager profileManager = new ProfileManagerImpl();
|
||||||
profile = ProfileCreator.getProfile(featureList);
|
Profile profile = ProfileCreator.getProfile4(FeatureCreator.getFeatureList4());
|
||||||
profileManager.addProfile(profile);
|
//profileManager.addProfile(profile);
|
||||||
PolicyManager policyManager = new PolicyManagerImpl();
|
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
||||||
policy = PolicyCreator.createPolicy4(profile);
|
Policy policy = PolicyCreator.createPolicy4(profile);
|
||||||
policyManager.addPolicy(policy);
|
policy = pap.addPolicy(policy);
|
||||||
|
pap.activatePolicy(policy.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = ("addNewPolicy"))
|
@Test(dependsOnMethods = ("addNewPolicy"))
|
||||||
@ -278,15 +269,32 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
|
|||||||
|
|
||||||
@Test(dependsOnMethods = ("getRoleRelatedPolicy"))
|
@Test(dependsOnMethods = ("getRoleRelatedPolicy"))
|
||||||
public void addSecondPolicy() throws PolicyManagementException, ProfileManagementException {
|
public void addSecondPolicy() throws PolicyManagementException, ProfileManagementException {
|
||||||
ProfileManager profileManager = new ProfileManagerImpl();
|
// ProfileManager profileManager = new ProfileManagerImpl();
|
||||||
profile = ProfileCreator.getProfile(featureList);
|
Profile profile = ProfileCreator.getProfile(FeatureCreator.getFeatureList());
|
||||||
profileManager.addProfile(profile);
|
//profileManager.addProfile(profile);
|
||||||
PolicyManager policyManager = new PolicyManagerImpl();
|
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
||||||
policy = PolicyCreator.createPolicy3(profile);
|
Policy policy = PolicyCreator.createPolicy3(profile);
|
||||||
policyManager.addPolicy(policy);
|
policy = pap.addPolicy(policy);
|
||||||
|
pap.activatePolicy(policy.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = ("getDeviceTypeRelatedPolicy"))
|
@Test(dependsOnMethods = ("addSecondPolicy"))
|
||||||
|
public void updatedPolicy() throws PolicyManagementException {
|
||||||
|
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
||||||
|
Profile profile = ProfileCreator.getProfile3(FeatureCreator.getFeatureList3());
|
||||||
|
Policy policy = PolicyCreator.createPolicy3(profile);
|
||||||
|
policy.setPolicyName("Policy_05");
|
||||||
|
policy = pap.addPolicy(policy);
|
||||||
|
pap.activatePolicy(policy.getId());
|
||||||
|
List<String> users = new ArrayList<>();
|
||||||
|
users.add("Udara");
|
||||||
|
users.add("Dileesha");
|
||||||
|
policy.setUsers(users);
|
||||||
|
pap.updatePolicy(policy);
|
||||||
|
pap.activatePolicy(policy.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = ("updatedPolicy"))
|
||||||
public void getRoleRelatedPolicySecondTime() throws PolicyManagementException {
|
public void getRoleRelatedPolicySecondTime() throws PolicyManagementException {
|
||||||
|
|
||||||
PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl();
|
PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl();
|
||||||
@ -348,7 +356,7 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
|
|||||||
PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl();
|
PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl();
|
||||||
policyAdministratorPoint.deletePolicy(1);
|
policyAdministratorPoint.deletePolicy(1);
|
||||||
|
|
||||||
log.debug("First policy deleted.");
|
log.debug("First policy deleted..!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -362,13 +370,14 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
|
|||||||
List<Device> devices = service.getAllDevices("android");
|
List<Device> devices = service.getAllDevices("android");
|
||||||
|
|
||||||
for (Policy policy : policies) {
|
for (Policy policy : policies) {
|
||||||
log.debug(policy.getPolicyName() + "-----P");
|
log.debug("Policy Name : " + policy.getPolicyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
log.debug(device.getDeviceIdentifier() + " ----- D");
|
log.debug("Device Name : " + device.getDeviceIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.policy.mgt.core;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||||
|
import org.wso2.carbon.ntask.common.TaskException;
|
||||||
|
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||||
|
import org.wso2.carbon.ntask.core.service.impl.TaskServiceImpl;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.enforcement.DelegationTask;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.services.SimplePolicyEvaluationTest;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
|
||||||
|
|
||||||
|
private static final String ANDROID = "android";
|
||||||
|
private static final Log log = LogFactory.getLog(PolicyEvaluationTestCase.class);
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Override
|
||||||
|
public void init() throws Exception {
|
||||||
|
|
||||||
|
PolicyEvaluationPoint evaluationPoint = new SimplePolicyEvaluationTest();
|
||||||
|
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(evaluationPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void activatePolicies() throws PolicyManagementException, TaskException {
|
||||||
|
PolicyManagerService policyManagerService = new PolicyManagerServiceImpl();
|
||||||
|
PolicyAdministratorPoint administratorPoint = policyManagerService.getPAP();
|
||||||
|
|
||||||
|
List<Policy> policies = policyManagerService.getPolicies(ANDROID);
|
||||||
|
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
log.debug("Policy status : " + policy.getPolicyName() + " - " + policy.isActive() + " - " + policy
|
||||||
|
.isUpdated() + " Policy id : " + policy.getId());
|
||||||
|
|
||||||
|
if (!policy.isActive()) {
|
||||||
|
administratorPoint.activatePolicy(policy.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// This cannot be called due to task service cannot be started from the
|
||||||
|
//administratorPoint.publishChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = ("activatePolicies"))
|
||||||
|
public void getEffectivePolicy() throws DeviceManagementException, PolicyEvaluationException {
|
||||||
|
|
||||||
|
log.debug("Getting effective policy for device started ..........");
|
||||||
|
|
||||||
|
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||||
|
List<Device> devices = service.getAllDevices(ANDROID);
|
||||||
|
|
||||||
|
PolicyEvaluationPoint evaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
|
||||||
|
|
||||||
|
for (Device device : devices) {
|
||||||
|
DeviceIdentifier identifier = new DeviceIdentifier();
|
||||||
|
identifier.setType(device.getType());
|
||||||
|
identifier.setId(device.getDeviceIdentifier());
|
||||||
|
Policy policy = evaluationPoint.getEffectivePolicy(identifier);
|
||||||
|
|
||||||
|
if (policy != null) {
|
||||||
|
log.debug("Name of the policy applied to device is " + policy.getPolicyName());
|
||||||
|
} else {
|
||||||
|
log.debug("No policy is applied to device.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = ("getEffectivePolicy"))
|
||||||
|
public void updatePriorities() throws PolicyManagementException, TaskException {
|
||||||
|
|
||||||
|
PolicyManagerService policyManagerService = new PolicyManagerServiceImpl();
|
||||||
|
PolicyAdministratorPoint administratorPoint = policyManagerService.getPAP();
|
||||||
|
|
||||||
|
List<Policy> policies = administratorPoint.getPolicies();
|
||||||
|
|
||||||
|
log.debug("Re-enforcing policy started...!");
|
||||||
|
|
||||||
|
int sixe = policies.size();
|
||||||
|
|
||||||
|
sortPolicies(policies);
|
||||||
|
int x = 0;
|
||||||
|
for (Policy policy : policies) {
|
||||||
|
policy.setPriorityId(sixe - x);
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
administratorPoint.updatePolicyPriorities(policies);
|
||||||
|
// administratorPoint.publishChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = ("updatePriorities"))
|
||||||
|
public void checkDelegations() {
|
||||||
|
|
||||||
|
log.debug("Delegation methods calls started because tasks cannot be started due to osgi constraints.....!");
|
||||||
|
|
||||||
|
DelegationTask delegationTask = new DelegationTask();
|
||||||
|
delegationTask.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sortPolicies(List<Policy> policyList) {
|
||||||
|
Collections.sort(policyList);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, 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 org.wso2.carbon.policy.mgt.core.services;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SimplePolicyEvaluationTest implements PolicyEvaluationPoint {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(SimplePolicyEvaluationTest.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
|
||||||
|
Policy policy = new Policy();
|
||||||
|
|
||||||
|
List<Policy> policyList;
|
||||||
|
PolicyAdministratorPoint policyAdministratorPoint;
|
||||||
|
PolicyInformationPoint policyInformationPoint;
|
||||||
|
PolicyManagerService policyManagerService = new PolicyManagerServiceImpl();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (policyManagerService != null) {
|
||||||
|
|
||||||
|
policyInformationPoint = policyManagerService.getPIP();
|
||||||
|
PIPDevice pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier);
|
||||||
|
policyList = policyInformationPoint.getRelatedPolicies(pipDevice);
|
||||||
|
|
||||||
|
for(Policy pol : policyList) {
|
||||||
|
log.debug("Policy used in evaluation - Name : " + pol.getPolicyName() );
|
||||||
|
}
|
||||||
|
|
||||||
|
sortPolicies(policyList);
|
||||||
|
if(!policyList.isEmpty()) {
|
||||||
|
policy = policyList.get(0);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
policyAdministratorPoint = policyManagerService.getPAP();
|
||||||
|
policyAdministratorPoint.setPolicyUsed(deviceIdentifier, policy);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String msg = "Error occurred when retrieving the policy related data from policy management service.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyEvaluationException(msg, e);
|
||||||
|
}
|
||||||
|
return policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sortPolicies(List<Policy> policyList) throws PolicyEvaluationException {
|
||||||
|
Collections.sort(policyList);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -27,10 +27,12 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DeviceCreator {
|
public class DeviceCreator {
|
||||||
|
|
||||||
private static List<Device> deviceList = new ArrayList<Device>();
|
//private static ;
|
||||||
|
|
||||||
public static List<Device> getDeviceList(DeviceType deviceType) {
|
public static List<Device> getDeviceList(DeviceType deviceType) {
|
||||||
|
|
||||||
|
List<Device> deviceList = new ArrayList<Device>();
|
||||||
|
|
||||||
Device device = new Device();
|
Device device = new Device();
|
||||||
device.setId(1);
|
device.setId(1);
|
||||||
device.setType(deviceType.getName());
|
device.setType(deviceType.getName());
|
||||||
@ -42,25 +44,131 @@ public class DeviceCreator {
|
|||||||
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
device.setEnrolmentInfo(enrolmentInfo);
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
|
||||||
Device device1 = new Device();
|
// Device device1 = new Device();
|
||||||
device1.setId(1);
|
// device1.setId(2);
|
||||||
device1.setType(deviceType.getName());
|
// device1.setType(deviceType.getName());
|
||||||
device1.setName("Nexus 5");
|
// device1.setName("Nexus 5");
|
||||||
device1.setDeviceIdentifier("def456");
|
// device1.setDeviceIdentifier("def456");
|
||||||
EnrolmentInfo enrolmentInfo1 = new EnrolmentInfo();
|
// EnrolmentInfo enrolmentInfo1 = new EnrolmentInfo();
|
||||||
enrolmentInfo1.setOwner("Manoj");
|
// enrolmentInfo1.setOwner("Manoj");
|
||||||
enrolmentInfo1.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
// enrolmentInfo1.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
enrolmentInfo1.setStatus(EnrolmentInfo.Status.ACTIVE);
|
// enrolmentInfo1.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
device1.setEnrolmentInfo(enrolmentInfo);
|
// device1.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
|
||||||
deviceList.add(device);
|
deviceList.add(device);
|
||||||
// deviceList.add(device2);
|
// deviceList.add(device1);
|
||||||
|
|
||||||
return deviceList;
|
return deviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<Device> getDeviceList2 (DeviceType deviceType) {
|
||||||
|
List<Device> deviceList = new ArrayList<Device>();
|
||||||
|
|
||||||
|
Device device = new Device();
|
||||||
|
device.setId(2);
|
||||||
|
device.setType(deviceType.getName());
|
||||||
|
device.setName("Apple 5S");
|
||||||
|
device.setDeviceIdentifier("def123");
|
||||||
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setOwner("Dilshan");
|
||||||
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
|
||||||
|
deviceList.add(device);
|
||||||
|
return deviceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Device> getDeviceList3 (DeviceType deviceType) {
|
||||||
|
List<Device> deviceList = new ArrayList<Device>();
|
||||||
|
|
||||||
|
Device device = new Device();
|
||||||
|
device.setId(3);
|
||||||
|
device.setType(deviceType.getName());
|
||||||
|
device.setName("Apple 6 Large");
|
||||||
|
device.setDeviceIdentifier("xxxx123");
|
||||||
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setOwner("Harshan");
|
||||||
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
|
||||||
|
deviceList.add(device);
|
||||||
|
return deviceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Device> getDeviceList4 (DeviceType deviceType) {
|
||||||
|
List<Device> deviceList = new ArrayList<Device>();
|
||||||
|
|
||||||
|
Device device = new Device();
|
||||||
|
device.setId(4);
|
||||||
|
device.setType(deviceType.getName());
|
||||||
|
device.setName("HTC M");
|
||||||
|
device.setDeviceIdentifier("ppp456");
|
||||||
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setOwner("Dilan");
|
||||||
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
|
||||||
|
deviceList.add(device);
|
||||||
|
return deviceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Device> getDeviceList5 (DeviceType deviceType) {
|
||||||
|
List<Device> deviceList = new ArrayList<Device>();
|
||||||
|
|
||||||
|
Device device = new Device();
|
||||||
|
device.setId(5);
|
||||||
|
device.setType(deviceType.getName());
|
||||||
|
device.setName("Sony Experia L");
|
||||||
|
device.setDeviceIdentifier("ssss123");
|
||||||
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setOwner("Milan");
|
||||||
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
|
||||||
|
deviceList.add(device);
|
||||||
|
return deviceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<Device> getDeviceList6 (DeviceType deviceType) {
|
||||||
|
List<Device> deviceList = new ArrayList<Device>();
|
||||||
|
|
||||||
|
Device device = new Device();
|
||||||
|
device.setId(6);
|
||||||
|
device.setType(deviceType.getName());
|
||||||
|
device.setName("Alcatel RTS");
|
||||||
|
device.setDeviceIdentifier("ttt123");
|
||||||
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setOwner("Dileesha");
|
||||||
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
|
||||||
|
deviceList.add(device);
|
||||||
|
return deviceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Device getSingleDevice() {
|
public static Device getSingleDevice() {
|
||||||
return deviceList.get(0);
|
|
||||||
|
Device device = new Device();
|
||||||
|
device.setId(1);
|
||||||
|
device.setType("android");
|
||||||
|
device.setName("Galaxy S6");
|
||||||
|
device.setDeviceIdentifier("abc123");
|
||||||
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
||||||
|
enrolmentInfo.setOwner("Geeth");
|
||||||
|
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
|
||||||
|
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
|
device.setEnrolmentInfo(enrolmentInfo);
|
||||||
|
|
||||||
|
|
||||||
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,10 +21,15 @@ package org.wso2.carbon.policy.mgt.core.util;
|
|||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FeatureCreator {
|
public class FeatureCreator {
|
||||||
|
|
||||||
|
private static List<Feature> featureList = new ArrayList<Feature>();
|
||||||
|
|
||||||
|
private static HashMap<Integer, Feature> featureMap = new HashMap<>();
|
||||||
|
|
||||||
public static List<Feature> getFeatureList() {
|
public static List<Feature> getFeatureList() {
|
||||||
|
|
||||||
Feature feature1 = new Feature();
|
Feature feature1 = new Feature();
|
||||||
@ -119,7 +124,7 @@ public class FeatureCreator {
|
|||||||
feature11.setDeviceType("android");
|
feature11.setDeviceType("android");
|
||||||
|
|
||||||
|
|
||||||
List<Feature> featureList = new ArrayList<Feature>();
|
List<Feature> featureList2 = new ArrayList<Feature>();
|
||||||
featureList.add(feature1);
|
featureList.add(feature1);
|
||||||
featureList.add(feature2);
|
featureList.add(feature2);
|
||||||
featureList.add(feature3);
|
featureList.add(feature3);
|
||||||
@ -132,6 +137,70 @@ public class FeatureCreator {
|
|||||||
featureList.add(feature10);
|
featureList.add(feature10);
|
||||||
featureList.add(feature11);
|
featureList.add(feature11);
|
||||||
|
|
||||||
return featureList;
|
featureList2.add(feature1);
|
||||||
|
featureList2.add(feature2);
|
||||||
|
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
for (Feature feature : featureList) {
|
||||||
|
featureMap.put(i, feature);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return featureList2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Feature> getFeatureList2() {
|
||||||
|
List<Feature> featureList2 = new ArrayList<Feature>();
|
||||||
|
|
||||||
|
featureList2.add(featureMap.get(3));
|
||||||
|
featureList2.add(featureMap.get(4));
|
||||||
|
|
||||||
|
return featureList2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Feature> getFeatureList3() {
|
||||||
|
List<Feature> featureList2 = new ArrayList<Feature>();
|
||||||
|
|
||||||
|
featureList2.add(featureMap.get(5));
|
||||||
|
featureList2.add(featureMap.get(6));
|
||||||
|
featureList2.add(featureMap.get(7));
|
||||||
|
|
||||||
|
return featureList2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Feature> getFeatureList4() {
|
||||||
|
List<Feature> featureList2 = new ArrayList<Feature>();
|
||||||
|
|
||||||
|
featureList2.add(featureMap.get(7));
|
||||||
|
featureList2.add(featureMap.get(8));
|
||||||
|
featureList2.add(featureMap.get(9));
|
||||||
|
|
||||||
|
return featureList2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Feature> getFeatureList5() {
|
||||||
|
List<Feature> featureList2 = new ArrayList<Feature>();
|
||||||
|
|
||||||
|
featureList2.add(featureMap.get(9));
|
||||||
|
featureList2.add(featureMap.get(10));
|
||||||
|
featureList2.add(featureMap.get(11));
|
||||||
|
featureList2.add(featureMap.get(3));
|
||||||
|
|
||||||
|
return featureList2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<Feature> getFeatureList6() {
|
||||||
|
List<Feature> featureList2 = new ArrayList<Feature>();
|
||||||
|
|
||||||
|
featureList2.add(featureMap.get(3));
|
||||||
|
featureList2.add(featureMap.get(8));
|
||||||
|
featureList2.add(featureMap.get(9));
|
||||||
|
featureList2.add(featureMap.get(5));
|
||||||
|
|
||||||
|
return featureList2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -50,7 +50,7 @@ public class PolicyCreator {
|
|||||||
policy.setPolicyName("Test_Policy_02");
|
policy.setPolicyName("Test_Policy_02");
|
||||||
policy.setGeneric(true);
|
policy.setGeneric(true);
|
||||||
policy.setProfile(profile);
|
policy.setProfile(profile);
|
||||||
policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
|
policy.setDevices(DeviceCreator.getDeviceList2(DeviceTypeCreator.getDeviceType()));
|
||||||
|
|
||||||
policy.setCompliance("ENFORCE");
|
policy.setCompliance("ENFORCE");
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ public class PolicyCreator {
|
|||||||
policy.setPolicyName("Test_Policy_03");
|
policy.setPolicyName("Test_Policy_03");
|
||||||
policy.setGeneric(true);
|
policy.setGeneric(true);
|
||||||
policy.setProfile(profile);
|
policy.setProfile(profile);
|
||||||
policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
|
policy.setDevices(DeviceCreator.getDeviceList3(DeviceTypeCreator.getDeviceType()));
|
||||||
|
|
||||||
List<String> roles = new ArrayList<String>();
|
List<String> roles = new ArrayList<String>();
|
||||||
roles.add("Role_01");
|
roles.add("Role_01");
|
||||||
@ -138,7 +138,7 @@ public class PolicyCreator {
|
|||||||
policy.setPolicyName("Test_Policy_04");
|
policy.setPolicyName("Test_Policy_04");
|
||||||
policy.setGeneric(true);
|
policy.setGeneric(true);
|
||||||
policy.setProfile(profile);
|
policy.setProfile(profile);
|
||||||
policy.setDevices(DeviceCreator.getDeviceList(DeviceTypeCreator.getDeviceType()));
|
policy.setDevices(DeviceCreator.getDeviceList4(DeviceTypeCreator.getDeviceType()));
|
||||||
|
|
||||||
policy.setCompliance("MONITOR");
|
policy.setCompliance("MONITOR");
|
||||||
policy.setOwnershipType("BYOD");
|
policy.setOwnershipType("BYOD");
|
||||||
|
|||||||
@ -41,4 +41,66 @@ public class ProfileCreator {
|
|||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Profile getProfile2(List<Feature> features) {
|
||||||
|
Profile profile = new Profile();
|
||||||
|
DeviceType deviceType = new DeviceType();
|
||||||
|
|
||||||
|
deviceType.setId(1);
|
||||||
|
deviceType.setName("android");
|
||||||
|
|
||||||
|
profile.setProfileFeaturesList(ProfileFeatureCreator.getProfileFeature(features));
|
||||||
|
profile.setProfileName("Test Profile 2");
|
||||||
|
profile.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||||
|
profile.setDeviceType(deviceType);
|
||||||
|
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Profile getProfile3(List<Feature> features) {
|
||||||
|
Profile profile = new Profile();
|
||||||
|
DeviceType deviceType = new DeviceType();
|
||||||
|
|
||||||
|
deviceType.setId(1);
|
||||||
|
deviceType.setName("android");
|
||||||
|
|
||||||
|
profile.setProfileFeaturesList(ProfileFeatureCreator.getProfileFeature(features));
|
||||||
|
profile.setProfileName("Test Profile 3");
|
||||||
|
profile.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||||
|
profile.setDeviceType(deviceType);
|
||||||
|
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Profile getProfile4(List<Feature> features) {
|
||||||
|
Profile profile = new Profile();
|
||||||
|
DeviceType deviceType = new DeviceType();
|
||||||
|
|
||||||
|
deviceType.setId(1);
|
||||||
|
deviceType.setName("android");
|
||||||
|
|
||||||
|
profile.setProfileFeaturesList(ProfileFeatureCreator.getProfileFeature(features));
|
||||||
|
profile.setProfileName("Test Profile 4");
|
||||||
|
profile.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||||
|
profile.setDeviceType(deviceType);
|
||||||
|
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Profile getProfile5(List<Feature> features) {
|
||||||
|
Profile profile = new Profile();
|
||||||
|
DeviceType deviceType = new DeviceType();
|
||||||
|
|
||||||
|
deviceType.setId(1);
|
||||||
|
deviceType.setName("android");
|
||||||
|
|
||||||
|
profile.setProfileFeaturesList(ProfileFeatureCreator.getProfileFeature(features));
|
||||||
|
profile.setProfileName("Test Profile 5");
|
||||||
|
profile.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
|
||||||
|
profile.setDeviceType(deviceType);
|
||||||
|
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,48 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2015, 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<DeviceMgtConfiguration>
|
||||||
|
<ManagementRepository>
|
||||||
|
<DataSourceConfiguration>
|
||||||
|
<JndiLookupDefinition>
|
||||||
|
<Name>jdbc/DM_DS</Name>
|
||||||
|
</JndiLookupDefinition>
|
||||||
|
</DataSourceConfiguration>
|
||||||
|
<EmailClientConfiguration>
|
||||||
|
<minimumThread>8</minimumThread>
|
||||||
|
<maximumThread>100</maximumThread>
|
||||||
|
<keepAliveTime>20</keepAliveTime>
|
||||||
|
<ThreadQueueCapacity>1000</ThreadQueueCapacity>
|
||||||
|
</EmailClientConfiguration>
|
||||||
|
<IdentityConfiguration>
|
||||||
|
<ServerUrl>https://localhost:9443</ServerUrl>
|
||||||
|
<AdminUsername>admin</AdminUsername>
|
||||||
|
<AdminPassword>admin</AdminPassword>
|
||||||
|
</IdentityConfiguration>
|
||||||
|
<PolicyConfiguration>
|
||||||
|
<monitoringClass>org.wso2.carbon.policy.mgt</monitoringClass>
|
||||||
|
<monitoringEnable>true</monitoringEnable>
|
||||||
|
<monitoringFrequency>60000</monitoringFrequency>
|
||||||
|
<maxRetries>5</maxRetries>
|
||||||
|
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
|
||||||
|
<minRetriesToMarkInactive>20</minRetriesToMarkInactive>
|
||||||
|
</PolicyConfiguration>
|
||||||
|
</ManagementRepository>
|
||||||
|
</DeviceMgtConfiguration>
|
||||||
|
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
<tasks-configuration xmlns:svns="http://org.wso2.securevault/configuration">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The currently running server mode; possible values are:-
|
||||||
|
STANDALONE, CLUSTERED, REMOTE, AUTO.
|
||||||
|
In AUTO mode, the server startup checks whether clustering is enabled in the system,
|
||||||
|
if so, CLUSTERED mode will be used, or else, the the server mode will be STANDALONE.
|
||||||
|
-->
|
||||||
|
<taskServerMode>AUTO</taskServerMode>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
To be used in CLUSTERED mode to notify how many servers are there in
|
||||||
|
the task server cluster, the servers wait till this amount of servers
|
||||||
|
are activated before the tasks are scheduled -->
|
||||||
|
<taskServerCount>2</taskServerCount>
|
||||||
|
|
||||||
|
<!-- The default location resolver configuration -->
|
||||||
|
<defaultLocationResolver>
|
||||||
|
<locationResolverClass>org.wso2.carbon.ntask.core.impl.RoundRobinTaskLocationResolver</locationResolverClass>
|
||||||
|
</defaultLocationResolver>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
if task-type-pattern matches and task-name-pattern matches, check existing addresses of address-pattern,
|
||||||
|
and if addresses exist, select address in round-robin fashion, if not move onto next rule in sequence.
|
||||||
|
<property name="rule-[order]">[task-type-pattern],[task-name-pattern],[address-pattern]</property>
|
||||||
|
-->
|
||||||
|
<!--defaultLocationResolver>
|
||||||
|
<locationResolverClass>org.wso2.carbon.ntask.core.impl.RuleBasedLocationResolver</locationResolverClass>
|
||||||
|
<properties>
|
||||||
|
<property name="rule-1">HIVE_TASK,.*,192.168.2.*</property>
|
||||||
|
<property name="rule-5">.*,.*,.*</property>
|
||||||
|
</properties>
|
||||||
|
</defaultLocationResolver-->
|
||||||
|
|
||||||
|
<!-- The address to which the remote task server should dispatch the trigger messages to,
|
||||||
|
usually this would be an endpoint to a load balancer -->
|
||||||
|
<taskClientDispatchAddress>https://localhost:9448</taskClientDispatchAddress>
|
||||||
|
|
||||||
|
<!-- The address of the remote task server -->
|
||||||
|
<remoteServerAddress>https://localhost:9443</remoteServerAddress>
|
||||||
|
|
||||||
|
<!-- The username to authenticate to the remote task server -->
|
||||||
|
<remoteServerUsername>admin</remoteServerUsername>
|
||||||
|
|
||||||
|
<!-- The password to authenticate to the remote task server -->
|
||||||
|
<remoteServerPassword>admin</remoteServerPassword>
|
||||||
|
|
||||||
|
<!-- Below contain a sample to be used when using with secure vault -->
|
||||||
|
<!--remoteServerPassword svns:secretAlias="remote.task.server.password"></remoteServerPassword-->
|
||||||
|
|
||||||
|
</tasks-configuration>
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
<Notifications>
|
||||||
|
<NotificationMessage type="enrol">
|
||||||
|
<Subject>Enroll your Device with WSO2 MDM</Subject>
|
||||||
|
<Header>Dear {first-name},</Header>
|
||||||
|
<Body>
|
||||||
|
You have been registered to the WSO2 MDM. Below is the link to enroll.
|
||||||
|
</Body>
|
||||||
|
<Url>{downloadUrl}</Url>
|
||||||
|
<Footer1>
|
||||||
|
Best Regards,
|
||||||
|
</Footer1>
|
||||||
|
<Footer2>
|
||||||
|
WSO2 MDM Team.
|
||||||
|
</Footer2>
|
||||||
|
<Footer3>
|
||||||
|
http://www.wso2.com
|
||||||
|
</Footer3>
|
||||||
|
</NotificationMessage>
|
||||||
|
<NotificationMessage type="userRegistration">
|
||||||
|
<Subject>Enroll your Device with WSO2 MDM</Subject>
|
||||||
|
<Header>Dear {first-name},</Header>
|
||||||
|
<Body>
|
||||||
|
You have been registered to WSO2 MDM with following credentials.
|
||||||
|
Username: {user-name}
|
||||||
|
Password: {password}
|
||||||
|
Below is the link to enroll.
|
||||||
|
</Body>
|
||||||
|
<Url>{downloadUrl}</Url>
|
||||||
|
<Footer1>
|
||||||
|
Best Regards,
|
||||||
|
</Footer1>
|
||||||
|
<Footer2>
|
||||||
|
WSO2 MDM Team.
|
||||||
|
</Footer2>
|
||||||
|
<Footer3>
|
||||||
|
http://www.wso2.com
|
||||||
|
</Footer3>
|
||||||
|
</NotificationMessage>
|
||||||
|
</Notifications>
|
||||||
@ -33,8 +33,8 @@
|
|||||||
|
|
||||||
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
|
<!--<Url>jdbc:mysql://localhost:3306/WSO2CDM</Url>-->
|
||||||
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
|
<!--<DriverClassName>com.mysql.jdbc.Driver</DriverClassName>-->
|
||||||
<!--<userName>root</userName>-->
|
<!--<User>root</User>-->
|
||||||
<!--<pwd></pwd>-->
|
<!--<Password></Password>-->
|
||||||
|
|
||||||
|
|
||||||
</DataSourceConfig>
|
</DataSourceConfig>
|
||||||
|
|||||||
@ -109,7 +109,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATIONS (
|
|||||||
APPLICATIONS BLOB DEFAULT NULL,
|
APPLICATIONS BLOB DEFAULT NULL,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_applications_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
CONSTRAINT fk_dm_device_applications_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
--- POLICY RELATED TABLES ----
|
--- POLICY RELATED TABLES ----
|
||||||
@ -143,7 +143,9 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
|
|||||||
PROFILE_ID INT(11) NOT NULL ,
|
PROFILE_ID INT(11) NOT NULL ,
|
||||||
OWNERSHIP_TYPE VARCHAR(45) NULL,
|
OWNERSHIP_TYPE VARCHAR(45) NULL,
|
||||||
COMPLIANCE VARCHAR(100) NULL,
|
COMPLIANCE VARCHAR(100) NULL,
|
||||||
PRIORITY INT NOT NULL ,
|
PRIORITY INT NOT NULL,
|
||||||
|
ACTIVE INT(2) NOT NULL,
|
||||||
|
UPDATED INT(1) NULL,
|
||||||
PRIMARY KEY (ID) ,
|
PRIMARY KEY (ID) ,
|
||||||
CONSTRAINT FK_DM_PROFILE_DM_POLICY
|
CONSTRAINT FK_DM_PROFILE_DM_POLICY
|
||||||
FOREIGN KEY (PROFILE_ID )
|
FOREIGN KEY (PROFILE_ID )
|
||||||
@ -158,6 +160,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
||||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||||
DEVICE_ID INT(11) NOT NULL ,
|
DEVICE_ID INT(11) NOT NULL ,
|
||||||
|
ENROLMENT_ID INT(11) NOT NULL,
|
||||||
|
DEVICE BLOB NOT NULL,
|
||||||
POLICY_ID INT(11) NOT NULL ,
|
POLICY_ID INT(11) NOT NULL ,
|
||||||
PRIMARY KEY (ID) ,
|
PRIMARY KEY (ID) ,
|
||||||
CONSTRAINT FK_POLICY_DEVICE_POLICY
|
CONSTRAINT FK_POLICY_DEVICE_POLICY
|
||||||
@ -243,8 +247,9 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
|
|||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
|
||||||
ID INT NOT NULL AUTO_INCREMENT ,
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
DEVICE_ID INT NOT NULL ,
|
DEVICE_ID INT NOT NULL,
|
||||||
|
ENROLMENT_ID INT(11) NOT NULL,
|
||||||
POLICY_ID INT NOT NULL ,
|
POLICY_ID INT NOT NULL ,
|
||||||
POLICY_CONTENT BLOB NULL ,
|
POLICY_CONTENT BLOB NULL ,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
@ -314,6 +319,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
|
|||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
|
||||||
ID INT NOT NULL AUTO_INCREMENT,
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
DEVICE_ID INT NOT NULL,
|
DEVICE_ID INT NOT NULL,
|
||||||
|
ENROLMENT_ID INT(11) NOT NULL,
|
||||||
POLICY_ID INT NOT NULL,
|
POLICY_ID INT NOT NULL,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
STATUS INT NULL,
|
STATUS INT NULL,
|
||||||
@ -345,6 +351,14 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
|
||||||
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
|
POLICY_ID INT NOT NULL,
|
||||||
|
DEVICE_TYPE_ID INT NOT NULL,
|
||||||
|
TENANT_ID INT(11) NOT NULL,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
|
);
|
||||||
|
|
||||||
-- POLICY RELATED TABLES FINISHED --
|
-- POLICY RELATED TABLES FINISHED --
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
<classes>
|
<classes>
|
||||||
<class name="org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase"/>
|
<class name="org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase"/>
|
||||||
<class name="org.wso2.carbon.policy.mgt.core.MonitoringTestCase" />
|
<class name="org.wso2.carbon.policy.mgt.core.MonitoringTestCase" />
|
||||||
|
<class name="org.wso2.carbon.policy.mgt.core.PolicyEvaluationTestCase" />
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
||||||
@ -0,0 +1,156 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2015, 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>certificate-mgt-feature</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.certificate.mgt.server.feature</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<name>WSO2 Carbon - Certificate Management Server Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
<description>This feature contains the core bundles required for back-end Certificate Management functionality
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle.wso2</groupId>
|
||||||
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle.wso2</groupId>
|
||||||
|
<artifactId>bcpkix-jdk15on</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle.wso2</groupId>
|
||||||
|
<artifactId>bcmail-jdk15on</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.jscep.wso2</groupId>
|
||||||
|
<artifactId>jscep</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io.wso2</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang.wso2</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec.wso2</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-resources</id>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>src/main/resources</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>build.properties</include>
|
||||||
|
<include>p2.inf</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.wso2.maven</groupId>
|
||||||
|
<artifactId>carbon-p2-plugin</artifactId>
|
||||||
|
<version>${carbon.p2.plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>p2-feature-generation</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>p2-feature-gen</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<id>org.wso2.carbon.certificate.mgt.server</id>
|
||||||
|
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||||
|
<adviceFile>
|
||||||
|
<properties>
|
||||||
|
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||||
|
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||||
|
</properties>
|
||||||
|
</adviceFile>
|
||||||
|
<bundles>
|
||||||
|
<bundleDef>
|
||||||
|
org.wso2.carbon.devicemgt:org.wso2.carbon.certificate.mgt.core:${carbon.device.mgt.version}
|
||||||
|
</bundleDef>
|
||||||
|
<bundleDef>
|
||||||
|
org.bouncycastle.wso2:bcprov-jdk15on:${bcprov.wso2.version}
|
||||||
|
</bundleDef>
|
||||||
|
<bundleDef>
|
||||||
|
org.bouncycastle.wso2:bcpkix-jdk15on:${bcpkix.wso2.version}
|
||||||
|
</bundleDef>
|
||||||
|
<bundleDef>
|
||||||
|
org.bouncycastle.wso2:bcmail-jdk15on:${bcmail.wso2.version}
|
||||||
|
</bundleDef>
|
||||||
|
<bundleDef>
|
||||||
|
com.google.code.jscep.wso2:jscep:${jscep.version}
|
||||||
|
</bundleDef>
|
||||||
|
<bundleDef>
|
||||||
|
commons-io.wso2:commons-io:${version.commons.io}
|
||||||
|
</bundleDef>
|
||||||
|
<bundleDef>
|
||||||
|
commons-lang.wso2:commons-lang:${version.commons.lang}
|
||||||
|
</bundleDef>
|
||||||
|
<bundleDef>
|
||||||
|
commons-codec.wso2:commons-codec:${version.commons.codec}
|
||||||
|
</bundleDef>
|
||||||
|
</bundles>
|
||||||
|
<importFeatures>
|
||||||
|
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
|
||||||
|
</importFeatures>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
custom = true
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||||
|
<CertificateConfigurations>
|
||||||
|
<CertificateKeystore>
|
||||||
|
<!-- Certificate Keystore file location-->
|
||||||
|
<CertificateKeystoreLocation>${carbon.home}/repository/resources/security/wso2certs.jks</CertificateKeystoreLocation>
|
||||||
|
<!-- Certificate Keystore type (JKS/PKCS12 etc.)-->
|
||||||
|
<CertificateKeystoreType>JKS</CertificateKeystoreType>
|
||||||
|
<!-- Certificate Keystore password-->
|
||||||
|
<CertificateKeystorePassword>wso2carbon</CertificateKeystorePassword>
|
||||||
|
<!-- Certificate authority certificate alias -->
|
||||||
|
<CACertAlias>cacert</CACertAlias>
|
||||||
|
<!-- Certificate authority private key password -->
|
||||||
|
<CAPrivateKeyPassword>cacert</CAPrivateKeyPassword>
|
||||||
|
<!-- Registration authority certificate alias -->
|
||||||
|
<RACertAlias>racert</RACertAlias>
|
||||||
|
<!-- Registration authority private key password -->
|
||||||
|
<RAPrivateKeyPassword>racert</RAPrivateKeyPassword>
|
||||||
|
</CertificateKeystore>
|
||||||
|
</CertificateConfigurations>
|
||||||
Binary file not shown.
@ -0,0 +1,3 @@
|
|||||||
|
instructions.configure = \
|
||||||
|
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/conf/wso2certs.jks,target:${installFolder}/../../resources/security/wso2certs.jks,overwrite:true);\
|
||||||
|
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/conf/certificate-config.xml,target:${installFolder}/../../conf/certificate-config.xml,overwrite:true);\
|
||||||
41
features/certificate-mgt/pom.xml
Normal file
41
features/certificate-mgt/pom.xml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2015, 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>certificate-mgt-feature</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>WSO2 Carbon - Certificate Management Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>org.wso2.carbon.certificate.mgt.server.feature</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -37,8 +37,11 @@
|
|||||||
</IdentityConfiguration>
|
</IdentityConfiguration>
|
||||||
<PolicyConfiguration>
|
<PolicyConfiguration>
|
||||||
<monitoringClass>org.wso2.carbon.policy.mgt</monitoringClass>
|
<monitoringClass>org.wso2.carbon.policy.mgt</monitoringClass>
|
||||||
|
<monitoringEnable>true</monitoringEnable>
|
||||||
|
<monitoringFrequency>60000</monitoringFrequency>
|
||||||
<maxRetries>5</maxRetries>
|
<maxRetries>5</maxRetries>
|
||||||
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
|
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
|
||||||
|
<minRetriesToMarkInactive>20</minRetriesToMarkInactive>
|
||||||
</PolicyConfiguration>
|
</PolicyConfiguration>
|
||||||
</ManagementRepository>
|
</ManagementRepository>
|
||||||
</DeviceMgtConfiguration>
|
</DeviceMgtConfiguration>
|
||||||
|
|||||||
@ -1,20 +1,15 @@
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
||||||
ID INT auto_increment NOT NULL,
|
ID INT auto_increment NOT NULL,
|
||||||
NAME VARCHAR(300) NULL DEFAULT NULL,
|
NAME VARCHAR(300) DEFAULT NULL,
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE (
|
||||||
ID INTEGER auto_increment NOT NULL,
|
ID INTEGER auto_increment NOT NULL,
|
||||||
DESCRIPTION TEXT NULL DEFAULT NULL,
|
DESCRIPTION TEXT DEFAULT NULL,
|
||||||
NAME VARCHAR(100) NULL DEFAULT NULL,
|
NAME VARCHAR(100) DEFAULT NULL,
|
||||||
DATE_OF_ENROLLMENT BIGINT NULL DEFAULT NULL,
|
DEVICE_TYPE_ID INT(11) DEFAULT NULL,
|
||||||
DATE_OF_LAST_UPDATE BIGINT NULL DEFAULT NULL,
|
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||||
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL,
|
|
||||||
STATUS VARCHAR(15) NULL DEFAULT NULL,
|
|
||||||
DEVICE_TYPE_ID INT(11) NULL DEFAULT NULL,
|
|
||||||
DEVICE_IDENTIFICATION VARCHAR(300) NULL DEFAULT NULL,
|
|
||||||
OWNER VARCHAR(45) NULL DEFAULT NULL,
|
|
||||||
TENANT_ID INTEGER DEFAULT 0,
|
TENANT_ID INTEGER DEFAULT 0,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
|
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
|
||||||
@ -68,10 +63,10 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
|||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
OWNER VARCHAR(50) NOT NULL,
|
OWNER VARCHAR(50) NOT NULL,
|
||||||
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL,
|
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
|
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
||||||
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
|
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||||
@ -128,12 +123,14 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY (
|
CREATE TABLE IF NOT EXISTS DM_POLICY (
|
||||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||||
NAME VARCHAR(45) NULL DEFAULT NULL ,
|
NAME VARCHAR(45) DEFAULT NULL ,
|
||||||
TENANT_ID INT(11) NOT NULL ,
|
TENANT_ID INT(11) NOT NULL ,
|
||||||
PROFILE_ID INT(11) NOT NULL ,
|
PROFILE_ID INT(11) NOT NULL ,
|
||||||
OWNERSHIP_TYPE VARCHAR(45) NULL,
|
OWNERSHIP_TYPE VARCHAR(45) NULL,
|
||||||
COMPLIANCE VARCHAR(100) NULL,
|
COMPLIANCE VARCHAR(100) NULL,
|
||||||
PRIORITY INT NOT NULL ,
|
PRIORITY INT NOT NULL,
|
||||||
|
ACTIVE INT(2) NOT NULL,
|
||||||
|
UPDATED INT(1) NULL,
|
||||||
PRIMARY KEY (ID) ,
|
PRIMARY KEY (ID) ,
|
||||||
CONSTRAINT FK_DM_PROFILE_DM_POLICY
|
CONSTRAINT FK_DM_PROFILE_DM_POLICY
|
||||||
FOREIGN KEY (PROFILE_ID )
|
FOREIGN KEY (PROFILE_ID )
|
||||||
@ -148,6 +145,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
||||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||||
DEVICE_ID INT(11) NOT NULL ,
|
DEVICE_ID INT(11) NOT NULL ,
|
||||||
|
ENROLMENT_ID INT(11) NOT NULL,
|
||||||
|
DEVICE BLOB NOT NULL,
|
||||||
POLICY_ID INT(11) NOT NULL ,
|
POLICY_ID INT(11) NOT NULL ,
|
||||||
PRIMARY KEY (ID) ,
|
PRIMARY KEY (ID) ,
|
||||||
CONSTRAINT FK_POLICY_DEVICE_POLICY
|
CONSTRAINT FK_POLICY_DEVICE_POLICY
|
||||||
@ -235,6 +234,7 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
|
||||||
ID INT NOT NULL AUTO_INCREMENT ,
|
ID INT NOT NULL AUTO_INCREMENT ,
|
||||||
DEVICE_ID INT NOT NULL ,
|
DEVICE_ID INT NOT NULL ,
|
||||||
|
ENROLMENT_ID INT(11) NOT NULL,
|
||||||
POLICY_ID INT NOT NULL ,
|
POLICY_ID INT NOT NULL ,
|
||||||
POLICY_CONTENT BLOB NULL ,
|
POLICY_CONTENT BLOB NULL ,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
@ -300,6 +300,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
|
|||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
|
||||||
ID INT NOT NULL AUTO_INCREMENT,
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
DEVICE_ID INT NOT NULL,
|
DEVICE_ID INT NOT NULL,
|
||||||
|
ENROLMENT_ID INT(11) NOT NULL,
|
||||||
POLICY_ID INT NOT NULL,
|
POLICY_ID INT NOT NULL,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
STATUS INT NULL,
|
STATUS INT NULL,
|
||||||
@ -317,6 +318,15 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
|
||||||
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
|
POLICY_ID INT NOT NULL,
|
||||||
|
DEVICE_TYPE_ID INT NOT NULL,
|
||||||
|
TENANT_ID INT(11) NOT NULL,
|
||||||
|
PRIMARY KEY (ID)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
|
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
|
||||||
ID INT NOT NULL AUTO_INCREMENT,
|
ID INT NOT NULL AUTO_INCREMENT,
|
||||||
COMPLIANCE_STATUS_ID INT NOT NULL,
|
COMPLIANCE_STATUS_ID INT NOT NULL,
|
||||||
@ -335,10 +345,10 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
|||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
DEVICE_ID INTEGER NOT NULL,
|
DEVICE_ID INTEGER NOT NULL,
|
||||||
OWNER VARCHAR(50) NOT NULL,
|
OWNER VARCHAR(50) NOT NULL,
|
||||||
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL,
|
OWNERSHIP VARCHAR(45) DEFAULT NULL,
|
||||||
STATUS VARCHAR(50) NULL,
|
STATUS VARCHAR(50) NULL,
|
||||||
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
|
DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL,
|
||||||
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
|
DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL,
|
||||||
TENANT_ID INT NOT NULL,
|
TENANT_ID INT NOT NULL,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||||
@ -349,12 +359,12 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
|||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
NAME VARCHAR(50) NOT NULL,
|
NAME VARCHAR(50) NOT NULL,
|
||||||
APP_IDENTIFIER VARCHAR(50) NOT NULL,
|
APP_IDENTIFIER VARCHAR(50) NOT NULL,
|
||||||
PLATFORM VARCHAR(50) NULL DEFAULT NULL,
|
PLATFORM VARCHAR(50) DEFAULT NULL,
|
||||||
CATEGORY VARCHAR(50) NULL,
|
CATEGORY VARCHAR(50) NULL,
|
||||||
VERSION VARCHAR(50) NULL,
|
VERSION VARCHAR(50) NULL,
|
||||||
TYPE VARCHAR(50) NULL,
|
TYPE VARCHAR(50) NULL,
|
||||||
LOCATION_URL VARCHAR(100) NULL DEFAULT NULL,
|
LOCATION_URL VARCHAR(100) DEFAULT NULL,
|
||||||
IMAGE_URL VARCHAR(100) NULL DEFAULT NULL,
|
IMAGE_URL VARCHAR(100) DEFAULT NULL,
|
||||||
APP_PROPERTIES BLOB NULL,
|
APP_PROPERTIES BLOB NULL,
|
||||||
TENANT_ID INTEGER NOT NULL,
|
TENANT_ID INTEGER NOT NULL,
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE` (
|
CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE` (
|
||||||
`ID` INT(11) NOT NULL ,
|
`ID` INT(11) NOT NULL ,
|
||||||
`NAME` VARCHAR(300) NULL DEFAULT NULL ,
|
`NAME` VARCHAR(300) DEFAULT NULL ,
|
||||||
PRIMARY KEY (`ID`) )
|
PRIMARY KEY (`ID`) )
|
||||||
ENGINE = InnoDB
|
ENGINE = InnoDB
|
||||||
DEFAULT CHARACTER SET = latin1;
|
DEFAULT CHARACTER SET = latin1;
|
||||||
@ -14,16 +14,11 @@ DEFAULT CHARACTER SET = latin1;
|
|||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE` (
|
CREATE TABLE IF NOT EXISTS `DM_DEVICE` (
|
||||||
`ID` VARCHAR(20) NOT NULL ,
|
`ID` VARCHAR(20) NOT NULL ,
|
||||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
`DESCRIPTION` TEXT DEFAULT NULL ,
|
||||||
`NAME` VARCHAR(100) NULL DEFAULT NULL ,
|
`NAME` VARCHAR(100) DEFAULT NULL ,
|
||||||
`DATE_OF_ENROLLMENT` DATETIME NULL DEFAULT NULL ,
|
`DEVICE_TYPE_ID` INT(11) DEFAULT NULL ,
|
||||||
`DATE_OF_LAST_UPDATE` DATETIME NULL DEFAULT NULL ,
|
`DEVICE_IDENTIFICATION` VARCHAR(300) DEFAULT NULL ,
|
||||||
`OWNERSHIP` VARCHAR(45) NULL DEFAULT NULL ,
|
`TENANT_ID` INTEGER DEFAULT 0,
|
||||||
`STATUS` VARCHAR(15) NULL DEFAULT NULL ,
|
|
||||||
`DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL ,
|
|
||||||
`DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL ,
|
|
||||||
`OWNER` VARCHAR(45) NULL DEFAULT NULL ,
|
|
||||||
TENANT_ID INTEGER DEFAULT 0,
|
|
||||||
PRIMARY KEY (`ID`) ,
|
PRIMARY KEY (`ID`) ,
|
||||||
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2_idx` (`DEVICE_TYPE_ID` ASC) ,
|
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2_idx` (`DEVICE_TYPE_ID` ASC) ,
|
||||||
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`
|
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`
|
||||||
|
|||||||
62
pom.xml
62
pom.xml
@ -37,15 +37,17 @@
|
|||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>components/device-mgt</module>
|
<module>components/device-mgt</module>
|
||||||
<module>components/apimgt-extensions</module>
|
<module>components/apimgt-extensions</module>
|
||||||
<module>components/policy-mgt</module>
|
<module>components/policy-mgt</module>
|
||||||
|
<module>components/certificate-mgt</module>
|
||||||
<module>components/webapp-authenticator-framework</module>
|
<module>components/webapp-authenticator-framework</module>
|
||||||
<module>components/oauth-extensions</module>
|
<module>components/oauth-extensions</module>
|
||||||
<module>features/device-mgt</module>
|
<module>features/device-mgt</module>
|
||||||
<module>features/apimgt-extensions</module>
|
<module>features/apimgt-extensions</module>
|
||||||
<module>features/policy-mgt</module>
|
<module>features/policy-mgt</module>
|
||||||
<module>features/webapp-authenticator-framework</module>
|
<module>features/webapp-authenticator-framework</module>
|
||||||
<module>features/oauth-extensions</module>
|
<module>features/oauth-extensions</module>
|
||||||
|
<module>features/certificate-mgt</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@ -133,6 +135,11 @@
|
|||||||
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
|
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
|
||||||
<version>${carbon.device.mgt.version}</version>
|
<version>${carbon.device.mgt.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
||||||
|
<version>${carbon.device.mgt.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
||||||
@ -931,6 +938,44 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle.wso2</groupId>
|
||||||
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
|
<version>${bcprov.wso2.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle.wso2</groupId>
|
||||||
|
<artifactId>bcpkix-jdk15on</artifactId>
|
||||||
|
<version>${bcpkix.wso2.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle.wso2</groupId>
|
||||||
|
<artifactId>bcmail-jdk15on</artifactId>
|
||||||
|
<version>${bcmail.wso2.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.jscep.wso2</groupId>
|
||||||
|
<artifactId>jscep</artifactId>
|
||||||
|
<version>${jscep.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec.wso2</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
<version>${version.commons.codec}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io.wso2</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>${version.commons.io}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang.wso2</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<version>${version.commons.lang}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
@ -1184,6 +1229,9 @@
|
|||||||
|
|
||||||
<!-- Carbon Commons -->
|
<!-- Carbon Commons -->
|
||||||
<carbon.commons.version>4.4.0</carbon.commons.version>
|
<carbon.commons.version>4.4.0</carbon.commons.version>
|
||||||
|
<version.commons.codec>1.4.0.wso2v1</version.commons.codec>
|
||||||
|
<version.commons.io>2.4.0.wso2v1</version.commons.io>
|
||||||
|
<version.commons.lang>2.6.0.wso2v1</version.commons.lang>
|
||||||
|
|
||||||
<!-- Carbon API Management -->
|
<!-- Carbon API Management -->
|
||||||
<carbon.api.mgt.version>1.4.0</carbon.api.mgt.version>
|
<carbon.api.mgt.version>1.4.0</carbon.api.mgt.version>
|
||||||
@ -1193,6 +1241,16 @@
|
|||||||
<cxf.bindings.version>2.5.11</cxf.bindings.version>
|
<cxf.bindings.version>2.5.11</cxf.bindings.version>
|
||||||
<json-simple.version>1.1.wso2v1</json-simple.version>
|
<json-simple.version>1.1.wso2v1</json-simple.version>
|
||||||
<jackson.version>1.9.0</jackson.version>
|
<jackson.version>1.9.0</jackson.version>
|
||||||
|
|
||||||
|
<!-- BouncyCastle -->
|
||||||
|
<bcprov.wso2.version>1.49.wso2v1</bcprov.wso2.version>
|
||||||
|
<bcpkix.wso2.version>1.49.wso2v1</bcpkix.wso2.version>
|
||||||
|
<bcprov.ext.wso2.version>1.49.wso2v1</bcprov.ext.wso2.version>
|
||||||
|
<bcprov.wso2.version.range>[1.40.wso2v1, 1.50.0)</bcprov.wso2.version.range>
|
||||||
|
<bcmail.wso2.version>1.49.wso2v1</bcmail.wso2.version>
|
||||||
|
|
||||||
|
<!-- JSCEP -->
|
||||||
|
<jscep.version>2.0.2.wso2v2</jscep.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user