mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixed conflicts and merged
This commit is contained in:
commit
564c2b280e
@ -22,7 +22,6 @@ import org.apache.catalina.core.StandardContext;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
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.scannotation.AnnotationDB;
|
|
||||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
||||||
import org.wso2.carbon.apimgt.api.model.Scope;
|
import org.wso2.carbon.apimgt.api.model.Scope;
|
||||||
@ -378,7 +377,6 @@ public class AnnotationProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory
|
* Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory
|
||||||
* if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
|
* if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
|
||||||
|
|||||||
@ -17,7 +17,6 @@ package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util;
|
|||||||
|
|
||||||
import org.scannotation.AnnotationDB;
|
import org.scannotation.AnnotationDB;
|
||||||
import org.scannotation.archiveiterator.Filter;
|
import org.scannotation.archiveiterator.Filter;
|
||||||
import org.scannotation.archiveiterator.IteratorFactory;
|
|
||||||
import org.scannotation.archiveiterator.StreamIterator;
|
import org.scannotation.archiveiterator.StreamIterator;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|||||||
@ -15,7 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util;
|
package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util;
|
||||||
|
|
||||||
import org.scannotation.archiveiterator.*;
|
|
||||||
|
import org.scannotation.archiveiterator.DirectoryIteratorFactory;
|
||||||
|
import org.scannotation.archiveiterator.Filter;
|
||||||
|
import org.scannotation.archiveiterator.JarIterator;
|
||||||
|
import org.scannotation.archiveiterator.StreamIterator;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|||||||
@ -1,8 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.cert.jaxrs.api.beans;
|
package org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by hasunie on 5/26/16.
|
|
||||||
*/
|
|
||||||
public class EnrollmentCertificate {
|
public class EnrollmentCertificate {
|
||||||
String serial;
|
String serial;
|
||||||
String pem;
|
String pem;
|
||||||
|
|||||||
@ -9,8 +9,8 @@ import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.EnrollmentCertificat
|
|||||||
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.ErrorResponse;
|
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.util.DeviceMgtAPIUtils;
|
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.util.RequestValidationUtil;
|
import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.util.RequestValidationUtil;
|
||||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.CertificateManagementException;
|
||||||
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
||||||
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
|
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
@ -76,7 +76,7 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem
|
|||||||
try {
|
try {
|
||||||
certificateResponse = certificateService.searchCertificates(serialNumber);
|
certificateResponse = certificateService.searchCertificates(serialNumber);
|
||||||
return Response.status(Response.Status.OK).entity(certificateResponse).build();
|
return Response.status(Response.Status.OK).entity(certificateResponse).build();
|
||||||
} catch (CertificateManagementDAOException e) {
|
} catch (CertificateManagementException e) {
|
||||||
String msg = "Error occurred while converting PEM file to X509Certificate";
|
String msg = "Error occurred while converting PEM file to X509Certificate";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
@ -106,7 +106,7 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem
|
|||||||
certificates.setCount(result.getRecordsTotal());
|
certificates.setCount(result.getRecordsTotal());
|
||||||
certificates.setList((List<CertificateResponse>) result.getData());
|
certificates.setList((List<CertificateResponse>) result.getData());
|
||||||
return Response.status(Response.Status.OK).entity(certificates).build();
|
return Response.status(Response.Status.OK).entity(certificates).build();
|
||||||
} catch (CertificateManagementDAOException e) {
|
} catch (CertificateManagementException e) {
|
||||||
String msg = "Error occurred while fetching all certificates.";
|
String msg = "Error occurred while fetching all certificates.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
@ -128,7 +128,7 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem
|
|||||||
}
|
}
|
||||||
return Response.status(Response.Status.OK).entity("Certificate that carries the serial number '" +
|
return Response.status(Response.Status.OK).entity("Certificate that carries the serial number '" +
|
||||||
serialNumber + "' has been removed").build();
|
serialNumber + "' has been removed").build();
|
||||||
} catch (CertificateManagementDAOException e) {
|
} catch (CertificateManagementException e) {
|
||||||
String msg = "Error occurred while converting PEM file to X509Certificate";
|
String msg = "Error occurred while converting PEM file to X509Certificate";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
|
|||||||
@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.certificate.mgt.core.dao;
|
package org.wso2.carbon.certificate.mgt.core.dao;
|
||||||
|
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.bean.Certificate;
|
||||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,8 +37,9 @@ public interface CertificateDAO {
|
|||||||
*
|
*
|
||||||
* @param certificate Holds the certificate and relevant details.
|
* @param certificate Holds the certificate and relevant details.
|
||||||
* @throws CertificateManagementDAOException
|
* @throws CertificateManagementDAOException
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
void addCertificate(List<org.wso2.carbon.certificate.mgt.core.bean.Certificate> certificate)
|
void addCertificate(List<Certificate> certificate)
|
||||||
throws CertificateManagementDAOException;
|
throws CertificateManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,31 +48,37 @@ public interface CertificateDAO {
|
|||||||
* @param serialNumber Serial number of the certificate.
|
* @param serialNumber Serial number of the certificate.
|
||||||
* @return representation of the certificate.
|
* @return representation of the certificate.
|
||||||
* @throws CertificateManagementDAOException
|
* @throws CertificateManagementDAOException
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse retrieveCertificate(String serialNumber
|
CertificateResponse retrieveCertificate(String serialNumber) throws CertificateManagementDAOException;
|
||||||
) throws CertificateManagementDAOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the certificates in a paginated manner.
|
* Get all the certificates in a paginated manner.
|
||||||
|
*
|
||||||
* @param request Request mentioning pagination details such as length and stating index.
|
* @param request Request mentioning pagination details such as length and stating index.
|
||||||
* @return Pagination result with data and the count of results.
|
* @return Pagination result with data and the count of results.
|
||||||
* @throws CertificateManagementDAOException
|
* @throws CertificateManagementDAOException
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
PaginationResult getAllCertificates(PaginationRequest request) throws CertificateManagementDAOException;
|
PaginationResult getAllCertificates(PaginationRequest request) throws CertificateManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the certificates.
|
* Get all the certificates.
|
||||||
|
*
|
||||||
* @return List of certificates
|
* @return List of certificates
|
||||||
* @throws CertificateManagementDAOException
|
* @throws CertificateManagementDAOException
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public List<CertificateResponse> getAllCertificates() throws CertificateManagementDAOException;
|
public List<CertificateResponse> getAllCertificates() throws CertificateManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a certificate identified by a serial number()
|
* Delete a certificate identified by a serial number()
|
||||||
|
*
|
||||||
* @param serialNumber serial number
|
* @param serialNumber serial number
|
||||||
* @return whether the certificate was removed or not.
|
* @return whether the certificate was removed or not.
|
||||||
*/
|
*/
|
||||||
boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException;
|
boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException;
|
||||||
|
|
||||||
public List<CertificateResponse> searchCertificate(String serialNumber) throws CertificateManagementDAOException;
|
public List<CertificateResponse> searchCertificate(String serialNumber) throws CertificateManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ public class CertificateManagementDAOFactory {
|
|||||||
try {
|
try {
|
||||||
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
|
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Error occurred while retrieving config.datasource connection", e);
|
log.error( "Error occurred while retrieving config.datasource connection", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ public class CertificateManagementDAOFactory {
|
|||||||
try {
|
try {
|
||||||
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
|
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Error occurred while retrieving config.datasource connection", e);
|
log.error("Error occurred while retrieving a datasource connection", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,11 +72,22 @@ public class CertificateManagementDAOFactory {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
conn = dataSource.getConnection();
|
conn = dataSource.getConnection();
|
||||||
conn.setAutoCommit(false);
|
|
||||||
currentConnection.set(conn);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new TransactionManagementException("Error occurred while retrieving config.datasource connection", e);
|
throw new TransactionManagementException("Error occurred while retrieving a data source connection", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e1) {
|
||||||
|
log.warn("Error occurred while closing the borrowed connection. " +
|
||||||
|
"Transaction has ended pre-maturely", e1);
|
||||||
|
}
|
||||||
|
throw new TransactionManagementException("Error occurred while setting auto-commit to false", e);
|
||||||
|
}
|
||||||
|
currentConnection.set(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openConnection() throws SQLException {
|
public static void openConnection() throws SQLException {
|
||||||
@ -111,6 +122,8 @@ public class CertificateManagementDAOFactory {
|
|||||||
conn.commit();
|
conn.commit();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Error occurred while committing the transaction", e);
|
log.error("Error occurred while committing the transaction", e);
|
||||||
|
} finally {
|
||||||
|
closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +138,8 @@ public class CertificateManagementDAOFactory {
|
|||||||
conn.rollback();
|
conn.rollback();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
log.warn("Error occurred while roll-backing the transaction", e);
|
||||||
|
} finally {
|
||||||
|
closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +153,7 @@ public class CertificateManagementDAOFactory {
|
|||||||
try {
|
try {
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.warn("Error occurred while close the connection");
|
log.warn("Error occurred while close the connection", e);
|
||||||
}
|
}
|
||||||
currentConnection.remove();
|
currentConnection.remove();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -674,10 +674,7 @@ public class CertificateGenerator {
|
|||||||
} catch (TransactionManagementException e) {
|
} catch (TransactionManagementException e) {
|
||||||
String errorMsg = "Error occurred when saving the generated certificate";
|
String errorMsg = "Error occurred when saving the generated certificate";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
CertificateManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new KeystoreException(errorMsg, e);
|
throw new KeystoreException(errorMsg, e);
|
||||||
} finally {
|
|
||||||
CertificateManagementDAOFactory.closeConnection();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -738,9 +735,8 @@ public class CertificateGenerator {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new KeystoreException("CSR cannot be recovered.", e);
|
throw new KeystoreException("CSR cannot be recovered.", e);
|
||||||
}
|
}
|
||||||
X509Certificate signedCertificate = generateCertificateFromCSR(privateKeyCA, certificationRequest,
|
return generateCertificateFromCSR(privateKeyCA, certificationRequest,
|
||||||
certCA.getIssuerX500Principal().getName());
|
certCA.getIssuerX500Principal().getName());
|
||||||
return signedCertificate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void extractCertificateDetails(byte[] certificateBytes, CertificateResponse certificateResponse)
|
public static void extractCertificateDetails(byte[] certificateBytes, CertificateResponse certificateResponse)
|
||||||
|
|||||||
@ -19,6 +19,7 @@ package org.wso2.carbon.certificate.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.certificate.mgt.core.dao.CertificateDAO;
|
||||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||||
@ -41,17 +42,21 @@ public class KeyStoreReader {
|
|||||||
|
|
||||||
private static final Log log = LogFactory.getLog(KeyStoreReader.class);
|
private static final Log log = LogFactory.getLog(KeyStoreReader.class);
|
||||||
|
|
||||||
private KeyStore loadKeyStore(String configEntryKeyStoreType, String configEntryKeyStorePath,
|
private CertificateDAO certDao;
|
||||||
String configEntryKeyStorePassword) throws KeystoreException {
|
|
||||||
|
|
||||||
InputStream inputStream = null;
|
public KeyStoreReader() {
|
||||||
|
this.certDao = CertificateManagementDAOFactory.getCertificateDAO();
|
||||||
|
}
|
||||||
|
|
||||||
|
private KeyStore loadKeyStore(
|
||||||
|
String configEntryKeyStoreType, String configEntryKeyStorePath,
|
||||||
|
String configEntryKeyStorePassword) throws KeystoreException {
|
||||||
|
InputStream is = null;
|
||||||
KeyStore keystore;
|
KeyStore keystore;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
keystore = KeyStore.getInstance(ConfigurationUtil.getConfigEntry(configEntryKeyStoreType));
|
keystore = KeyStore.getInstance(ConfigurationUtil.getConfigEntry(configEntryKeyStoreType));
|
||||||
inputStream = new FileInputStream(ConfigurationUtil.getConfigEntry(configEntryKeyStorePath));
|
is = new FileInputStream(ConfigurationUtil.getConfigEntry(configEntryKeyStorePath));
|
||||||
keystore.load(inputStream, ConfigurationUtil.getConfigEntry(configEntryKeyStorePassword).toCharArray());
|
keystore.load(is, ConfigurationUtil.getConfigEntry(configEntryKeyStorePassword).toCharArray());
|
||||||
|
|
||||||
} catch (KeyStoreException e) {
|
} catch (KeyStoreException e) {
|
||||||
String errorMsg = "KeyStore issue occurred when loading KeyStore";
|
String errorMsg = "KeyStore issue occurred when loading KeyStore";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
@ -74,8 +79,8 @@ public class KeyStoreReader {
|
|||||||
throw new KeystoreException(errorMsg, e);
|
throw new KeystoreException(errorMsg, e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (inputStream != null) {
|
if (is != null) {
|
||||||
inputStream.close();
|
is.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error closing KeyStore input stream", e);
|
log.error("Error closing KeyStore input stream", e);
|
||||||
@ -86,16 +91,12 @@ public class KeyStoreReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void saveKeyStore(KeyStore keyStore, String configEntryKeyStorePath,
|
private synchronized void saveKeyStore(KeyStore keyStore, String configEntryKeyStorePath,
|
||||||
String configEntryKeyStorePassword) throws KeystoreException {
|
String configEntryKeyStorePassword) throws KeystoreException {
|
||||||
|
FileOutputStream os = null;
|
||||||
FileOutputStream outputStream = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
outputStream = new FileOutputStream(
|
os = new FileOutputStream(
|
||||||
ConfigurationUtil.getConfigEntry(configEntryKeyStorePath));
|
ConfigurationUtil.getConfigEntry(configEntryKeyStorePath));
|
||||||
keyStore.store(outputStream, ConfigurationUtil.getConfigEntry(configEntryKeyStorePassword).toCharArray());
|
keyStore.store(os, ConfigurationUtil.getConfigEntry(configEntryKeyStorePassword).toCharArray());
|
||||||
outputStream.close();
|
|
||||||
|
|
||||||
} catch (KeyStoreException e) {
|
} catch (KeyStoreException e) {
|
||||||
String errorMsg = "KeyStore issue occurred when loading KeyStore";
|
String errorMsg = "KeyStore issue occurred when loading KeyStore";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
@ -118,8 +119,8 @@ public class KeyStoreReader {
|
|||||||
throw new KeystoreException(errorMsg, e);
|
throw new KeystoreException(errorMsg, e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (outputStream != null) {
|
if (os != null) {
|
||||||
outputStream.close();
|
os.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error closing KeyStore output stream", e);
|
log.error("Error closing KeyStore output stream", e);
|
||||||
@ -139,10 +140,8 @@ public class KeyStoreReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Certificate getCACertificate() throws KeystoreException {
|
public Certificate getCACertificate() throws KeystoreException {
|
||||||
|
|
||||||
KeyStore keystore = loadCertificateKeyStore();
|
KeyStore keystore = loadCertificateKeyStore();
|
||||||
Certificate caCertificate;
|
Certificate caCertificate;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
caCertificate = keystore.getCertificate(ConfigurationUtil.getConfigEntry(ConfigurationUtil.CA_CERT_ALIAS));
|
caCertificate = keystore.getCertificate(ConfigurationUtil.getConfigEntry(ConfigurationUtil.CA_CERT_ALIAS));
|
||||||
} catch (KeyStoreException e) {
|
} catch (KeyStoreException e) {
|
||||||
@ -188,7 +187,6 @@ public class KeyStoreReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Certificate getRACertificate() throws KeystoreException {
|
public Certificate getRACertificate() throws KeystoreException {
|
||||||
|
|
||||||
KeyStore keystore = loadCertificateKeyStore();
|
KeyStore keystore = loadCertificateKeyStore();
|
||||||
Certificate raCertificate;
|
Certificate raCertificate;
|
||||||
try {
|
try {
|
||||||
@ -207,13 +205,11 @@ public class KeyStoreReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Certificate getCertificateByAlias(String alias) throws KeystoreException {
|
public Certificate getCertificateByAlias(String alias) throws KeystoreException {
|
||||||
|
|
||||||
Certificate raCertificate = null;
|
Certificate raCertificate = null;
|
||||||
try {
|
try {
|
||||||
CertificateManagementDAOFactory.openConnection();
|
CertificateManagementDAOFactory.openConnection();
|
||||||
CertificateResponse certificateResponse = CertificateManagementDAOFactory.getCertificateDAO().
|
CertificateResponse certificateResponse = certDao.retrieveCertificate(alias);
|
||||||
retrieveCertificate(alias);
|
if (certificateResponse != null) {
|
||||||
if(certificateResponse != null) {
|
|
||||||
raCertificate = (Certificate) Serializer.deserialize(certificateResponse.getCertificate());
|
raCertificate = (Certificate) Serializer.deserialize(certificateResponse.getCertificate());
|
||||||
}
|
}
|
||||||
} catch (CertificateManagementDAOException e) {
|
} catch (CertificateManagementDAOException e) {
|
||||||
@ -221,7 +217,7 @@ public class KeyStoreReader {
|
|||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new KeystoreException(errorMsg, e);
|
throw new KeystoreException(errorMsg, e);
|
||||||
} catch (ClassNotFoundException | IOException e) {
|
} catch (ClassNotFoundException | IOException e) {
|
||||||
String errorMsg = "Error when deserializing saved certificate.";
|
String errorMsg = "Error when de-serializing saved certificate.";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new KeystoreException(errorMsg, e);
|
throw new KeystoreException(errorMsg, e);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -234,8 +230,7 @@ public class KeyStoreReader {
|
|||||||
return raCertificate;
|
return raCertificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrivateKey getRAPrivateKey() throws KeystoreException {
|
public PrivateKey getRAPrivateKey() throws KeystoreException {
|
||||||
|
|
||||||
KeyStore keystore = loadCertificateKeyStore();
|
KeyStore keystore = loadCertificateKeyStore();
|
||||||
PrivateKey raPrivateKey;
|
PrivateKey raPrivateKey;
|
||||||
try {
|
try {
|
||||||
@ -264,13 +259,11 @@ public class KeyStoreReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CertificateResponse getCertificateBySerial(String serialNumber) throws KeystoreException {
|
public CertificateResponse getCertificateBySerial(String serialNumber) throws KeystoreException {
|
||||||
|
|
||||||
CertificateResponse certificateResponse = null;
|
CertificateResponse certificateResponse = null;
|
||||||
try {
|
try {
|
||||||
CertificateManagementDAOFactory.openConnection();
|
CertificateManagementDAOFactory.openConnection();
|
||||||
certificateResponse = CertificateManagementDAOFactory.getCertificateDAO().
|
certificateResponse = certDao.retrieveCertificate(serialNumber);
|
||||||
retrieveCertificate(serialNumber);
|
if (certificateResponse != null && certificateResponse.getCertificate() != null) {
|
||||||
if(certificateResponse != null && certificateResponse.getCertificate() != null) {
|
|
||||||
Certificate certificate = (Certificate) Serializer.deserialize(certificateResponse.getCertificate());
|
Certificate certificate = (Certificate) Serializer.deserialize(certificateResponse.getCertificate());
|
||||||
if (certificate instanceof X509Certificate) {
|
if (certificate instanceof X509Certificate) {
|
||||||
X509Certificate x509cert = (X509Certificate) certificate;
|
X509Certificate x509cert = (X509Certificate) certificate;
|
||||||
@ -278,10 +271,9 @@ public class KeyStoreReader {
|
|||||||
certificateResponse.setCommonName(commonName);
|
certificateResponse.setCommonName(commonName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (CertificateManagementDAOException e) {
|
} catch (CertificateManagementDAOException e) {
|
||||||
String errorMsg = "Error when retrieving certificate from the the database for the serial number: " +
|
String errorMsg = "Error when retrieving certificate from the the database for the serial number: " +
|
||||||
serialNumber;
|
serialNumber;
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new KeystoreException(errorMsg, e);
|
throw new KeystoreException(errorMsg, e);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -289,7 +281,7 @@ public class KeyStoreReader {
|
|||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new KeystoreException(errorMsg, e);
|
throw new KeystoreException(errorMsg, e);
|
||||||
} catch (ClassNotFoundException | IOException e) {
|
} catch (ClassNotFoundException | IOException e) {
|
||||||
String errorMsg = "Error when deserializing saved certificate.";
|
String errorMsg = "Error when de-serializing saved certificate.";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new KeystoreException(errorMsg, e);
|
throw new KeystoreException(errorMsg, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
package org.wso2.carbon.certificate.mgt.core.service;
|
package org.wso2.carbon.certificate.mgt.core.service;
|
||||||
|
|
||||||
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
||||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException;
|
import org.wso2.carbon.certificate.mgt.core.exception.CertificateManagementException;
|
||||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||||
import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse;
|
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.exception.KeystoreException;
|
||||||
@ -47,8 +47,8 @@ public interface CertificateManagementService {
|
|||||||
|
|
||||||
byte[] getPKIMessageSCEP(InputStream inputStream) throws KeystoreException;
|
byte[] getPKIMessageSCEP(InputStream inputStream) throws KeystoreException;
|
||||||
|
|
||||||
X509Certificate generateCertificateFromCSR(PrivateKey privateKey, PKCS10CertificationRequest request,
|
X509Certificate generateCertificateFromCSR(
|
||||||
String issueSubject) throws KeystoreException;
|
PrivateKey privateKey, PKCS10CertificationRequest request, String issueSubject) throws KeystoreException;
|
||||||
|
|
||||||
Certificate getCertificateByAlias(String alias) throws KeystoreException;
|
Certificate getCertificateByAlias(String alias) throws KeystoreException;
|
||||||
|
|
||||||
@ -71,13 +71,14 @@ public interface CertificateManagementService {
|
|||||||
|
|
||||||
public X509Certificate pemToX509Certificate(String pem) throws KeystoreException;
|
public X509Certificate pemToX509Certificate(String pem) throws KeystoreException;
|
||||||
|
|
||||||
public CertificateResponse retrieveCertificate(String serialNumber) throws CertificateManagementDAOException;
|
public CertificateResponse retrieveCertificate(String serialNumber) throws CertificateManagementException;
|
||||||
|
|
||||||
public PaginationResult getAllCertificates(PaginationRequest request) throws CertificateManagementDAOException;
|
public PaginationResult getAllCertificates(PaginationRequest request) throws CertificateManagementException;
|
||||||
|
|
||||||
boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException;
|
boolean removeCertificate(String serialNumber) throws CertificateManagementException;
|
||||||
|
|
||||||
public List<CertificateResponse> getCertificates() throws CertificateManagementDAOException;
|
public List<CertificateResponse> getCertificates() throws CertificateManagementException;
|
||||||
|
|
||||||
|
public List<CertificateResponse> searchCertificates(String serialNumber) throws CertificateManagementException;
|
||||||
|
|
||||||
public List<CertificateResponse> searchCertificates(String serialNumber) throws CertificateManagementDAOException;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOExceptio
|
|||||||
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||||
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse;
|
||||||
import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse;
|
import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse;
|
||||||
|
import org.wso2.carbon.certificate.mgt.core.exception.CertificateManagementException;
|
||||||
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
|
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.CertificateGenerator;
|
||||||
import org.wso2.carbon.certificate.mgt.core.impl.KeyStoreReader;
|
import org.wso2.carbon.certificate.mgt.core.impl.KeyStoreReader;
|
||||||
@ -51,7 +52,6 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static CertificateManagementServiceImpl getInstance() {
|
public static CertificateManagementServiceImpl getInstance() {
|
||||||
|
|
||||||
if (certificateManagementServiceImpl == null) {
|
if (certificateManagementServiceImpl == null) {
|
||||||
certificateManagementServiceImpl = new CertificateManagementServiceImpl();
|
certificateManagementServiceImpl = new CertificateManagementServiceImpl();
|
||||||
keyStoreReader = new KeyStoreReader();
|
keyStoreReader = new KeyStoreReader();
|
||||||
@ -106,7 +106,8 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
|
|||||||
return certificateGenerator.verifyPEMSignature(requestCertificate);
|
return certificateGenerator.verifyPEMSignature(requestCertificate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public CertificateResponse verifySubjectDN(String requestDN) throws KeystoreException {
|
@Override
|
||||||
|
public CertificateResponse verifySubjectDN(String requestDN) throws KeystoreException {
|
||||||
return certificateGenerator.verifyCertificateDN(requestDN);
|
return certificateGenerator.verifyCertificateDN(requestDN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,39 +136,47 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
|
|||||||
return certificateGenerator.pemToX509Certificate(pem);
|
return certificateGenerator.pemToX509Certificate(pem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CertificateResponse retrieveCertificate(String serialNumber)
|
public CertificateResponse retrieveCertificate(String serialNumber) throws CertificateManagementException {
|
||||||
throws CertificateManagementDAOException {
|
|
||||||
CertificateDAO certificateDAO;
|
CertificateDAO certificateDAO;
|
||||||
try {
|
try {
|
||||||
CertificateManagementDAOFactory.openConnection();
|
CertificateManagementDAOFactory.openConnection();
|
||||||
certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
|
certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
|
||||||
return certificateDAO.retrieveCertificate(serialNumber);
|
return certificateDAO.retrieveCertificate(serialNumber);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "Error when opening connection";
|
String msg = "Error occurred while opening a connection to the underlying data source";
|
||||||
log.error(errorMsg, e);
|
log.error(msg, e);
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
throw new CertificateManagementException(msg, e);
|
||||||
|
} catch (CertificateManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while looking up for the certificate carrying the serial number '" +
|
||||||
|
serialNumber + "' in the underlying certificate repository";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new CertificateManagementException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
CertificateManagementDAOFactory.closeConnection();
|
CertificateManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaginationResult getAllCertificates(PaginationRequest request)
|
public PaginationResult getAllCertificates(PaginationRequest request) throws CertificateManagementException {
|
||||||
throws CertificateManagementDAOException {
|
|
||||||
try {
|
try {
|
||||||
CertificateManagementDAOFactory.openConnection();
|
CertificateManagementDAOFactory.openConnection();
|
||||||
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
|
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
|
||||||
return certificateDAO.getAllCertificates(request);
|
return certificateDAO.getAllCertificates(request);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "Error when opening connection";
|
String msg = "Error occurred while opening a connection to the underlying data source";
|
||||||
log.error(errorMsg, e);
|
log.error(msg, e);
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
throw new CertificateManagementException(msg, e);
|
||||||
|
} catch (CertificateManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while looking up for the list of certificates managed in the underlying " +
|
||||||
|
"certificate repository";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new CertificateManagementException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
CertificateManagementDAOFactory.closeConnection();
|
CertificateManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException {
|
public boolean removeCertificate(String serialNumber) throws CertificateManagementException {
|
||||||
try {
|
try {
|
||||||
CertificateManagementDAOFactory.beginTransaction();
|
CertificateManagementDAOFactory.beginTransaction();
|
||||||
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
|
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
|
||||||
@ -175,38 +184,53 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
|
|||||||
CertificateManagementDAOFactory.commitTransaction();
|
CertificateManagementDAOFactory.commitTransaction();
|
||||||
return status;
|
return status;
|
||||||
} catch (TransactionManagementException e) {
|
} catch (TransactionManagementException e) {
|
||||||
String errorMsg = "Error when deleting";
|
String msg = "Error occurred while removing certificate carrying serial number '" + serialNumber + "'";
|
||||||
log.error(errorMsg, e);
|
log.error(msg, e);
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
throw new CertificateManagementException(msg, e);
|
||||||
|
} catch (CertificateManagementDAOException e) {
|
||||||
|
CertificateManagementDAOFactory.rollbackTransaction();
|
||||||
|
String msg = "Error occurred while removing the certificate carrying serial number '" + serialNumber +
|
||||||
|
"' from the certificate repository";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new CertificateManagementException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CertificateResponse> getCertificates() throws CertificateManagementException {
|
||||||
|
try {
|
||||||
|
CertificateManagementDAOFactory.openConnection();
|
||||||
|
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
|
||||||
|
return certificateDAO.getAllCertificates();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while opening a connection to the underlying data source";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new CertificateManagementException(msg, e);
|
||||||
|
} catch (CertificateManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while looking up for the list of certificates managed in the " +
|
||||||
|
"underlying certificate repository";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new CertificateManagementException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
CertificateManagementDAOFactory.closeConnection();
|
CertificateManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CertificateResponse> getCertificates() throws CertificateManagementDAOException {
|
public List<CertificateResponse> searchCertificates(String serialNumber) throws CertificateManagementException {
|
||||||
try {
|
|
||||||
CertificateManagementDAOFactory.openConnection();
|
|
||||||
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
|
|
||||||
return certificateDAO.getAllCertificates();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String errorMsg = "Error when opening connection";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
|
||||||
} finally {
|
|
||||||
CertificateManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public List<CertificateResponse> searchCertificates(String serialNumber) throws CertificateManagementDAOException {
|
|
||||||
try {
|
try {
|
||||||
CertificateManagementDAOFactory.openConnection();
|
CertificateManagementDAOFactory.openConnection();
|
||||||
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
|
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
|
||||||
return certificateDAO.searchCertificate(serialNumber);
|
return certificateDAO.searchCertificate(serialNumber);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "Error when opening connection";
|
String msg = "Error occurred while opening a connection to the underlying data source";
|
||||||
log.error(errorMsg, e);
|
log.error(msg, e);
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
throw new CertificateManagementException(msg, e);
|
||||||
|
} catch (CertificateManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while searching for the list of certificates carrying the serial number '" +
|
||||||
|
serialNumber + "' in the underlying certificate repository";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new CertificateManagementException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
CertificateManagementDAOFactory.closeConnection();
|
CertificateManagementDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import org.wso2.carbon.user.api.AuthorizationManager;
|
|||||||
import org.wso2.carbon.user.api.UserRealm;
|
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 org.wso2.carbon.user.api.UserStoreManager;
|
||||||
|
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
@ -53,22 +54,29 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
|
|
||||||
private static final String API_BASE_PATH = "/roles";
|
private static final String API_BASE_PATH = "/roles";
|
||||||
private static final Log log = LogFactory.getLog(RoleManagementServiceImpl.class);
|
private static final Log log = LogFactory.getLog(RoleManagementServiceImpl.class);
|
||||||
|
private static final String PRIMARY_USER_STORE = "PRIMARY";
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Override
|
@Override
|
||||||
public Response getRoles(
|
public Response getRoles(
|
||||||
@QueryParam("filter") String filter,
|
@QueryParam("filter") String filter,
|
||||||
@QueryParam("user-store") String userStoreName,
|
@QueryParam("user-store") String userStore,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||||
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
|
@QueryParam("offset") int offset, @QueryParam("limit") int limit) {
|
||||||
List<String> filteredRoles;
|
List<String> filteredRoles;
|
||||||
RoleList targetRoles = new RoleList();
|
RoleList targetRoles = new RoleList();
|
||||||
|
|
||||||
|
//if user store is null set it to primary
|
||||||
|
if(userStore == null || "".equals(userStore)){
|
||||||
|
userStore = PRIMARY_USER_STORE;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//Get the total role count that matches the given filter
|
//Get the total role count that matches the given filter
|
||||||
filteredRoles = getRolesFromUserStore(filter);
|
filteredRoles = getRolesFromUserStore(filter, userStore);
|
||||||
targetRoles.setCount(filteredRoles.size());
|
targetRoles.setCount(filteredRoles.size());
|
||||||
|
|
||||||
filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter), offset, limit);
|
filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter, userStore), offset, limit);
|
||||||
targetRoles.setList(filteredRoles);
|
targetRoles.setList(filteredRoles);
|
||||||
|
|
||||||
return Response.ok().entity(targetRoles).build();
|
return Response.ok().entity(targetRoles).build();
|
||||||
@ -321,14 +329,14 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getRolesFromUserStore(String filter) throws UserStoreException {
|
private List<String> getRolesFromUserStore(String filter, String userStore) throws UserStoreException {
|
||||||
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
AbstractUserStoreManager userStoreManager = (AbstractUserStoreManager) DeviceMgtAPIUtils.getUserStoreManager();
|
||||||
String[] roles;
|
String[] roles;
|
||||||
boolean filterRolesByName = (!((filter == null) || filter.isEmpty()));
|
boolean filterRolesByName = (!((filter == null) || filter.isEmpty()));
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Getting the list of user roles");
|
log.debug("Getting the list of user roles");
|
||||||
}
|
}
|
||||||
roles = userStoreManager.getRoleNames();
|
roles = userStoreManager.getRoleNames(userStore+"/*", -1, false, true, true);
|
||||||
// removing all internal roles, roles created for Service-providers and application related roles.
|
// removing all internal roles, roles created for Service-providers and application related roles.
|
||||||
List<String> filteredRoles = new ArrayList<>();
|
List<String> filteredRoles = new ArrayList<>();
|
||||||
for (String role : roles) {
|
for (String role : roles) {
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public class DeviceIdentifier implements Serializable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
this.type = type;
|
this.type = type.toLowerCase();
|
||||||
}
|
}
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
|
|||||||
@ -95,7 +95,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|||||||
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
|
//TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()"
|
||||||
String type = null;
|
String type = null;
|
||||||
if (deviceIds.size() > 0) {
|
if (deviceIds.size() > 0) {
|
||||||
type = deviceIds.get(0).getType();
|
type = deviceIds.get(0).getType().toLowerCase();
|
||||||
}
|
}
|
||||||
Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
|
Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
|
||||||
addOperation(type, operation, deviceIds);
|
addOperation(type, operation, deviceIds);
|
||||||
|
|||||||
@ -121,8 +121,8 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
notificationStrategy.execute(new NotificationContext(deviceId, operation));
|
notificationStrategy.execute(new NotificationContext(deviceId, operation));
|
||||||
} catch (PushNotificationExecutionFailedException e) {
|
} catch (PushNotificationExecutionFailedException e) {
|
||||||
log.error("Error occurred while sending push notifications to " +
|
log.error("Error occurred while sending push notifications to " +
|
||||||
deviceId.getType() + " device carrying id '" +
|
deviceId.getType() + " device carrying id '" +
|
||||||
deviceId + "'", e);
|
deviceId + "'", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
return deviceDAO.getDevice(deviceId, tenantId);
|
return deviceDAO.getDevice(deviceId, tenantId);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new OperationManagementException("Error occurred while opening a connection the data " +
|
throw new OperationManagementException("Error occurred while opening a connection the data " +
|
||||||
"source", e);
|
"source", e);
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
OperationManagementDAOFactory.rollbackTransaction();
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
throw new OperationManagementException(
|
throw new OperationManagementException(
|
||||||
@ -209,44 +209,49 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
throw new UnauthorizedDeviceAccessException("User '" + getUser() + "' is not authorized to " +
|
throw new UnauthorizedDeviceAccessException("User '" + getUser() + "' is not authorized to " +
|
||||||
"fetch operations on device '" + deviceId.getId() + "'");
|
"fetch operations on device '" + deviceId.getId() + "'");
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
try {
|
|
||||||
DeviceManagementDAOFactory.openConnection();
|
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
if (enrolmentId < 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
OperationManagementDAOFactory.openConnection();
|
|
||||||
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
|
|
||||||
operationDAO.getOperationsForDevice(enrolmentId);
|
|
||||||
|
|
||||||
operations = new ArrayList<>();
|
|
||||||
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
|
|
||||||
Operation operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
||||||
operations.add(operation);
|
|
||||||
}
|
|
||||||
} catch (OperationManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
||||||
"operations assigned for '" + deviceId.getType() +
|
|
||||||
"' device '" + deviceId.getId() + "'", e);
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving metadata of '" +
|
|
||||||
deviceId.getType() + "' device carrying the identifier '" +
|
|
||||||
deviceId.getId() + "'");
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementException(
|
|
||||||
"Error occurred while opening a connection to the data source", e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
} catch (DeviceAccessAuthorizationException e) {
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
|
||||||
this.getUser(), e);
|
this.getUser(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving metadata of '" +
|
||||||
|
deviceId.getType() + "' device carrying the identifier '" +
|
||||||
|
deviceId.getId() + "'");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while opening a connection to the data source", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (enrolmentId < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
OperationManagementDAOFactory.openConnection();
|
||||||
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
|
||||||
|
operationDAO.getOperationsForDevice(enrolmentId);
|
||||||
|
|
||||||
|
operations = new ArrayList<>();
|
||||||
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
|
||||||
|
Operation operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||||
|
operations.add(operation);
|
||||||
|
}
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
||||||
|
"operations assigned for '" + deviceId.getType() +
|
||||||
|
"' device '" + deviceId.getId() + "'", e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while opening a connection to the data source", e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,55 +264,59 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
try {
|
try {
|
||||||
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
||||||
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
||||||
if (isUserAuthorized) {
|
if (!isUserAuthorized) {
|
||||||
try {
|
log.error("User : " + getUser() + " is not authorized to fetch operations on device : " +
|
||||||
try {
|
deviceId.getId());
|
||||||
DeviceManagementDAOFactory.openConnection();
|
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
OperationManagementDAOFactory.openConnection();
|
|
||||||
if (enrolmentId < 0) {
|
|
||||||
throw new OperationManagementException("Device not found for given device " +
|
|
||||||
"Identifier:" + deviceId.getId() + " and given type" +
|
|
||||||
deviceId.getType());
|
|
||||||
}
|
|
||||||
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
|
|
||||||
operationDAO.getOperationsForDevice(enrolmentId, request);
|
|
||||||
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
|
|
||||||
Operation operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
||||||
operations.add(operation);
|
|
||||||
}
|
|
||||||
paginationResult = new PaginationResult();
|
|
||||||
int count = operationDAO.getOperationCountForDevice(enrolmentId);
|
|
||||||
paginationResult.setData(operations);
|
|
||||||
paginationResult.setRecordsTotal(count);
|
|
||||||
paginationResult.setRecordsFiltered(count);
|
|
||||||
} catch (OperationManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
||||||
"operations assigned for '" + deviceId.getType() +
|
|
||||||
"' device '" + deviceId.getId() + "'", e);
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving metadata of '" +
|
|
||||||
deviceId.getType() + "' device carrying the identifier '" +
|
|
||||||
deviceId.getId() + "'");
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementException(
|
|
||||||
"Error occurred while opening a connection to the data source", e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.info("User : " + getUser() + " is not authorized to fetch operations on device : " + deviceId.getId());
|
|
||||||
}
|
}
|
||||||
} catch (DeviceAccessAuthorizationException e) {
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
|
||||||
this.getUser(), e);
|
this.getUser(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while opening a connection to the data source", e);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving metadata of '" +
|
||||||
|
deviceId.getType() + "' device carrying the identifier '" +
|
||||||
|
deviceId.getId() + "'");
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
OperationManagementDAOFactory.openConnection();
|
||||||
|
if (enrolmentId < 0) {
|
||||||
|
throw new OperationManagementException("Device not found for given device " +
|
||||||
|
"Identifier:" + deviceId.getId() + " and given type" +
|
||||||
|
deviceId.getType());
|
||||||
|
}
|
||||||
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
|
||||||
|
operationDAO.getOperationsForDevice(enrolmentId, request);
|
||||||
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
|
||||||
|
Operation operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||||
|
operations.add(operation);
|
||||||
|
}
|
||||||
|
paginationResult = new PaginationResult();
|
||||||
|
int count = operationDAO.getOperationCountForDevice(enrolmentId);
|
||||||
|
paginationResult.setData(operations);
|
||||||
|
paginationResult.setRecordsTotal(count);
|
||||||
|
paginationResult.setRecordsFiltered(count);
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
||||||
|
"operations assigned for '" + deviceId.getType() +
|
||||||
|
"' device '" + deviceId.getId() + "'", e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while opening a connection to the data source", e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
return paginationResult;
|
return paginationResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,57 +332,61 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
try {
|
try {
|
||||||
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
||||||
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
||||||
if (isUserAuthorized) {
|
if (!isUserAuthorized) {
|
||||||
try {
|
log.error("User : " + getUser() + " is not authorized to fetch operations on device : "
|
||||||
try {
|
|
||||||
DeviceManagementDAOFactory.openConnection();
|
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
OperationManagementDAOFactory.openConnection();
|
|
||||||
if (enrolmentId < 0) {
|
|
||||||
throw new OperationManagementException("Device not found for the given device Identifier:" +
|
|
||||||
deviceId.getId() + " and given type:" +
|
|
||||||
deviceId.getType());
|
|
||||||
}
|
|
||||||
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(
|
|
||||||
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(
|
|
||||||
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(
|
|
||||||
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(
|
|
||||||
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
Operation operation;
|
|
||||||
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
||||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
||||||
operations.add(operation);
|
|
||||||
}
|
|
||||||
Collections.sort(operations, new OperationCreateTimeComparator());
|
|
||||||
} catch (OperationManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
||||||
"pending operations assigned for '" + deviceId.getType() +
|
|
||||||
"' device '" + deviceId.getId() + "'", e);
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
||||||
"for device Identifier type -'" + deviceId.getType() +
|
|
||||||
"' and device Id '" + deviceId.getId() + "'", e);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementException(
|
|
||||||
"Error occurred while opening a connection to the data source", e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
|
|
||||||
+ deviceId.getId());
|
+ deviceId.getId());
|
||||||
}
|
}
|
||||||
} catch (DeviceAccessAuthorizationException e) {
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
||||||
this.getUser(), e);
|
this.getUser(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while opening a connection to the data source", e);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
||||||
|
"for device Identifier type -'" + deviceId.getType() +
|
||||||
|
"' and device Id '" + deviceId.getId() + "'", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
OperationManagementDAOFactory.openConnection();
|
||||||
|
if (enrolmentId < 0) {
|
||||||
|
throw new OperationManagementException("Device not found for the given device Identifier:" +
|
||||||
|
deviceId.getId() + " and given type:" +
|
||||||
|
deviceId.getType());
|
||||||
|
}
|
||||||
|
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(
|
||||||
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(
|
||||||
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(
|
||||||
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(
|
||||||
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
Operation operation;
|
||||||
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
||||||
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||||
|
operations.add(operation);
|
||||||
|
}
|
||||||
|
Collections.sort(operations, new OperationCreateTimeComparator());
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
||||||
|
"pending operations assigned for '" + deviceId.getType() +
|
||||||
|
"' device '" + deviceId.getId() + "'", e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while opening a connection to the data source", e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,63 +400,67 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
try {
|
try {
|
||||||
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
||||||
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
||||||
if (isUserAuthorized) {
|
if (!isUserAuthorized) {
|
||||||
try {
|
log.error("User : " + getUser() + " is not authorized to fetch operations on device : "
|
||||||
try {
|
|
||||||
DeviceManagementDAOFactory.openConnection();
|
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
OperationManagementDAOFactory.openConnection();
|
|
||||||
if (enrolmentId < 0) {
|
|
||||||
throw new OperationManagementException("Device not found for given device " +
|
|
||||||
"Identifier:" + deviceId.getId() + " and given type" +
|
|
||||||
deviceId.getType());
|
|
||||||
}
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
|
|
||||||
getNextOperation(enrolmentId);
|
|
||||||
if (dtoOperation != null) {
|
|
||||||
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND.
|
|
||||||
equals(dtoOperation.getType())) {
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
|
|
||||||
commandOperation =
|
|
||||||
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
|
|
||||||
getOperation(dtoOperation.getId());
|
|
||||||
dtoOperation.setEnabled(commandOperation.isEnabled());
|
|
||||||
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG.
|
|
||||||
equals(dtoOperation.getType())) {
|
|
||||||
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
|
||||||
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE.
|
|
||||||
equals(dtoOperation.getType())) {
|
|
||||||
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
|
||||||
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY.
|
|
||||||
equals(dtoOperation.getType())) {
|
|
||||||
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
|
||||||
}
|
|
||||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
||||||
}
|
|
||||||
} catch (OperationManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
||||||
"for device Identifier type -'" + deviceId.getType() +
|
|
||||||
"' and device Id '" + deviceId.getId(), e);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementException(
|
|
||||||
"Error occurred while opening a connection to the data source", e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
|
|
||||||
+ deviceId.getId());
|
+ deviceId.getId());
|
||||||
}
|
}
|
||||||
} catch (DeviceAccessAuthorizationException e) {
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
|
||||||
this.getUser(), e);
|
this.getUser(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
||||||
|
"for device Identifier type -'" + deviceId.getType() +
|
||||||
|
"' and device Id '" + deviceId.getId(), e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while opening a connection to the data source", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
OperationManagementDAOFactory.openConnection();
|
||||||
|
if (enrolmentId < 0) {
|
||||||
|
throw new OperationManagementException("Device not found for given device " +
|
||||||
|
"Identifier:" + deviceId.getId() + " and given type" +
|
||||||
|
deviceId.getType());
|
||||||
|
}
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
|
||||||
|
getNextOperation(enrolmentId);
|
||||||
|
if (dtoOperation != null) {
|
||||||
|
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND.
|
||||||
|
equals(dtoOperation.getType())) {
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
|
||||||
|
commandOperation =
|
||||||
|
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
|
||||||
|
getOperation(dtoOperation.getId());
|
||||||
|
dtoOperation.setEnabled(commandOperation.isEnabled());
|
||||||
|
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG.
|
||||||
|
equals(dtoOperation.getType())) {
|
||||||
|
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE.
|
||||||
|
equals(dtoOperation.getType())) {
|
||||||
|
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY.
|
||||||
|
equals(dtoOperation.getType())) {
|
||||||
|
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
}
|
||||||
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||||
|
}
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while opening a connection to the data source", e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,52 +474,53 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
try {
|
try {
|
||||||
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
||||||
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
||||||
if (isUserAuthorized) {
|
if (!isUserAuthorized) {
|
||||||
try {
|
log.error("User : " + getUser() + " is not authorized to update operations on device : "
|
||||||
try {
|
|
||||||
DeviceManagementDAOFactory.openConnection();
|
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while opening a connection to the" +
|
|
||||||
" data source", e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
OperationManagementDAOFactory.beginTransaction();
|
|
||||||
boolean isUpdated = false;
|
|
||||||
if (operation.getStatus() != null) {
|
|
||||||
isUpdated = operationDAO.updateOperationStatus(enrolmentId, operationId,
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.
|
|
||||||
valueOf(operation.getStatus().toString()));
|
|
||||||
}
|
|
||||||
if (isUpdated && operation.getOperationResponse() != null) {
|
|
||||||
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
|
|
||||||
}
|
|
||||||
OperationManagementDAOFactory.commitTransaction();
|
|
||||||
} catch (OperationManagementDAOException e) {
|
|
||||||
OperationManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new OperationManagementException(
|
|
||||||
"Error occurred while updating the operation: " + operationId + " status:" +
|
|
||||||
operation.getStatus(), e);
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
OperationManagementDAOFactory.rollbackTransaction();
|
|
||||||
throw new OperationManagementException(
|
|
||||||
"Error occurred while fetching the device for device identifier: " + deviceId.getId() +
|
|
||||||
"type:" + deviceId.getType(), e);
|
|
||||||
} catch (TransactionManagementException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while initiating a transaction", e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.info("User : " + getUser() + " is not authorized to update operations on device : "
|
|
||||||
+ deviceId.getId());
|
+ deviceId.getId());
|
||||||
}
|
}
|
||||||
} catch (DeviceAccessAuthorizationException e) {
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
||||||
this.getUser(), e);
|
this.getUser(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while opening a connection to the" +
|
||||||
|
" data source", e);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while fetching the device for device identifier: " + deviceId.getId() +
|
||||||
|
"type:" + deviceId.getType(), e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
OperationManagementDAOFactory.beginTransaction();
|
||||||
|
boolean isUpdated = false;
|
||||||
|
if (operation.getStatus() != null) {
|
||||||
|
isUpdated = operationDAO.updateOperationStatus(enrolmentId, operationId,
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.
|
||||||
|
valueOf(operation.getStatus().toString()));
|
||||||
|
}
|
||||||
|
if (isUpdated && operation.getOperationResponse() != null) {
|
||||||
|
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
|
||||||
|
}
|
||||||
|
OperationManagementDAOFactory.commitTransaction();
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
OperationManagementDAOFactory.rollbackTransaction();
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while updating the operation: " + operationId + " status:" +
|
||||||
|
operation.getStatus(), e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while initiating a transaction", e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -538,68 +556,72 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
try {
|
try {
|
||||||
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
||||||
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
||||||
if (isUserAuthorized) {
|
if (!isUserAuthorized) {
|
||||||
try {
|
log.error("User : " + getUser() + " is not authorized to fetch operations on device : "
|
||||||
try {
|
|
||||||
DeviceManagementDAOFactory.openConnection();
|
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
OperationManagementDAOFactory.openConnection();
|
|
||||||
if (enrolmentId < 0) {
|
|
||||||
throw new OperationManagementException("Device not found for given device identifier: " +
|
|
||||||
deviceId.getId() + " type: " + deviceId.getType());
|
|
||||||
}
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
|
|
||||||
getOperationByDeviceAndId(enrolmentId, operationId);
|
|
||||||
if (dtoOperation.getType().
|
|
||||||
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
|
|
||||||
commandOperation =
|
|
||||||
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
|
|
||||||
getOperation(dtoOperation.getId());
|
|
||||||
dtoOperation.setEnabled(commandOperation.isEnabled());
|
|
||||||
} else if (dtoOperation.getType().
|
|
||||||
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
|
|
||||||
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
|
||||||
} else if (dtoOperation.getType().equals(
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE)) {
|
|
||||||
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
|
||||||
} else if (dtoOperation.getType().equals(
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY)) {
|
|
||||||
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dtoOperation == null) {
|
|
||||||
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
|
|
||||||
" device id:" + deviceId.getId());
|
|
||||||
}
|
|
||||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
||||||
} catch (OperationManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
||||||
"operations assigned for '" + deviceId.getType() +
|
|
||||||
"' device '" + deviceId.getId() + "'", e);
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
||||||
"for device Identifier type -'" + deviceId.getType() +
|
|
||||||
"' and device Id '" + deviceId.getId() + "'", e);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while opening connection to the data source",
|
|
||||||
e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
|
|
||||||
+ deviceId.getId());
|
+ deviceId.getId());
|
||||||
}
|
}
|
||||||
} catch (DeviceAccessAuthorizationException e) {
|
} catch (DeviceAccessAuthorizationException e) {
|
||||||
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
||||||
this.getUser(), e);
|
this.getUser(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
||||||
|
"for device Identifier type -'" + deviceId.getType() +
|
||||||
|
"' and device Id '" + deviceId.getId() + "'", e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while opening connection to the data source",
|
||||||
|
e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
OperationManagementDAOFactory.openConnection();
|
||||||
|
if (enrolmentId < 0) {
|
||||||
|
throw new OperationManagementException("Device not found for given device identifier: " +
|
||||||
|
deviceId.getId() + " type: " + deviceId.getType());
|
||||||
|
}
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
|
||||||
|
getOperationByDeviceAndId(enrolmentId, operationId);
|
||||||
|
if (dtoOperation.getType().
|
||||||
|
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
|
||||||
|
commandOperation =
|
||||||
|
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
|
||||||
|
getOperation(dtoOperation.getId());
|
||||||
|
dtoOperation.setEnabled(commandOperation.isEnabled());
|
||||||
|
} else if (dtoOperation.getType().
|
||||||
|
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
|
||||||
|
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
} else if (dtoOperation.getType().equals(
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE)) {
|
||||||
|
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
} else if (dtoOperation.getType().equals(
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY)) {
|
||||||
|
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dtoOperation == null) {
|
||||||
|
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
|
||||||
|
" device id:" + deviceId.getId());
|
||||||
|
}
|
||||||
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
||||||
|
"operations assigned for '" + deviceId.getType() +
|
||||||
|
"' device '" + deviceId.getId() + "'", e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while opening connection to the data source",
|
||||||
|
e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,56 +634,7 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
try {
|
try {
|
||||||
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
||||||
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
isUserAuthorized(deviceId, DeviceGroupConstants.Permissions.DEFAULT_OPERATOR_PERMISSIONS);
|
||||||
if (isUserAuthorized) {
|
if (!isUserAuthorized) {
|
||||||
try {
|
|
||||||
try {
|
|
||||||
DeviceManagementDAOFactory.openConnection();
|
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
OperationManagementDAOFactory.openConnection();
|
|
||||||
|
|
||||||
if (enrolmentId < 0) {
|
|
||||||
throw new OperationManagementException(
|
|
||||||
"Device not found for device id:" + deviceId.getId() + " " + "type:" +
|
|
||||||
deviceId.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status dtoOpStatus =
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.toString());
|
|
||||||
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus));
|
|
||||||
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
|
||||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
||||||
|
|
||||||
Operation operation;
|
|
||||||
|
|
||||||
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
||||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
||||||
operations.add(operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (OperationManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
||||||
"operations assigned for '" + deviceId.getType() +
|
|
||||||
"' device '" +
|
|
||||||
deviceId.getId() + "' and status:" + status.toString(), e);
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
|
||||||
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
||||||
"for device Identifier type -'" + deviceId.getType() +
|
|
||||||
"' and device Id '" + deviceId.getId(), e);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementException(
|
|
||||||
"Error occurred while opening a connection to the data source", e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOFactory.closeConnection();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
|
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
|
||||||
+ deviceId.getId());
|
+ deviceId.getId());
|
||||||
}
|
}
|
||||||
@ -669,6 +642,59 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
||||||
this.getUser(), e);
|
this.getUser(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
||||||
|
"for device Identifier type -'" + deviceId.getType() +
|
||||||
|
"' and device Id '" + deviceId.getId(), e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while opening a connection to the data source", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
OperationManagementDAOFactory.openConnection();
|
||||||
|
|
||||||
|
if (enrolmentId < 0) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Device not found for device id:" + deviceId.getId() + " " + "type:" +
|
||||||
|
deviceId.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status dtoOpStatus =
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.toString());
|
||||||
|
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus));
|
||||||
|
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||||
|
|
||||||
|
Operation operation;
|
||||||
|
|
||||||
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
||||||
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||||
|
operations.add(operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (OperationManagementDAOException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
||||||
|
"operations assigned for '" + deviceId.getType() +
|
||||||
|
"' device '" +
|
||||||
|
deviceId.getId() + "' and status:" + status.toString(), e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new OperationManagementException(
|
||||||
|
"Error occurred while opening a connection to the data source", e);
|
||||||
|
} finally {
|
||||||
|
OperationManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -809,7 +835,8 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException {
|
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit,
|
||||||
|
int offset) throws OperationManagementException {
|
||||||
try {
|
try {
|
||||||
OperationManagementDAOFactory.openConnection();
|
OperationManagementDAOFactory.openConnection();
|
||||||
return operationDAO.getActivitiesUpdatedAfter(timestamp, limit, offset);
|
return operationDAO.getActivitiesUpdatedAfter(timestamp, limit, offset);
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.search.util;
|
package org.wso2.carbon.device.mgt.core.search.util;
|
||||||
|
|
||||||
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.device.details.DeviceInfo;
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
||||||
|
|||||||
@ -111,6 +111,14 @@
|
|||||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||||
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
|
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.apimgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.apimgt.api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.apimgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.apimgt.impl</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -148,7 +156,8 @@
|
|||||||
javax.xml.*;resolution:=optional,
|
javax.xml.*;resolution:=optional,
|
||||||
org.apache.commons.lang,
|
org.apache.commons.lang,
|
||||||
javax.ws.rs;version="0.0.0";resolution:=optional,
|
javax.ws.rs;version="0.0.0";resolution:=optional,
|
||||||
org.scannotation
|
org.scannotation,
|
||||||
|
org.scannotation.archiveiterator
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@ -38,11 +38,14 @@ import javax.ws.rs.PUT;
|
|||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
@ -80,14 +83,13 @@ public class AnnotationProcessor {
|
|||||||
* Scan the context for classes with annotations
|
* Scan the context for classes with annotations
|
||||||
*/
|
*/
|
||||||
public Set<String> scanStandardContext(String className) throws IOException {
|
public Set<String> scanStandardContext(String className) throws IOException {
|
||||||
AnnotationDB db = new AnnotationDB();
|
ExtendedAnnotationDB db = new ExtendedAnnotationDB();
|
||||||
db.addIgnoredPackages(PACKAGE_ORG_APACHE);
|
db.addIgnoredPackages(PACKAGE_ORG_APACHE);
|
||||||
db.addIgnoredPackages(PACKAGE_ORG_CODEHAUS);
|
db.addIgnoredPackages(PACKAGE_ORG_CODEHAUS);
|
||||||
db.addIgnoredPackages(PACKAGE_ORG_SPRINGFRAMEWORK);
|
db.addIgnoredPackages(PACKAGE_ORG_SPRINGFRAMEWORK);
|
||||||
URL[] libPath = WarUrlFinder.findWebInfLibClasspaths(servletContext);
|
|
||||||
URL classPath = WarUrlFinder.findWebInfClassesPath(servletContext);
|
URL classPath = findWebInfClassesPath(servletContext);
|
||||||
URL[] urls = (URL[]) ArrayUtils.add(libPath, libPath.length, classPath);
|
db.scanArchives(classPath);
|
||||||
db.scanArchives(urls);
|
|
||||||
|
|
||||||
//Returns a list of classes with given Annotation
|
//Returns a list of classes with given Annotation
|
||||||
return db.getAnnotationIndex().get(className);
|
return db.getAnnotationIndex().get(className);
|
||||||
@ -276,4 +278,28 @@ public class AnnotationProcessor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory
|
||||||
|
* if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
|
||||||
|
*
|
||||||
|
* @param servletContext
|
||||||
|
* @return null if cannot determin /WEB-INF/classes
|
||||||
|
*/
|
||||||
|
public static URL findWebInfClassesPath(ServletContext servletContext)
|
||||||
|
{
|
||||||
|
String path = servletContext.getRealPath("/WEB-INF/classes");
|
||||||
|
if (path == null) return null;
|
||||||
|
File fp = new File(path);
|
||||||
|
if (fp.exists() == false) return null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
URI uri = fp.toURI();
|
||||||
|
return uri.toURL();
|
||||||
|
}
|
||||||
|
catch (MalformedURLException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.extensions.feature.mgt.util;
|
||||||
|
|
||||||
|
import org.scannotation.AnnotationDB;
|
||||||
|
import org.scannotation.archiveiterator.Filter;
|
||||||
|
import org.scannotation.archiveiterator.StreamIterator;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class ExtendedAnnotationDB extends AnnotationDB {
|
||||||
|
|
||||||
|
public ExtendedAnnotationDB() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void scanArchives(URL... urls) throws IOException {
|
||||||
|
URL[] arr$ = urls;
|
||||||
|
int len$ = urls.length;
|
||||||
|
|
||||||
|
for(int i$ = 0; i$ < len$; ++i$) {
|
||||||
|
URL url = arr$[i$];
|
||||||
|
Filter filter = new Filter() {
|
||||||
|
public boolean accepts(String filename) {
|
||||||
|
if(filename.endsWith(".class")) {
|
||||||
|
if(filename.startsWith("/") || filename.startsWith("\\")) {
|
||||||
|
filename = filename.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!ExtendedAnnotationDB.this.ignoreScan(filename.replace('/', '.'))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
StreamIterator it = ExtendedIteratorFactory.create(url, filter);
|
||||||
|
|
||||||
|
InputStream stream;
|
||||||
|
while((stream = it.next()) != null) {
|
||||||
|
this.scanClass(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean ignoreScan(String intf) {
|
||||||
|
String[] arr$;
|
||||||
|
int len$;
|
||||||
|
int i$;
|
||||||
|
String ignored;
|
||||||
|
if(this.scanPackages != null) {
|
||||||
|
arr$ = this.scanPackages;
|
||||||
|
len$ = arr$.length;
|
||||||
|
|
||||||
|
for(i$ = 0; i$ < len$; ++i$) {
|
||||||
|
ignored = arr$[i$];
|
||||||
|
if(intf.startsWith(ignored + ".")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
arr$ = this.ignoredPackages;
|
||||||
|
len$ = arr$.length;
|
||||||
|
|
||||||
|
for(i$ = 0; i$ < len$; ++i$) {
|
||||||
|
ignored = arr$[i$];
|
||||||
|
if(intf.startsWith(ignored + ".")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.extensions.feature.mgt.util;
|
||||||
|
|
||||||
|
import org.scannotation.archiveiterator.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class ExtendedFileProtocolIteratorFactory implements DirectoryIteratorFactory {
|
||||||
|
|
||||||
|
private static final String ENCODING_SCHEME = "UTF-8";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StreamIterator create(URL url, Filter filter) throws IOException {
|
||||||
|
File f = new File(java.net.URLDecoder.decode(url.getPath(), ENCODING_SCHEME));
|
||||||
|
return f.isDirectory()?new FileIterator(f, filter):new JarIterator(url.openStream(), filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.extensions.feature.mgt.util;
|
||||||
|
|
||||||
|
import org.scannotation.archiveiterator.DirectoryIteratorFactory;
|
||||||
|
import org.scannotation.archiveiterator.Filter;
|
||||||
|
import org.scannotation.archiveiterator.JarIterator;
|
||||||
|
import org.scannotation.archiveiterator.StreamIterator;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class ExtendedIteratorFactory {
|
||||||
|
|
||||||
|
private static final ConcurrentHashMap<String, DirectoryIteratorFactory> registry = new ConcurrentHashMap();
|
||||||
|
|
||||||
|
public static StreamIterator create(URL url, Filter filter) throws IOException {
|
||||||
|
String urlString = url.toString();
|
||||||
|
if(urlString.endsWith("!/")) {
|
||||||
|
urlString = urlString.substring(4);
|
||||||
|
urlString = urlString.substring(0, urlString.length() - 2);
|
||||||
|
url = new URL(urlString);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!urlString.endsWith("/")) {
|
||||||
|
return new JarIterator(url.openStream(), filter);
|
||||||
|
} else {
|
||||||
|
DirectoryIteratorFactory factory = registry.get(url.getProtocol());
|
||||||
|
if(factory == null) {
|
||||||
|
throw new IOException("Unable to scan directory of protocol: " + url.getProtocol());
|
||||||
|
} else {
|
||||||
|
return factory.create(url, filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
registry.put("file", new ExtendedFileProtocolIteratorFactory());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,27 +22,24 @@ var log = new Log("api/data-tables-invoker-api.jag");
|
|||||||
var uri = request.getRequestURI();
|
var uri = request.getRequestURI();
|
||||||
var uriMatcher = new URIMatcher(String(uri));
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
var devicemgtProps = require("/app/conf/devicemgt-props.js").config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
||||||
|
|
||||||
|
function appendQueryParam (url, queryParam , value) {
|
||||||
|
if (url.indexOf("?") > 0) {
|
||||||
|
return url + "&" + queryParam + "=" + value;
|
||||||
|
}
|
||||||
|
return url + "?" + queryParam + "=" + value;
|
||||||
|
}
|
||||||
|
|
||||||
if (uriMatcher.match("/{context}/api/data-tables/invoker")) {
|
if (uriMatcher.match("/{context}/api/data-tables/invoker")) {
|
||||||
var url = request.getParameter("url");
|
var url = request.getParameter("url");
|
||||||
var targetURL;
|
var targetURL = devicemgtProps["httpsURL"] + request.getParameter("url");
|
||||||
var payload = request.getContent();
|
|
||||||
|
|
||||||
function appendQueryParam (url, queryParam , value) {
|
|
||||||
if (url.indexOf("?") > 0) {
|
|
||||||
return url + "&" + queryParam + "=" + value;
|
|
||||||
}
|
|
||||||
return url + "?" + queryParam + "=" + value;
|
|
||||||
}
|
|
||||||
targetURL = devicemgtProps["httpsURL"] + request.getParameter("url");
|
|
||||||
|
|
||||||
var allParams = request.getAllParameters();
|
var allParams = request.getAllParameters();
|
||||||
|
|
||||||
for (var key in allParams) {
|
for (var key in allParams) {
|
||||||
if (allParams.hasOwnProperty(key)) {
|
if (allParams.hasOwnProperty(key)) {
|
||||||
if(key == "limit" || key == "offset" || key == "filter"){
|
if (key == "limit" || key == "offset" || key == "filter") {
|
||||||
targetURL = appendQueryParam(targetURL, key, allParams[key]);
|
targetURL = appendQueryParam(targetURL, key, allParams[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ var log = new Log("api/device-api.jag");
|
|||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var deviceModule = require("/app/modules/device.js").deviceModule;
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
var utility = require("/app/modules/utility.js").utility;
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var userModule = require("/app/modules/user.js").userModule;
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ var uriMatcher = new URIMatcher(String(uri));
|
|||||||
var log = new Log("api/device-api.jag");
|
var log = new Log("api/device-api.jag");
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var utility = require("/app/modules/utility.js").utility;
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
var user = session.get(constants.USER_SESSION_KEY);
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
|
|||||||
@ -23,7 +23,7 @@ var uri = request.getRequestURI();
|
|||||||
var uriMatcher = new URIMatcher(String(uri));
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
|
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
||||||
|
|
||||||
if (uriMatcher.match("/{context}/api/invoker/execute/")) {
|
if (uriMatcher.match("/{context}/api/invoker/execute/")) {
|
||||||
|
|||||||
@ -23,7 +23,7 @@ var uriMatcher = new URIMatcher(String(uri));
|
|||||||
var log = new Log("api/operation-api.jag");
|
var log = new Log("api/operation-api.jag");
|
||||||
|
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
|
|
||||||
if (uriMatcher.match("/{context}/api/operation/paginate")) {
|
if (uriMatcher.match("/{context}/api/operation/paginate")) {
|
||||||
var deviceType = request.getParameter("deviceType");
|
var deviceType = request.getParameter("deviceType");
|
||||||
|
|||||||
@ -16,7 +16,12 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
var apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
|
||||||
var tokenCookie = apiWrapperUtil.refreshToken();
|
/*
|
||||||
print(tokenCookie);
|
@Deprecated - new
|
||||||
|
*/
|
||||||
|
|
||||||
|
// var apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
||||||
|
// var tokenCookie = apiWrapperUtil.refreshToken();
|
||||||
|
// print(tokenCookie);
|
||||||
%>
|
%>
|
||||||
@ -23,7 +23,7 @@ var uriMatcher = new URIMatcher(String(uri));
|
|||||||
var log = new Log("api/user-api.jag");
|
var log = new Log("api/user-api.jag");
|
||||||
|
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var userModule = require("/app/modules/user.js").userModule;
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
var deviceModule = require("/app/modules/device.js").deviceModule;
|
var deviceModule = require("/app/modules/device.js").deviceModule;
|
||||||
var utility = require("/app/modules/utility.js").utility;
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
|
|||||||
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var config = function () {
|
|
||||||
var conf = application.get("PINCH_CONFIG");
|
|
||||||
if (!conf) {
|
|
||||||
var pinch = require('/app/modules/pinch.min.js').pinch;
|
|
||||||
var server = require('carbon').server;
|
|
||||||
var config = require('/app/conf/config.json');
|
|
||||||
pinch(config, /^/, function (path, key, value) {
|
|
||||||
if ((typeof value === 'string') && value.indexOf('%https.ip%') > -1) {
|
|
||||||
return value.replace('%https.ip%', server.address("https"));
|
|
||||||
} else if ((typeof value === 'string') && value.indexOf('%http.ip%') > -1) {
|
|
||||||
return value.replace('%http.ip%', server.address("http"));
|
|
||||||
} else if ((typeof value === 'string') && value.indexOf('%date-year%') > -1) {
|
|
||||||
var year = new Date().getFullYear();
|
|
||||||
return value.replace("%date-year%", year);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
});
|
|
||||||
application.put("PINCH_CONFIG", config);
|
|
||||||
conf = config;
|
|
||||||
}
|
|
||||||
return conf;
|
|
||||||
};
|
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var conf = function () {
|
||||||
|
var conf = application.get("UI_CONF");
|
||||||
|
if (!conf) {
|
||||||
|
conf = require("/app/conf/config.json");
|
||||||
|
var pinch = require("/app/conf/reader/pinch.min.js")["pinch"];
|
||||||
|
var server = require("carbon")["server"];
|
||||||
|
pinch(conf, /^/,
|
||||||
|
function (path, key, value) {
|
||||||
|
if ((typeof value === "string") && value.indexOf("%https.ip%") > -1) {
|
||||||
|
return value.replace("%https.ip%", server.address("https"));
|
||||||
|
} else if ((typeof value === "string") && value.indexOf("%http.ip%") > -1) {
|
||||||
|
return value.replace("%http.ip%", server.address("http"));
|
||||||
|
} else if ((typeof value === "string") && value.indexOf("%date-year%") > -1) {
|
||||||
|
var year = new Date().getFullYear();
|
||||||
|
return value.replace("%date-year%", year);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
application.put("UI_CONF", conf);
|
||||||
|
}
|
||||||
|
return conf;
|
||||||
|
}();
|
||||||
@ -1,64 +1,76 @@
|
|||||||
|
{{!-- 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. --}}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
{{defineZone "favicon"}}
|
||||||
<title>{{#defineZone "title"}}WSO2 Template{{/defineZone}}</title>
|
<title>
|
||||||
{{defineZone "favicon"}}
|
{{defineZone "title"}}
|
||||||
{{defineZone "topCss"}}
|
</title>
|
||||||
{{defineZone "topJs"}}
|
{{defineZone "topLibCss"}}
|
||||||
</head>
|
{{defineZone "topCss"}}
|
||||||
<body>
|
{{defineZone "topJs"}}
|
||||||
|
</head>
|
||||||
<!--modal-->
|
<body>
|
||||||
<div class="wr-modalpopup">
|
<!--modal-->
|
||||||
<div class="modalpopup-container">
|
<div class="wr-modalpopup">
|
||||||
<div class="modalpopup-close-btn" onclick="hidePopup();">
|
<div class="modalpopup-container">
|
||||||
<span class="fw-stack">
|
<div class="modalpopup-close-btn" onclick="hidePopup();">
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
<span class="fw-stack">
|
||||||
<i class="fw fw-left-arrow fw-stack-1x"></i>
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
</span>
|
<i class="fw fw-left-arrow fw-stack-1x"></i>
|
||||||
GO BACK
|
</span>
|
||||||
|
GO BACK
|
||||||
|
</div>
|
||||||
|
<div class="modalpopup-content">
|
||||||
|
<!-- dynamic content -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modalpopup-bg"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modalpopup-content"><!-- dynamic content --></div>
|
<!--modal-->
|
||||||
</div>
|
|
||||||
<div class="modalpopup-bg"></div>
|
|
||||||
</div>
|
|
||||||
<!--modal-->
|
|
||||||
|
|
||||||
<!-- header -->
|
{{defineZone "header"}}
|
||||||
{{defineZone "header"}}
|
|
||||||
<!-- /header -->
|
|
||||||
|
|
||||||
<!-- navbars -->
|
<div class="navbar-wrapper">
|
||||||
<div class="navbar-wrapper">
|
{{defineZone "navbars"}}
|
||||||
{{defineZone "navbars"}}
|
</div>
|
||||||
</div>
|
|
||||||
<!-- /navbars -->
|
|
||||||
|
|
||||||
<!-- sidepanes -->
|
{{defineZone "sidePanes"}}
|
||||||
{{defineZone "sidePanes"}}
|
|
||||||
<!-- /sidepanes -->
|
|
||||||
|
|
||||||
<!-- page-content-wrapper -->
|
<!-- page-content-wrapper -->
|
||||||
<div class="page-content-wrapper">
|
<div class="page-content-wrapper">
|
||||||
{{defineZone "contentTitle"}}
|
{{defineZone "contentTitle"}}
|
||||||
<div class="container-fluid body-wrapper">
|
<div class="container-fluid body-wrapper">
|
||||||
{{defineZone "content"}}
|
{{defineZone "content"}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- /page-content-wrapper -->
|
<!-- /page-content-wrapper -->
|
||||||
|
|
||||||
<!-- footer -->
|
<footer class="footer">
|
||||||
<footer class="footer">
|
<div class="container-fluid">
|
||||||
<div class="container-fluid">
|
{{defineZone "footer"}}
|
||||||
{{defineZone "footer"}}
|
</div>
|
||||||
</div>
|
</footer>
|
||||||
</footer>
|
|
||||||
<!-- /footer -->
|
|
||||||
|
|
||||||
{{defineZone "bottomJs"}}
|
{{defineZone "bottomLibJs"}}
|
||||||
</body>
|
{{defineZone "bottomJs"}}
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -1,55 +1,135 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||||
* KIND, either express or implied. See the License for the
|
* either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var apiWrapperUtil = function () {
|
var apiWrapperUtil = function () {
|
||||||
var module = {};
|
|
||||||
var tokenUtil = require("/app/modules/util.js").util;
|
|
||||||
var constants = require("/app/modules/constants.js");
|
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
|
||||||
var log = new Log("/app/modules/api-wrapper-util.js");
|
var log = new Log("/app/modules/api-wrapper-util.js");
|
||||||
|
|
||||||
module.refreshToken = function () {
|
var tokenUtil = require("/app/modules/util.js")["util"];
|
||||||
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
|
var constants = require("/app/modules/constants.js");
|
||||||
var clientData = session.get(constants.ENCODED_CLIENT_KEYS_IDENTIFIER);
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
tokenPair = tokenUtil.refreshToken(tokenPair, clientData);
|
|
||||||
session.put(constants.ACCESS_TOKEN_PAIR_IDENTIFIER, tokenPair);
|
var privateMethods = {};
|
||||||
};
|
var publicMethods = {};
|
||||||
module.setupAccessTokenPair = function (type, properties) {
|
|
||||||
var tokenPair;
|
privateMethods.setUpEncodedTenantBasedClientCredentials = function (username) {
|
||||||
var clientData = tokenUtil.getDyanmicCredentials(properties);
|
if (!username) {
|
||||||
var jwtToken = tokenUtil.getTokenWithJWTGrantType(clientData);
|
log.error("Could not set up encoded tenant based client credentials " +
|
||||||
clientData = tokenUtil.getTenantBasedAppCredentials(properties.username, jwtToken);
|
"to session context. No username is found as input.");
|
||||||
var encodedClientKeys = tokenUtil.encode(clientData.clientId + ":" + clientData.clientSecret);
|
} else {
|
||||||
session.put(constants.ENCODED_CLIENT_KEYS_IDENTIFIER, encodedClientKeys);
|
var dynamicClientCredentials = tokenUtil.getDyanmicClientCredentials();
|
||||||
if (type == constants.GRANT_TYPE_PASSWORD) {
|
if (!dynamicClientCredentials) {
|
||||||
var scopes = devicemgtProps.scopes;
|
log.error("Could not set up encoded tenant based client credentials " +
|
||||||
var scope = "";
|
"to session context as the server is unable to obtain dynamic client credentials.");
|
||||||
scopes.forEach(function(entry) {
|
} else {
|
||||||
scope += entry + " ";
|
var jwtToken = tokenUtil.getTokenWithJWTGrantType(dynamicClientCredentials);
|
||||||
});
|
if (!jwtToken) {
|
||||||
tokenPair =
|
log.error("Could not set up encoded tenant based client credentials " +
|
||||||
tokenUtil.getTokenWithPasswordGrantType(properties.username, encodeURIComponent(properties.password),
|
"to session context as the server is unable to obtain a jwt token.");
|
||||||
encodedClientKeys, scope);
|
} else {
|
||||||
} else if (type == constants.GRANT_TYPE_SAML) {
|
var tenantBasedClientCredentials = tokenUtil.getTenantBasedAppCredentials(username, jwtToken);
|
||||||
tokenPair = tokenUtil.
|
if (!tenantBasedClientCredentials) {
|
||||||
getTokenWithSAMLGrantType(properties.samlToken, encodedClientKeys, "PRODUCTION");
|
log.error("Could not set up encoded tenant based client credentials " +
|
||||||
|
"to session context as the server is unable to obtain such credentials.");
|
||||||
|
} else {
|
||||||
|
var encodedTenantBasedClientCredentials =
|
||||||
|
tokenUtil.encode(tenantBasedClientCredentials["clientId"] + ":" +
|
||||||
|
tenantBasedClientCredentials["clientSecret"]);
|
||||||
|
// setting up encoded tenant based client credentials to session context.
|
||||||
|
session.put(constants["ENCODED_CLIENT_KEYS_IDENTIFIER"], encodedTenantBasedClientCredentials);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
session.put(constants.ACCESS_TOKEN_PAIR_IDENTIFIER, tokenPair);
|
|
||||||
};
|
};
|
||||||
return module;
|
|
||||||
|
publicMethods.refreshToken = function () {
|
||||||
|
var accessTokenPair = parse(session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"]));
|
||||||
|
// accessTokenPair includes current access token as well as current refresh token
|
||||||
|
var encodedClientCredentials = session.get(constants["ENCODED_CLIENT_KEYS_IDENTIFIER"]);
|
||||||
|
if (!accessTokenPair || !encodedClientCredentials) {
|
||||||
|
log.error("Error in refreshing tokens. Either the access token pair, " +
|
||||||
|
"encoded client credentials or both input are not found under session context.");
|
||||||
|
} else {
|
||||||
|
var newAccessTokenPair = tokenUtil.refreshToken(accessTokenPair, encodedClientCredentials);
|
||||||
|
if (!newAccessTokenPair) {
|
||||||
|
log.error("Error in refreshing tokens. Unable to update " +
|
||||||
|
"session context with new access token pair.");
|
||||||
|
} else {
|
||||||
|
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"], stringify(newAccessTokenPair));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.setupAccessTokenPairByPasswordGrantType = function (username, password) {
|
||||||
|
if (!username || !password) {
|
||||||
|
log.error("Could not set up access token pair by password grant type. " +
|
||||||
|
"Either username, password or both are missing as input.");
|
||||||
|
} else {
|
||||||
|
privateMethods.setUpEncodedTenantBasedClientCredentials(username);
|
||||||
|
var encodedClientCredentials = session.get(constants["ENCODED_CLIENT_KEYS_IDENTIFIER"]);
|
||||||
|
if (!encodedClientCredentials) {
|
||||||
|
log.error("Could not set up access token pair by password grant type. " +
|
||||||
|
"Encoded client credentials are missing.");
|
||||||
|
} else {
|
||||||
|
var accessTokenPair;
|
||||||
|
// accessTokenPair will include current access token as well as current refresh token
|
||||||
|
var arrayOfScopes = devicemgtProps["scopes"];
|
||||||
|
var stringOfScopes = "";
|
||||||
|
arrayOfScopes.forEach(function (entry) {
|
||||||
|
stringOfScopes += entry + " ";
|
||||||
|
});
|
||||||
|
accessTokenPair = tokenUtil.
|
||||||
|
getTokenWithPasswordGrantType(username,
|
||||||
|
encodeURIComponent(password), encodedClientCredentials, stringOfScopes);
|
||||||
|
if (!accessTokenPair) {
|
||||||
|
log.error("Could not set up access token pair by password grant type. Error in token retrieval.");
|
||||||
|
} else {
|
||||||
|
// setting up access token pair into session context as a string
|
||||||
|
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"], stringify(accessTokenPair));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
publicMethods.setupAccessTokenPairBySamlGrantType = function (username, samlToken) {
|
||||||
|
if (!username || !samlToken) {
|
||||||
|
log.error("Could not set up access token pair by saml grant type. " +
|
||||||
|
"Either username, samlToken or both are missing as input.");
|
||||||
|
} else {
|
||||||
|
privateMethods.setUpEncodedTenantBasedClientCredentials(username);
|
||||||
|
var encodedClientCredentials = session.get(constants["ENCODED_CLIENT_KEYS_IDENTIFIER"]);
|
||||||
|
if (!encodedClientCredentials) {
|
||||||
|
log.error("Could not set up access token pair by saml grant type. " +
|
||||||
|
"Encoded client credentials are missing.");
|
||||||
|
} else {
|
||||||
|
var accessTokenPair;
|
||||||
|
// accessTokenPair will include current access token as well as current refresh token
|
||||||
|
accessTokenPair = tokenUtil.
|
||||||
|
getTokenWithSAMLGrantType(samlToken, encodedClientCredentials, "PRODUCTION");
|
||||||
|
if (!accessTokenPair) {
|
||||||
|
log.error("Could not set up access token pair by password grant type. Error in token retrieval.");
|
||||||
|
} else {
|
||||||
|
// setting up access token pair into session context as a string
|
||||||
|
session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"], stringify(accessTokenPair));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return publicMethods;
|
||||||
}();
|
}();
|
||||||
@ -31,7 +31,7 @@ var backendServiceInvoker = function () {
|
|||||||
var TOKEN_EXPIRED = "Access token expired";
|
var TOKEN_EXPIRED = "Access token expired";
|
||||||
var TOKEN_INVALID = "Invalid input. Access token validation failed";
|
var TOKEN_INVALID = "Invalid input. Access token validation failed";
|
||||||
|
|
||||||
var devicemgtProps = require("/app/conf/devicemgt-props.js").config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var userModule = require("/app/modules/user.js")["userModule"];
|
var userModule = require("/app/modules/user.js")["userModule"];
|
||||||
var tokenUtil = require("/app/modules/api-wrapper-util.js")["apiWrapperUtil"];
|
var tokenUtil = require("/app/modules/api-wrapper-util.js")["apiWrapperUtil"];
|
||||||
@ -41,7 +41,7 @@ var backendServiceInvoker = function () {
|
|||||||
* If the token pair s not set in the session this will send a redirect to the login page.
|
* If the token pair s not set in the session this will send a redirect to the login page.
|
||||||
*/
|
*/
|
||||||
privateMethods.getAccessToken = function () {
|
privateMethods.getAccessToken = function () {
|
||||||
var tokenPair = session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"]);
|
var tokenPair = parse(session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"]));
|
||||||
if (tokenPair) {
|
if (tokenPair) {
|
||||||
return tokenPair.accessToken;
|
return tokenPair.accessToken;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -22,7 +22,7 @@ deviceModule = function () {
|
|||||||
|
|
||||||
var utility = require('/app/modules/utility.js').utility;
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
var constants = require('/app/modules/constants.js');
|
var constants = require('/app/modules/constants.js');
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
var ArrayList = Packages.java.util.ArrayList;
|
var ArrayList = Packages.java.util.ArrayList;
|
||||||
|
|||||||
@ -22,7 +22,7 @@ var groupModule = {};
|
|||||||
|
|
||||||
var userModule = require("/app/modules/user.js").userModule;
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
var constants = require('/app/modules/constants.js');
|
var constants = require('/app/modules/constants.js');
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var utility = require("/app/modules/utility.js").utility;
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var carbonModule = require("carbon");
|
var carbonModule = require("carbon");
|
||||||
var devicemgtProps = require("/app/conf/devicemgt-props.js").config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var carbonServer = new carbonModule.server.Server({
|
var carbonServer = new carbonModule.server.Server({
|
||||||
tenanted: true,
|
tenanted: true,
|
||||||
url: devicemgtProps["httpsURL"] + "/admin"
|
url: devicemgtProps["httpsURL"] + "/admin"
|
||||||
@ -31,4 +31,4 @@ var permissions = {
|
|||||||
'/permission/admin/device-mgt/user': ['ui.execute'],
|
'/permission/admin/device-mgt/user': ['ui.execute'],
|
||||||
'/permission/admin/manage/api/subscribe': ['ui.execute']
|
'/permission/admin/manage/api/subscribe': ['ui.execute']
|
||||||
};
|
};
|
||||||
userModule.addRole("internal/devicemgt-user", ["admin"], permissions);
|
//userModule.addRole("internal/devicemgt-user", ["admin"], permissions);
|
||||||
|
|||||||
@ -16,79 +16,83 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated - new
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This invokerRequestWrapper contains the wrappers for invoker util requests.
|
* This invokerRequestWrapper contains the wrappers for invoker util requests.
|
||||||
*/
|
*/
|
||||||
var invokerRequestWrapper = function () {
|
//var invokerRequestWrapper = function () {
|
||||||
|
//
|
||||||
var constants = require("/modules/constants.js");
|
// var constants = require("/modules/constants.js");
|
||||||
var serviceInvokers = require("/modules/backend-service-invoker.js").backendServiceInvoker;
|
// var serviceInvokers = require("/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
//
|
||||||
var publicWrappers = [];
|
// var publicWrappers = [];
|
||||||
|
//
|
||||||
publicWrappers.initiate = function (method, url, payload) {
|
// publicWrappers.initiate = function (method, url, payload) {
|
||||||
switch (method) {
|
// switch (method) {
|
||||||
case constants.HTTP_GET:
|
// case constants.HTTP_GET:
|
||||||
var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
// var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
||||||
var response = {};
|
// var response = {};
|
||||||
response.content = responsePayload["responseContent"];
|
// response.content = responsePayload["responseContent"];
|
||||||
response.status = "success";
|
// response.status = "success";
|
||||||
return response;
|
// return response;
|
||||||
},
|
// },
|
||||||
function (responsePayload) {
|
// function (responsePayload) {
|
||||||
var response = {};
|
// var response = {};
|
||||||
response.content = responsePayload;
|
// response.content = responsePayload;
|
||||||
response.status = "error";
|
// response.status = "error";
|
||||||
return response;
|
// return response;
|
||||||
});
|
// });
|
||||||
return response;
|
// return response;
|
||||||
break;
|
// break;
|
||||||
case constants.HTTP_POST:
|
// case constants.HTTP_POST:
|
||||||
var response = serviceInvokers.XMLHttp.post(url, payload, function (responsePayload) {
|
// var response = serviceInvokers.XMLHttp.post(url, payload, function (responsePayload) {
|
||||||
var response = {};
|
// var response = {};
|
||||||
response.content = responsePayload["responseContent"];
|
// response.content = responsePayload["responseContent"];
|
||||||
response.status = "success";
|
// response.status = "success";
|
||||||
return response;
|
// return response;
|
||||||
},
|
// },
|
||||||
function (responsePayload) {
|
// function (responsePayload) {
|
||||||
var response = {};
|
// var response = {};
|
||||||
response.content = responsePayload;
|
// response.content = responsePayload;
|
||||||
response.status = "error";
|
// response.status = "error";
|
||||||
return response;
|
// return response;
|
||||||
});
|
// });
|
||||||
return response;
|
// return response;
|
||||||
break;
|
// break;
|
||||||
case constants.HTTP_PUT:
|
// case constants.HTTP_PUT:
|
||||||
var response = serviceInvokers.XMLHttp.put(url, payload, function (responsePayload) {
|
// var response = serviceInvokers.XMLHttp.put(url, payload, function (responsePayload) {
|
||||||
var response = {};
|
// var response = {};
|
||||||
response.content = responsePayload["responseContent"];
|
// response.content = responsePayload["responseContent"];
|
||||||
response.status = "success";
|
// response.status = "success";
|
||||||
return response;
|
// return response;
|
||||||
},
|
// },
|
||||||
function (responsePayload) {
|
// function (responsePayload) {
|
||||||
var response = {};
|
// var response = {};
|
||||||
response.content = responsePayload;
|
// response.content = responsePayload;
|
||||||
response.status = "error";
|
// response.status = "error";
|
||||||
return response;
|
// return response;
|
||||||
});
|
// });
|
||||||
return response;
|
// return response;
|
||||||
break;
|
// break;
|
||||||
case constants.HTTP_DELETE:
|
// case constants.HTTP_DELETE:
|
||||||
var response = serviceInvokers.XMLHttp.delete(url, function (responsePayload) {
|
// var response = serviceInvokers.XMLHttp.delete(url, function (responsePayload) {
|
||||||
var response = {};
|
// var response = {};
|
||||||
response.content = responsePayload["responseContent"];
|
// response.content = responsePayload["responseContent"];
|
||||||
response.status = "success";
|
// response.status = "success";
|
||||||
return response;
|
// return response;
|
||||||
},
|
// },
|
||||||
function (responsePayload) {
|
// function (responsePayload) {
|
||||||
var response = {};
|
// var response = {};
|
||||||
response.content = responsePayload;
|
// response.content = responsePayload;
|
||||||
response.status = "error";
|
// response.status = "error";
|
||||||
return response;
|
// return response;
|
||||||
});
|
// });
|
||||||
return response;
|
// return response;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}();
|
//}();
|
||||||
|
|||||||
@ -23,20 +23,17 @@ var onFail;
|
|||||||
var log = new Log("/app/modules/login.js");
|
var log = new Log("/app/modules/login.js");
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
onSuccess = function (context) {
|
onSuccess = function (context) {
|
||||||
var properties;
|
|
||||||
var utility = require("/app/modules/utility.js").utility;
|
var utility = require("/app/modules/utility.js").utility;
|
||||||
var apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
var apiWrapperUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil;
|
||||||
if (context.input.samlToken) {
|
if (context.input.samlToken) {
|
||||||
properties = {samlToken: context.input.samlToken};
|
apiWrapperUtil.setupAccessTokenPairBySamlGrantType(context.input.username, context.input.samlToken);
|
||||||
apiWrapperUtil.setupAccessTokenPair(constants.GRANT_TYPE_SAML, properties);
|
|
||||||
} else {
|
} else {
|
||||||
properties = {username: context.input.username, password: context.input.password};
|
apiWrapperUtil.setupAccessTokenPairByPasswordGrantType(context.input.username, context.input.password);
|
||||||
apiWrapperUtil.setupAccessTokenPair(constants.GRANT_TYPE_PASSWORD, properties);
|
|
||||||
}
|
}
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var carbonServer = require("carbon").server;
|
var carbonServer = require("carbon").server;
|
||||||
(new carbonServer.Server({url: devicemgtProps["adminService"]}))
|
(new carbonServer.Server({url: devicemgtProps["adminService"]}))
|
||||||
.login(context.input.username, context.input.password);
|
.login(context.input.username, context.input.password);
|
||||||
};
|
};
|
||||||
|
|
||||||
onFail = function (error) {
|
onFail = function (error) {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ var operationModule = function () {
|
|||||||
var log = new Log("/app/modules/operation.js");
|
var log = new Log("/app/modules/operation.js");
|
||||||
var utility = require('/app/modules/utility.js').utility;
|
var utility = require('/app/modules/utility.js').utility;
|
||||||
var constants = require('/app/modules/constants.js');
|
var constants = require('/app/modules/constants.js');
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
var publicMethods = {};
|
var publicMethods = {};
|
||||||
|
|||||||
@ -25,7 +25,7 @@ policyModule = function () {
|
|||||||
|
|
||||||
var constants = require('/app/modules/constants.js');
|
var constants = require('/app/modules/constants.js');
|
||||||
var utility = require("/app/modules/utility.js")["utility"];
|
var utility = require("/app/modules/utility.js")["utility"];
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||||
|
|
||||||
var publicMethods = {};
|
var publicMethods = {};
|
||||||
|
|||||||
@ -24,7 +24,7 @@ var userModule = function () {
|
|||||||
|
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var utility = require("/app/modules/utility.js")["utility"];
|
var utility = require("/app/modules/utility.js")["utility"];
|
||||||
var devicemgtProps = require("/app/conf/devicemgt-props.js").config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"];
|
||||||
|
|
||||||
/* Initializing user manager */
|
/* Initializing user manager */
|
||||||
|
|||||||
@ -21,7 +21,7 @@ var util = function () {
|
|||||||
var module = {};
|
var module = {};
|
||||||
var Base64 = Packages.org.apache.commons.codec.binary.Base64;
|
var Base64 = Packages.org.apache.commons.codec.binary.Base64;
|
||||||
var String = Packages.java.lang.String;
|
var String = Packages.java.lang.String;
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var carbon = require('carbon');
|
var carbon = require('carbon');
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var adminUser = devicemgtProps["adminUser"];
|
var adminUser = devicemgtProps["adminUser"];
|
||||||
|
|||||||
@ -20,7 +20,7 @@ var utility;
|
|||||||
utility = function () {
|
utility = function () {
|
||||||
|
|
||||||
var constants = require('/app/modules/constants.js');
|
var constants = require('/app/modules/constants.js');
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var log = new Log("/app/modules/utility.js");
|
var log = new Log("/app/modules/utility.js");
|
||||||
var JavaClass = Packages.java.lang.Class;
|
var JavaClass = Packages.java.lang.Class;
|
||||||
var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext;
|
var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|||||||
@ -21,7 +21,7 @@ function onRequest(context) {
|
|||||||
var user = session.get(constants.USER_SESSION_KEY);
|
var user = session.get(constants.USER_SESSION_KEY);
|
||||||
var userModule = require("/app/modules/user.js").userModule;
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
var permissions = userModule.getUIPermissions();
|
var permissions = userModule.getUIPermissions();
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
|
|
||||||
if (!permissions.VIEW_DASHBOARD) {
|
if (!permissions.VIEW_DASHBOARD) {
|
||||||
response.sendRedirect(constants.WEB_APP_CONTEXT + "/devices");
|
response.sendRedirect(constants.WEB_APP_CONTEXT + "/devices");
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
* @returns {*} A context object that returns the dynamic state of this page to be presented
|
* @returns {*} A context object that returns the dynamic state of this page to be presented
|
||||||
*/
|
*/
|
||||||
function onRequest(context) {
|
function onRequest(context) {
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var page = {};
|
var page = {};
|
||||||
page["groupNameJSRegEx"] = devicemgtProps.groupValidationConfig.groupNameJSRegEx;
|
page["groupNameJSRegEx"] = devicemgtProps.groupValidationConfig.groupNameJSRegEx;
|
||||||
page["groupNameRegExViolationErrorMsg"] = devicemgtProps.groupValidationConfig.groupNameRegExViolationErrorMsg;
|
page["groupNameRegExViolationErrorMsg"] = devicemgtProps.groupValidationConfig.groupNameRegExViolationErrorMsg;
|
||||||
|
|||||||
@ -26,7 +26,7 @@ function onRequest(context) {
|
|||||||
//var log = new Log("/app/pages/cdmf.page.user.create server-side js");
|
//var log = new Log("/app/pages/cdmf.page.user.create server-side js");
|
||||||
|
|
||||||
var userModule = require("/app/modules/user.js")["userModule"];
|
var userModule = require("/app/modules/user.js")["userModule"];
|
||||||
var devicemgtProps = require("/app/conf/devicemgt-props.js").config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
|
|
||||||
var page = {};
|
var page = {};
|
||||||
var response = userModule.getRolesByUserStore();
|
var response = userModule.getRolesByUserStore();
|
||||||
|
|||||||
@ -20,7 +20,7 @@ function onRequest(context) {
|
|||||||
var userModule = require("/app/modules/user.js").userModule;
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
var userName = request.getParameter("username");
|
var userName = request.getParameter("username");
|
||||||
var user = userModule.getUser(userName)["content"];
|
var user = userModule.getUser(userName)["content"];
|
||||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
var devicemgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
if (user) {
|
if (user) {
|
||||||
var title;
|
var title;
|
||||||
if (user.firstname || user.lastname) {
|
if (user.firstname || user.lastname) {
|
||||||
|
|||||||
@ -108,7 +108,7 @@ $("a.invite-user-link").click(function () {
|
|||||||
invokerUtil.post(
|
invokerUtil.post(
|
||||||
inviteUserAPI,
|
inviteUserAPI,
|
||||||
usernameList,
|
usernameList,
|
||||||
// The success callback
|
// success callback
|
||||||
function (data, textStatus, jqXHR) {
|
function (data, textStatus, jqXHR) {
|
||||||
if (jqXHR.status == 200) {
|
if (jqXHR.status == 200) {
|
||||||
$(modalPopupContent).html($('#invite-user-success-content').html());
|
$(modalPopupContent).html($('#invite-user-success-content').html());
|
||||||
@ -117,7 +117,7 @@ $("a.invite-user-link").click(function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// The error callback
|
// error callback
|
||||||
function (jqXHR) {
|
function (jqXHR) {
|
||||||
console.log("error in invite-user API, status code: " + jqXHR.status);
|
console.log("error in invite-user API, status code: " + jqXHR.status);
|
||||||
$(modalPopupContent).html($('#invite-user-error-content').html());
|
$(modalPopupContent).html($('#invite-user-error-content').html());
|
||||||
@ -212,7 +212,7 @@ function resetPassword(uname) {
|
|||||||
invokerUtil.post(
|
invokerUtil.post(
|
||||||
resetPasswordServiceURL,
|
resetPasswordServiceURL,
|
||||||
resetPasswordFormData,
|
resetPasswordFormData,
|
||||||
// The success callback
|
// success callback
|
||||||
function (data, textStatus, jqXHR) {
|
function (data, textStatus, jqXHR) {
|
||||||
if (jqXHR.status == 200) {
|
if (jqXHR.status == 200) {
|
||||||
$(modalPopupContent).html($('#reset-password-success-content').html());
|
$(modalPopupContent).html($('#reset-password-success-content').html());
|
||||||
@ -221,7 +221,7 @@ function resetPassword(uname) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// The error callback
|
// error callback
|
||||||
function (jqXHR) {
|
function (jqXHR) {
|
||||||
console.log("error in reset-password API, status code: " + jqXHR.status);
|
console.log("error in reset-password API, status code: " + jqXHR.status);
|
||||||
var payload = JSON.parse(jqXHR.responseText);
|
var payload = JSON.parse(jqXHR.responseText);
|
||||||
@ -271,14 +271,19 @@ function loadUsers() {
|
|||||||
|
|
||||||
var objects = [];
|
var objects = [];
|
||||||
|
|
||||||
$(data.users).each(function (index) {
|
$(data.users).each(
|
||||||
objects.push({
|
function (index) {
|
||||||
username: data.users[index].username,
|
objects.push(
|
||||||
firstname: data.users[index].firstname ? data.users[index].firstname: '' ,
|
{
|
||||||
lastname: data.users[index].lastname ? data.users[index].lastname : '',
|
username: data.users[index].username,
|
||||||
emailAddress : data.users[index].emailAddress ? data.users[index].emailAddress: '',
|
firstname: data.users[index].firstname ? data.users[index].firstname: '' ,
|
||||||
DT_RowId : "user-" + data.users[index].username})
|
lastname: data.users[index].lastname ? data.users[index].lastname : '',
|
||||||
});
|
emailAddress : data.users[index].emailAddress ? data.users[index].emailAddress: '',
|
||||||
|
DT_RowId : "user-" + data.users[index].username
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
var json = {
|
var json = {
|
||||||
"recordsTotal": data.count,
|
"recordsTotal": data.count,
|
||||||
@ -330,32 +335,53 @@ function loadUsers() {
|
|||||||
class: "text-right content-fill text-left-on-grid-view no-wrap",
|
class: "text-right content-fill text-left-on-grid-view no-wrap",
|
||||||
data: null,
|
data: null,
|
||||||
render: function (data, type, row, meta) {
|
render: function (data, type, row, meta) {
|
||||||
return '<a href="/emm/users/edit-user?username=' + data.username + '" data-username="' + data.username +
|
return '<a href="/emm/users/edit-user?username=' + data.username + '" ' +
|
||||||
'" data-click-event="edit-form" class="btn padding-reduce-on-grid-view edit-user-link"> ' +
|
'data-username="' + data.username + '" ' +
|
||||||
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
|
'data-click-event="edit-form" ' +
|
||||||
'<i class="fw fw-edit fw-stack-1x"></i>' +
|
'class="btn padding-reduce-on-grid-view edit-user-link">' +
|
||||||
' </span> <span class="hidden-xs hidden-on-grid-view">Edit</span> </a>' +
|
'<span class="fw-stack">' +
|
||||||
|
'<i class="fw fw-ring fw-stack-2x"></i>' +
|
||||||
'<a href="#" data-username="' + data.username + '" data-user-id=' + data.username +
|
'<i class="fw fw-edit fw-stack-1x"></i>' +
|
||||||
' data-click-event="remove-form" onclick="javascript:removeUser(\'' + data.username + '\', \'' +
|
'</span>' +
|
||||||
data.username + '\')" class="btn padding-reduce-on-grid-view remove-user-link">' +
|
'<span class="hidden-xs hidden-on-grid-view"> Edit</span>' +
|
||||||
'<span class="fw-stack"> <i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-delete fw-stack-1x">' +
|
'</a>' +
|
||||||
'</i> </span> <span class="hidden-xs hidden-on-grid-view">Remove</span> </a>' +
|
'<a href="#" ' +
|
||||||
|
'data-username="' + data.username + '" ' +
|
||||||
'<a href="#" data-username="' + data.username + '" data-user-id="' + data.username +
|
'data-user-id="' + data.username + '" ' +
|
||||||
'" data-click-event="edit-form" onclick="javascript:resetPassword(\'' + data.username +
|
'data-click-event="edit-form" ' +
|
||||||
'\')" class="btn padding-reduce-on-grid-view remove-user-link"> <span class="fw-stack">' +
|
'onclick="javascript:resetPassword(\'' + data.username + '\')" ' +
|
||||||
'<i class="fw fw-ring fw-stack-2x">' +
|
'class="btn padding-reduce-on-grid-view remove-user-link">' +
|
||||||
'</i> <i class="fw fw-key fw-stack-1x"></i> <span class="fw-stack fw-move-right fw-move-bottom"> ' +
|
'<span class="fw-stack">' +
|
||||||
'<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"><' +
|
'<i class="fw fw-ring fw-stack-2x"></i>' +
|
||||||
'/i> <i class="fw fw-circle fw-stack-2x"></i> <i class="fw fw-refresh fw-stack-1x fw-inverse">' +
|
'<i class="fw fw-key fw-stack-1x"></i>' +
|
||||||
'</i> </span> </span> <span class="hidden-xs hidden-on-grid-view">Reset</span> </a>'
|
'<span class="fw-stack fw-move-right fw-move-bottom">' +
|
||||||
|
'<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i> ' +
|
||||||
|
'<i class="fw fw-circle fw-stack-2x"></i>' +
|
||||||
|
'<i class="fw fw-refresh fw-stack-1x fw-inverse"></i> ' +
|
||||||
|
'</span>' +
|
||||||
|
'</span>' +
|
||||||
|
'<span class="hidden-xs hidden-on-grid-view"> Reset Password</span>' +
|
||||||
|
'</a>' +
|
||||||
|
'<a href="#" ' +
|
||||||
|
'data-username="' + data.username + '" ' +
|
||||||
|
'data-user-id=' + data.username + ' ' +
|
||||||
|
'data-click-event="remove-form" ' +
|
||||||
|
'onclick="javascript:removeUser(\'' + data.username + '\', \'' + data.username + '\')" ' +
|
||||||
|
'class="btn padding-reduce-on-grid-view remove-user-link">' +
|
||||||
|
'<span class="fw-stack">' +
|
||||||
|
'<i class="fw fw-ring fw-stack-2x"></i>' +
|
||||||
|
'<i class="fw fw-delete fw-stack-1x"></i>' +
|
||||||
|
'</span>' +
|
||||||
|
'<span class="hidden-xs hidden-on-grid-view"> Remove</span> ' +
|
||||||
|
'</a>'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$("#user-grid").datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/users', dataFilter, columns, fnCreatedRow, null);
|
$("#user-grid").datatables_extended_serverside_paging(
|
||||||
|
null, '/api/device-mgt/v1.0/users', dataFilter, columns, fnCreatedRow, null
|
||||||
|
);
|
||||||
|
|
||||||
$("#loading-content").hide();
|
$("#loading-content").hide();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,14 +27,14 @@
|
|||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="{{@app.context}}/users">
|
<a href="{{@app.context}}/users">
|
||||||
Users
|
USERS
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
|
|
||||||
{{#zone "navbarActions"}}
|
{{#zone "navbarActions"}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{@app.context}}/user/add" class="cu-btn">
|
<a href="{{@app.context}}/user/add">
|
||||||
<span class="icon fw-stack">
|
<span class="icon fw-stack">
|
||||||
<i class="fw fw-add fw-stack-1x"></i>
|
<i class="fw fw-add fw-stack-1x"></i>
|
||||||
<i class="fw fw-ring fw-stack-2x"></i>
|
<i class="fw fw-ring fw-stack-2x"></i>
|
||||||
|
|||||||
@ -29,7 +29,7 @@ function onRequest(context) {
|
|||||||
|
|
||||||
var page = {};
|
var page = {};
|
||||||
var userModule = require("/app/modules/user.js")["userModule"];
|
var userModule = require("/app/modules/user.js")["userModule"];
|
||||||
var deviceMgtProps = require("/app/conf/devicemgt-props.js").config();
|
var deviceMgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
|
|
||||||
page["adminUser"] = deviceMgtProps["adminUser"];
|
page["adminUser"] = deviceMgtProps["adminUser"];
|
||||||
page["permissions"] = userModule.getUIPermissions();
|
page["permissions"] = userModule.getUIPermissions();
|
||||||
|
|||||||
@ -30,9 +30,9 @@ function onRequest (context) {
|
|||||||
var userModule = require("/app/modules/user.js").userModule;
|
var userModule = require("/app/modules/user.js").userModule;
|
||||||
var constants = require("/app/modules/constants.js");
|
var constants = require("/app/modules/constants.js");
|
||||||
var permissions = userModule.getUIPermissions();
|
var permissions = userModule.getUIPermissions();
|
||||||
var mdmProps = require('/app/conf/devicemgt-props.js').config();
|
var deviceMgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
context.permissions = permissions;
|
context.permissions = permissions;
|
||||||
context["enrollmentURL"] = mdmProps.enrollmentURL;
|
context["enrollmentURL"] = deviceMgtProps.enrollmentURL;
|
||||||
|
|
||||||
return configs;
|
return configs;
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
function onRequest(context) {
|
function onRequest(context) {
|
||||||
var userModule = require("/app/modules/user.js")["userModule"];
|
var userModule = require("/app/modules/user.js")["userModule"];
|
||||||
var deviceMgtProps = require('/app/conf/devicemgt-props.js').config();
|
var deviceMgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var response = userModule.getRoles();
|
var response = userModule.getRoles();
|
||||||
if (response["status"] == "success") {
|
if (response["status"] == "success") {
|
||||||
context["roles"] = response["content"];
|
context["roles"] = response["content"];
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
function onRequest(context) {
|
function onRequest(context) {
|
||||||
var userModule = require("/app/modules/user.js")["userModule"];
|
var userModule = require("/app/modules/user.js")["userModule"];
|
||||||
var deviceMgtProps = require("/app/conf/devicemgt-props.js").config();
|
var deviceMgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
var uri = request.getRequestURI();
|
var uri = request.getRequestURI();
|
||||||
var uriMatcher = new URIMatcher(String(uri));
|
var uriMatcher = new URIMatcher(String(uri));
|
||||||
var isMatched = uriMatcher.match("/{context}/role/edit/{rolename}");
|
var isMatched = uriMatcher.match("/{context}/role/edit/{rolename}");
|
||||||
|
|||||||
@ -30,7 +30,7 @@ function onRequest(context) {
|
|||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/roles/remove")) {
|
if (userModule.isAuthorized("/permission/admin/device-mgt/roles/remove")) {
|
||||||
context["removePermitted"] = true;
|
context["removePermitted"] = true;
|
||||||
}
|
}
|
||||||
var deviceMgtProps = require("/app/conf/devicemgt-props.js").config();
|
var deviceMgtProps = require("/app/conf/reader/main.js")["conf"];
|
||||||
context["appContext"] = deviceMgtProps.appContext;
|
context["appContext"] = deviceMgtProps.appContext;
|
||||||
context["adminRole"] = deviceMgtProps.adminRole;
|
context["adminRole"] = deviceMgtProps.adminRole;
|
||||||
return context;
|
return context;
|
||||||
|
|||||||
@ -16,38 +16,58 @@
|
|||||||
under the License.
|
under the License.
|
||||||
}}
|
}}
|
||||||
{{#zone "navMenu-icon"}}
|
{{#zone "navMenu-icon"}}
|
||||||
<span class="icon fw-stack"><i class="fw fw-tiles fw-stack-1x"></i></span>
|
<span class="icon fw-stack">
|
||||||
|
<i class="fw fw-tiles fw-stack-1x toggle-icon-up"></i>
|
||||||
|
</span>
|
||||||
{{/zone}}
|
{{/zone}}
|
||||||
|
|
||||||
{{~#zone "navMenu-items"}}
|
{{#zone "navMenu-items"}}
|
||||||
{{#if permissions.VIEW_DASHBOARD}}
|
{{#if permissions.VIEW_DASHBOARD}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{@app.context}}"><i class="fw fw-dashboard"></i>Admin Dashboard</a>
|
<a href="{{@app.context}}">
|
||||||
|
<i class="fw fw-dashboard"></i>
|
||||||
|
Admin Dashboard
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if permissions.LIST_OWN_DEVICES}}
|
{{#if permissions.LIST_OWN_DEVICES}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{@app.context}}/devices"><i class="fw fw-mobile"></i>Device Management</a>
|
<a href="{{@app.context}}/devices">
|
||||||
|
<i class="fw fw-mobile"></i>
|
||||||
|
Device Management
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if permissions.LIST_GROUPS}}
|
{{#if permissions.LIST_GROUPS}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{@app.context}}/groups"><i class="fw fw-grouping"></i>Group Management</a>
|
<a href="{{@app.context}}/groups">
|
||||||
|
<i class="fw fw-grouping"></i>
|
||||||
|
Group Management
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if permissions.ADD_USER}}
|
{{#if permissions.ADD_USER}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{@app.context}}/users"><i class="fw fw-user"></i>User Management</a>
|
<a href="{{@app.context}}/users">
|
||||||
|
<i class="fw fw-user"></i>
|
||||||
|
User Management
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if permissions.ADD_ROLE}}
|
{{#if permissions.ADD_ROLE}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{@app.context}}/roles"><i class="fw fw-bookmark"></i>Role Management</a>
|
<a href="{{@app.context}}/roles">
|
||||||
|
<i class="fw fw-bookmark"></i>
|
||||||
|
Role Management
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if permissions.ADD_POLICY}}
|
{{#if permissions.ADD_POLICY}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{@app.context}}/policies"><i class="fw fw-policy"></i>Policy Management</a>
|
<a href="{{@app.context}}/policies">
|
||||||
|
<i class="fw fw-policy"></i>
|
||||||
|
Policy Management
|
||||||
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if permissions.TENANT_CONFIGURATION}}
|
{{#if permissions.TENANT_CONFIGURATION}}
|
||||||
|
|||||||
@ -19,10 +19,6 @@
|
|||||||
"url": "/api/user/*",
|
"url": "/api/user/*",
|
||||||
"path": "/api/user-api.jag"
|
"path": "/api/user-api.jag"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"url": "/token",
|
|
||||||
"path": "/api/token-api.jag"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"url": "/api/invoker/*",
|
"url": "/api/invoker/*",
|
||||||
"path": "/api/invoker-api.jag"
|
"path": "/api/invoker-api.jag"
|
||||||
|
|||||||
@ -111,7 +111,7 @@
|
|||||||
<adviceFile>
|
<adviceFile>
|
||||||
<properties>
|
<properties>
|
||||||
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||||
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
<propertyDef>org.eclipse.equinox.p2.type.group:true</propertyDef>
|
||||||
</properties>
|
</properties>
|
||||||
</adviceFile>
|
</adviceFile>
|
||||||
<bundles>
|
<bundles>
|
||||||
|
|||||||
@ -49,10 +49,10 @@
|
|||||||
<artifactId>org.wso2.carbon.device.mgt.api.feature</artifactId>
|
<artifactId>org.wso2.carbon.device.mgt.api.feature</artifactId>
|
||||||
<type>zip</type>
|
<type>zip</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!--<dependency>-->
|
||||||
<groupId>org.wso2.carbon.commons</groupId>
|
<!--<groupId>org.wso2.carbon.commons</groupId>-->
|
||||||
<artifactId>org.wso2.carbon.email.verification</artifactId>
|
<!--<artifactId>org.wso2.carbon.email.verification</artifactId>-->
|
||||||
</dependency>
|
<!--</dependency>-->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -114,9 +114,9 @@
|
|||||||
<bundleDef>
|
<bundleDef>
|
||||||
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.common:${carbon.device.mgt.version}
|
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.common:${carbon.device.mgt.version}
|
||||||
</bundleDef>
|
</bundleDef>
|
||||||
<bundleDef>
|
<!--<bundleDef>-->
|
||||||
org.wso2.carbon.commons:org.wso2.carbon.email.verification
|
<!--org.wso2.carbon.commons:org.wso2.carbon.email.verification-->
|
||||||
</bundleDef>
|
<!--</bundleDef>-->
|
||||||
<bundleDef>
|
<bundleDef>
|
||||||
org.wso2.carbon.identity:org.wso2.carbon.identity.oauth.stub:${carbon.identity.version}
|
org.wso2.carbon.identity:org.wso2.carbon.identity.oauth.stub:${carbon.identity.version}
|
||||||
</bundleDef>
|
</bundleDef>
|
||||||
|
|||||||
@ -127,7 +127,7 @@
|
|||||||
<adviceFile>
|
<adviceFile>
|
||||||
<properties>
|
<properties>
|
||||||
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||||
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
<propertyDef>org.eclipse.equinox.p2.type.group:true</propertyDef>
|
||||||
</properties>
|
</properties>
|
||||||
</adviceFile>
|
</adviceFile>
|
||||||
<bundles>
|
<bundles>
|
||||||
|
|||||||
14
pom.xml
14
pom.xml
@ -757,11 +757,11 @@
|
|||||||
<version>${axiom.wso2.version}</version>
|
<version>${axiom.wso2.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<!--<dependency>-->
|
||||||
<groupId>org.wso2.carbon.commons</groupId>
|
<!--<groupId>org.wso2.carbon.commons</groupId>-->
|
||||||
<artifactId>org.wso2.carbon.email.verification</artifactId>
|
<!--<artifactId>org.wso2.carbon.email.verification</artifactId>-->
|
||||||
<version>${carbon.commons.version}</version>
|
<!--<version>${carbon.commons.version}</version>-->
|
||||||
</dependency>
|
<!--</dependency>-->
|
||||||
|
|
||||||
<!-- API Management dependencies -->
|
<!-- API Management dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -1791,8 +1791,8 @@
|
|||||||
<carbon.governance.version>4.5.8</carbon.governance.version>
|
<carbon.governance.version>4.5.8</carbon.governance.version>
|
||||||
|
|
||||||
<!-- Axiom -->
|
<!-- Axiom -->
|
||||||
<axiom.version>1.2.11-wso2v5</axiom.version>
|
<axiom.version>1.2.11-wso2v11</axiom.version>
|
||||||
<axiom.osgi.version.range>[1.2.11.wso2v5, 1.3.0)</axiom.osgi.version.range>
|
<axiom.osgi.version.range>[1.2.11, 1.3.0)</axiom.osgi.version.range>
|
||||||
<axiom.wso2.version>1.2.11.wso2v5</axiom.wso2.version>
|
<axiom.wso2.version>1.2.11.wso2v5</axiom.wso2.version>
|
||||||
|
|
||||||
<!-- Carbon Device Management -->
|
<!-- Carbon Device Management -->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user