mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge pull request #318 from Securepoint/master
Minor bug fixies and code improvements
This commit is contained in:
commit
cc90bef42b
@ -22,13 +22,13 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
|
||||||
|
import org.wso2.carbon.apimgt.application.extension.api.util.APIUtil;
|
||||||
import org.wso2.carbon.apimgt.application.extension.api.util.RegistrationProfile;
|
import org.wso2.carbon.apimgt.application.extension.api.util.RegistrationProfile;
|
||||||
import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants;
|
import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants;
|
||||||
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
||||||
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
||||||
import org.wso2.carbon.base.MultitenantConstants;
|
import org.wso2.carbon.base.MultitenantConstants;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.apimgt.application.extension.api.util.APIUtil;
|
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
@ -46,7 +46,7 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
|
|||||||
public Response register(@QueryParam("tenantDomain") String tenantDomain,
|
public Response register(@QueryParam("tenantDomain") String tenantDomain,
|
||||||
@QueryParam("applicationName") String applicationName) {
|
@QueryParam("applicationName") String applicationName) {
|
||||||
String authenticatedTenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
String authenticatedTenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
||||||
if (!authenticatedTenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(authenticatedTenantDomain)) {
|
||||||
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
|
return Response.status(Response.Status.NOT_ACCEPTABLE).build();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -23,12 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.wso2.carbon.apimgt.api.APIConsumer;
|
import org.wso2.carbon.apimgt.api.APIConsumer;
|
||||||
import org.wso2.carbon.apimgt.api.APIManagementException;
|
import org.wso2.carbon.apimgt.api.APIManagementException;
|
||||||
import org.wso2.carbon.apimgt.api.model.API;
|
import org.wso2.carbon.apimgt.api.model.*;
|
||||||
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
|
|
||||||
import org.wso2.carbon.apimgt.api.model.APIKey;
|
|
||||||
import org.wso2.carbon.apimgt.api.model.Application;
|
|
||||||
import org.wso2.carbon.apimgt.api.model.SubscribedAPI;
|
|
||||||
import org.wso2.carbon.apimgt.api.model.Subscriber;
|
|
||||||
import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants;
|
import org.wso2.carbon.apimgt.application.extension.constants.ApiApplicationConstants;
|
||||||
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
|
||||||
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
|
||||||
@ -415,7 +410,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|||||||
int applicationId = createApplication(apiConsumer, apiApplicationName, username, groupId);
|
int applicationId = createApplication(apiConsumer, apiApplicationName, username, groupId);
|
||||||
String tenantDomain = MultitenantUtils.getTenantDomain(username);
|
String tenantDomain = MultitenantUtils.getTenantDomain(username);
|
||||||
Set<API> userVisibleAPIs = apiConsumer.getAllPublishedAPIs(tenantDomain);
|
Set<API> userVisibleAPIs = apiConsumer.getAllPublishedAPIs(tenantDomain);
|
||||||
if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||||
userVisibleAPIs.addAll(apiConsumer.getAllPublishedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
userVisibleAPIs.addAll(apiConsumer.getAllPublishedAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
|
||||||
}
|
}
|
||||||
Subscriber subscriber = apiConsumer.getSubscriber(username);
|
Subscriber subscriber = apiConsumer.getSubscriber(username);
|
||||||
@ -443,7 +438,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
|
|||||||
try {
|
try {
|
||||||
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
|
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(username);
|
||||||
loginInfoJsonObj.put("user", username);
|
loginInfoJsonObj.put("user", username);
|
||||||
if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||||
loginInfoJsonObj.put("isSuperTenant", true);
|
loginInfoJsonObj.put("isSuperTenant", true);
|
||||||
} else {
|
} else {
|
||||||
loginInfoJsonObj.put("isSuperTenant", false);
|
loginInfoJsonObj.put("isSuperTenant", false);
|
||||||
|
|||||||
@ -37,7 +37,7 @@ public final class APIManagerUtil {
|
|||||||
*/
|
*/
|
||||||
public static int getTenantId(String tenantDomain) throws APIManagerException {
|
public static int getTenantId(String tenantDomain) throws APIManagerException {
|
||||||
try {
|
try {
|
||||||
if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||||
return MultitenantConstants.SUPER_TENANT_ID;
|
return MultitenantConstants.SUPER_TENANT_ID;
|
||||||
}
|
}
|
||||||
TenantManager tenantManager = APIApplicationManagerExtensionDataHolder.getInstance().getTenantManager();
|
TenantManager tenantManager = APIApplicationManagerExtensionDataHolder.getInstance().getTenantManager();
|
||||||
|
|||||||
@ -36,10 +36,10 @@ import java.util.*;
|
|||||||
|
|
||||||
public class APIPublisherUtil {
|
public class APIPublisherUtil {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(APIPublisherUtil.class);
|
|
||||||
private static final String DEFAULT_API_VERSION = "1.0.0";
|
|
||||||
public static final String API_VERSION_PARAM = "{version}";
|
public static final String API_VERSION_PARAM = "{version}";
|
||||||
public static final String API_PUBLISH_ENVIRONMENT = "Production and Sandbox";
|
public static final String API_PUBLISH_ENVIRONMENT = "Production and Sandbox";
|
||||||
|
private static final Log log = LogFactory.getLog(APIPublisherUtil.class);
|
||||||
|
private static final String DEFAULT_API_VERSION = "1.0.0";
|
||||||
private static final String API_CONFIG_DEFAULT_VERSION = "1.0.0";
|
private static final String API_CONFIG_DEFAULT_VERSION = "1.0.0";
|
||||||
private static final String PARAM_MANAGED_API_ENDPOINT = "managed-api-endpoint";
|
private static final String PARAM_MANAGED_API_ENDPOINT = "managed-api-endpoint";
|
||||||
private static final String PARAM_MANAGED_API_OWNER = "managed-api-owner";
|
private static final String PARAM_MANAGED_API_OWNER = "managed-api-owner";
|
||||||
@ -242,7 +242,7 @@ public class APIPublisherUtil {
|
|||||||
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
|
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
|
||||||
apiConfig.setTenantDomain(tenantDomain);
|
apiConfig.setTenantDomain(tenantDomain);
|
||||||
String contextTemplate = context + "/" + APIConstants.VERSION_PLACEHOLDER;
|
String contextTemplate = context + "/" + APIConstants.VERSION_PLACEHOLDER;
|
||||||
if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||||
contextTemplate = context + "/t/" + tenantDomain + "/" + APIConstants.VERSION_PLACEHOLDER;
|
contextTemplate = context + "/t/" + tenantDomain + "/" + APIConstants.VERSION_PLACEHOLDER;
|
||||||
}
|
}
|
||||||
apiConfig.setContextTemplate(contextTemplate);
|
apiConfig.setContextTemplate(contextTemplate);
|
||||||
|
|||||||
@ -66,11 +66,10 @@ public class AnnotationProcessor {
|
|||||||
private static final String HTTP_PORT = "httpPort";
|
private static final String HTTP_PORT = "httpPort";
|
||||||
private static final String STRING_ARR = "string_arr";
|
private static final String STRING_ARR = "string_arr";
|
||||||
private static final String STRING = "string";
|
private static final String STRING = "string";
|
||||||
|
Class<API> apiClazz;
|
||||||
private StandardContext context;
|
private StandardContext context;
|
||||||
private Method[] pathClazzMethods;
|
private Method[] pathClazzMethods;
|
||||||
private Class<Path> pathClazz;
|
private Class<Path> pathClazz;
|
||||||
Class<API> apiClazz;
|
|
||||||
private ClassLoader classLoader;
|
private ClassLoader classLoader;
|
||||||
private ServletContext servletContext;
|
private ServletContext servletContext;
|
||||||
|
|
||||||
@ -319,7 +318,7 @@ public class AnnotationProcessor {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String makeContextURLReady(String context) {
|
private String makeContextURLReady(String context) {
|
||||||
if (context != null && !context.equalsIgnoreCase("")) {
|
if (context != null && context.length() > 0) {
|
||||||
if (context.startsWith("/")) {
|
if (context.startsWith("/")) {
|
||||||
return context;
|
return context;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -46,14 +46,7 @@ import org.bouncycastle.operator.OperatorCreationException;
|
|||||||
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||||
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
|
||||||
import org.bouncycastle.util.Store;
|
import org.bouncycastle.util.Store;
|
||||||
import org.jscep.message.CertRep;
|
import org.jscep.message.*;
|
||||||
import org.jscep.message.MessageDecodingException;
|
|
||||||
import org.jscep.message.MessageEncodingException;
|
|
||||||
import org.jscep.message.PkcsPkiEnvelopeDecoder;
|
|
||||||
import org.jscep.message.PkcsPkiEnvelopeEncoder;
|
|
||||||
import org.jscep.message.PkiMessage;
|
|
||||||
import org.jscep.message.PkiMessageDecoder;
|
|
||||||
import org.jscep.message.PkiMessageEncoder;
|
|
||||||
import org.jscep.transaction.FailInfo;
|
import org.jscep.transaction.FailInfo;
|
||||||
import org.jscep.transaction.Nonce;
|
import org.jscep.transaction.Nonce;
|
||||||
import org.jscep.transaction.TransactionId;
|
import org.jscep.transaction.TransactionId;
|
||||||
@ -72,31 +65,11 @@ import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
|||||||
|
|
||||||
import javax.security.auth.x500.X500Principal;
|
import javax.security.auth.x500.X500Principal;
|
||||||
import javax.xml.bind.DatatypeConverter;
|
import javax.xml.bind.DatatypeConverter;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.*;
|
||||||
import java.security.KeyFactory;
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.KeyPairGenerator;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.NoSuchProviderException;
|
|
||||||
import java.security.PrivateKey;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.security.Security;
|
|
||||||
import java.security.SignatureException;
|
|
||||||
import java.security.cert.Certificate;
|
import java.security.cert.Certificate;
|
||||||
import java.security.cert.CertificateEncodingException;
|
import java.security.cert.*;
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.security.cert.CertificateExpiredException;
|
|
||||||
import java.security.cert.CertificateFactory;
|
|
||||||
import java.security.cert.CertificateNotYetValidException;
|
|
||||||
import java.security.cert.X509Certificate;
|
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -108,6 +81,46 @@ public class CertificateGenerator {
|
|||||||
|
|
||||||
private static final Log log = LogFactory.getLog(CertificateGenerator.class);
|
private static final Log log = LogFactory.getLog(CertificateGenerator.class);
|
||||||
|
|
||||||
|
public static String getCommonName(X509Certificate requestCertificate) {
|
||||||
|
String distinguishedName = requestCertificate.getSubjectDN().getName();
|
||||||
|
if (distinguishedName != null && !distinguishedName.isEmpty()) {
|
||||||
|
String[] dnSplits = distinguishedName.split(",");
|
||||||
|
for (String dnSplit : dnSplits) {
|
||||||
|
if (dnSplit.contains("CN=")) {
|
||||||
|
String[] cnSplits = dnSplit.split("=");
|
||||||
|
if (cnSplits[1] != null) {
|
||||||
|
return cnSplits[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void extractCertificateDetails(byte[] certificateBytes, CertificateResponse certificateResponse)
|
||||||
|
throws CertificateManagementDAOException {
|
||||||
|
try {
|
||||||
|
if (certificateBytes != null) {
|
||||||
|
java.security.cert.Certificate x509Certificate =
|
||||||
|
(java.security.cert.Certificate) Serializer.deserialize(certificateBytes);
|
||||||
|
if (x509Certificate instanceof X509Certificate) {
|
||||||
|
X509Certificate certificate = (X509Certificate) x509Certificate;
|
||||||
|
certificateResponse.setNotAfter(certificate.getNotAfter().getTime());
|
||||||
|
certificateResponse.setNotBefore(certificate.getNotBefore().getTime());
|
||||||
|
certificateResponse.setCertificateserial(certificate.getSerialNumber());
|
||||||
|
certificateResponse.setIssuer(certificate.getIssuerDN().getName());
|
||||||
|
certificateResponse.setSubject(certificate.getSubjectDN().getName());
|
||||||
|
certificateResponse.setCertificateVersion(certificate.getVersion());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException | IOException e) {
|
||||||
|
String errorMsg = "Error while deserializing the certificate.";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new CertificateManagementDAOException(errorMsg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public List<X509Certificate> getRootCertificates(byte[] ca, byte[] ra) throws KeystoreException {
|
public List<X509Certificate> getRootCertificates(byte[] ca, byte[] ra) throws KeystoreException {
|
||||||
|
|
||||||
if (ca == null) {
|
if (ca == null) {
|
||||||
@ -333,22 +346,6 @@ public class CertificateGenerator {
|
|||||||
return lookUpCertificate;
|
return lookUpCertificate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCommonName(X509Certificate requestCertificate) {
|
|
||||||
String distinguishedName = requestCertificate.getSubjectDN().getName();
|
|
||||||
if (distinguishedName != null && !distinguishedName.isEmpty()) {
|
|
||||||
String[] dnSplits = distinguishedName.split(",");
|
|
||||||
for (String dnSplit : dnSplits) {
|
|
||||||
if (dnSplit.contains("CN=")) {
|
|
||||||
String[] cnSplits = dnSplit.split("=");
|
|
||||||
if (cnSplits[1] != null) {
|
|
||||||
return cnSplits[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public X509Certificate pemToX509Certificate(String pem)
|
public X509Certificate pemToX509Certificate(String pem)
|
||||||
throws KeystoreException {
|
throws KeystoreException {
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
@ -399,7 +396,7 @@ public class CertificateGenerator {
|
|||||||
Certificate lookUpCertificate = keyStoreReader.getCertificateByAlias(
|
Certificate lookUpCertificate = keyStoreReader.getCertificateByAlias(
|
||||||
reqCert.getSerialNumber().toString());
|
reqCert.getSerialNumber().toString());
|
||||||
|
|
||||||
if (lookUpCertificate != null && (lookUpCertificate instanceof X509Certificate)) {
|
if (lookUpCertificate instanceof X509Certificate) {
|
||||||
return (X509Certificate) lookUpCertificate;
|
return (X509Certificate) lookUpCertificate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -682,7 +679,6 @@ public class CertificateGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String extractChallengeToken(X509Certificate certificate) {
|
public String extractChallengeToken(X509Certificate certificate) {
|
||||||
|
|
||||||
byte[] challengePassword = certificate.getExtensionValue(
|
byte[] challengePassword = certificate.getExtensionValue(
|
||||||
@ -742,28 +738,4 @@ public class CertificateGenerator {
|
|||||||
return generateCertificateFromCSR(privateKeyCA, certificationRequest,
|
return generateCertificateFromCSR(privateKeyCA, certificationRequest,
|
||||||
certCA.getIssuerX500Principal().getName());
|
certCA.getIssuerX500Principal().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void extractCertificateDetails(byte[] certificateBytes, CertificateResponse certificateResponse)
|
|
||||||
throws CertificateManagementDAOException {
|
|
||||||
try {
|
|
||||||
if (certificateBytes != null) {
|
|
||||||
java.security.cert.Certificate x509Certificate =
|
|
||||||
(java.security.cert.Certificate) Serializer.deserialize(certificateBytes);
|
|
||||||
if (x509Certificate instanceof X509Certificate) {
|
|
||||||
X509Certificate certificate = (X509Certificate) x509Certificate;
|
|
||||||
certificateResponse.setNotAfter(certificate.getNotAfter().getTime());
|
|
||||||
certificateResponse.setNotBefore(certificate.getNotBefore().getTime());
|
|
||||||
certificateResponse.setCertificateserial(certificate.getSerialNumber());
|
|
||||||
certificateResponse.setIssuer(certificate.getIssuerDN().getName());
|
|
||||||
certificateResponse.setSubject(certificate.getSubjectDN().getName());
|
|
||||||
certificateResponse.setCertificateVersion(certificate.getVersion());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException | IOException e) {
|
|
||||||
String errorMsg = "Error while deserializing the certificate.";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -60,6 +60,10 @@ public class DeviceDataPublisher {
|
|||||||
private static Map<String, DataPublisher> dataPublisherMap;
|
private static Map<String, DataPublisher> dataPublisherMap;
|
||||||
private static DeviceDataPublisher deviceDataPublisher;
|
private static DeviceDataPublisher deviceDataPublisher;
|
||||||
|
|
||||||
|
public DeviceDataPublisher() {
|
||||||
|
dataPublisherMap = new ConcurrentHashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
public static DeviceDataPublisher getInstance() {
|
public static DeviceDataPublisher getInstance() {
|
||||||
if (deviceDataPublisher == null) {
|
if (deviceDataPublisher == null) {
|
||||||
synchronized (DeviceDataPublisher.class) {
|
synchronized (DeviceDataPublisher.class) {
|
||||||
@ -71,10 +75,6 @@ public class DeviceDataPublisher {
|
|||||||
return deviceDataPublisher;
|
return deviceDataPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceDataPublisher() {
|
|
||||||
dataPublisherMap = new ConcurrentHashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this return the data publisher for the tenant.
|
* this return the data publisher for the tenant.
|
||||||
*
|
*
|
||||||
@ -95,7 +95,7 @@ public class DeviceDataPublisher {
|
|||||||
String analyticsServerUrlGroups = analyticsConfig.getReceiverServerUrl();
|
String analyticsServerUrlGroups = analyticsConfig.getReceiverServerUrl();
|
||||||
String analyticsServerUsername = analyticsConfig.getAdminUsername();
|
String analyticsServerUsername = analyticsConfig.getAdminUsername();
|
||||||
String analyticsServerPassword = analyticsConfig.getAdminPassword();
|
String analyticsServerPassword = analyticsConfig.getAdminPassword();
|
||||||
if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
String userInfo[] = getAnalyticsServerUserInfo(tenantId);
|
String userInfo[] = getAnalyticsServerUserInfo(tenantId);
|
||||||
if (userInfo != null) {
|
if (userInfo != null) {
|
||||||
|
|||||||
@ -134,11 +134,11 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
UIPermissionNode[] deviceMgtPermissions = new UIPermissionNode[2];
|
UIPermissionNode[] deviceMgtPermissions = new UIPermissionNode[2];
|
||||||
|
|
||||||
for (UIPermissionNode permissionNode : rolePermissions.getNodeList()) {
|
for (UIPermissionNode permissionNode : rolePermissions.getNodeList()) {
|
||||||
if (permissionNode.getResourcePath().equals("/permission/admin")) {
|
if ("/permission/admin".equals(permissionNode.getResourcePath())) {
|
||||||
for (UIPermissionNode node : permissionNode.getNodeList()) {
|
for (UIPermissionNode node : permissionNode.getNodeList()) {
|
||||||
if (node.getResourcePath().equals("/permission/admin/device-mgt")) {
|
if ("/permission/admin/device-mgt".equals(node.getResourcePath())) {
|
||||||
deviceMgtPermissions[0] = node;
|
deviceMgtPermissions[0] = node;
|
||||||
} else if (node.getResourcePath().equals("/permission/admin/login")) {
|
} else if ("/permission/admin/login".equals(node.getResourcePath())) {
|
||||||
deviceMgtPermissions[1] = node;
|
deviceMgtPermissions[1] = node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,8 +47,7 @@ public class QueryBuilderImpl implements QueryBuilder {
|
|||||||
Condition locCondition = new Condition();
|
Condition locCondition = new Condition();
|
||||||
|
|
||||||
if (conditions.size() == 1) {
|
if (conditions.size() == 1) {
|
||||||
|
if (Constants.LOCATION.equalsIgnoreCase(conditions.get(0).getKey())) {
|
||||||
if (conditions.get(0).getKey().equalsIgnoreCase(Constants.LOCATION)) {
|
|
||||||
locCondition = conditions.get(0);
|
locCondition = conditions.get(0);
|
||||||
} else if (Utils.checkDeviceDetailsColumns(conditions.get(0).getKey()) ||
|
} else if (Utils.checkDeviceDetailsColumns(conditions.get(0).getKey()) ||
|
||||||
Utils.checkDeviceLocationColumns(conditions.get(0).getKey())) {
|
Utils.checkDeviceLocationColumns(conditions.get(0).getKey())) {
|
||||||
@ -58,7 +57,7 @@ public class QueryBuilderImpl implements QueryBuilder {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Condition con : conditions) {
|
for (Condition con : conditions) {
|
||||||
if (con.getKey().equalsIgnoreCase(Constants.LOCATION)) {
|
if (Constants.LOCATION.equalsIgnoreCase(con.getKey())) {
|
||||||
locCondition = con;
|
locCondition = con;
|
||||||
} else if (Utils.checkDeviceDetailsColumns(con.getKey()) ||
|
} else if (Utils.checkDeviceDetailsColumns(con.getKey()) ||
|
||||||
Utils.checkDeviceLocationColumns(con.getKey())) {
|
Utils.checkDeviceLocationColumns(con.getKey())) {
|
||||||
|
|||||||
@ -228,7 +228,7 @@ public final class DeviceManagerUtil {
|
|||||||
*/
|
*/
|
||||||
public static int getTenantId(String tenantDomain) throws DeviceManagementException {
|
public static int getTenantId(String tenantDomain) throws DeviceManagementException {
|
||||||
try {
|
try {
|
||||||
if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||||
return MultitenantConstants.SUPER_TENANT_ID;
|
return MultitenantConstants.SUPER_TENANT_ID;
|
||||||
}
|
}
|
||||||
TenantManager tenantManager = DeviceManagementDataHolder.getInstance().getTenantManager();
|
TenantManager tenantManager = DeviceManagementDataHolder.getInstance().getTenantManager();
|
||||||
|
|||||||
@ -67,25 +67,25 @@ public class FeatureFilterImpl implements FeatureFilter {
|
|||||||
for (FeatureRules rule : featureRulesList) {
|
for (FeatureRules rule : featureRulesList) {
|
||||||
String ruleName = rule.getEvaluationCriteria();
|
String ruleName = rule.getEvaluationCriteria();
|
||||||
String featureName = rule.getName();
|
String featureName = rule.getName();
|
||||||
if (ruleName.equalsIgnoreCase(Constants.DENY_OVERRIDES)) {
|
if (Constants.DENY_OVERRIDES.equalsIgnoreCase(ruleName)) {
|
||||||
getDenyOverridesFeatures(featureName, featureList, effectiveFeatureList);
|
getDenyOverridesFeatures(featureName, featureList, effectiveFeatureList);
|
||||||
}
|
}
|
||||||
if (ruleName.equalsIgnoreCase(Constants.PERMIT_OVERRIDES)) {
|
if (Constants.PERMIT_OVERRIDES.equalsIgnoreCase(ruleName)) {
|
||||||
getPermitOverridesFeatures(featureName, featureList, effectiveFeatureList);
|
getPermitOverridesFeatures(featureName, featureList, effectiveFeatureList);
|
||||||
}
|
}
|
||||||
if (ruleName.equalsIgnoreCase(Constants.FIRST_APPLICABLE)) {
|
if (Constants.FIRST_APPLICABLE.equalsIgnoreCase(ruleName)) {
|
||||||
getFirstApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
getFirstApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||||
}
|
}
|
||||||
if (ruleName.equalsIgnoreCase(Constants.LAST_APPLICABLE)) {
|
if (Constants.LAST_APPLICABLE.equalsIgnoreCase(ruleName)) {
|
||||||
getLastApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
getLastApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||||
}
|
}
|
||||||
if (ruleName.equalsIgnoreCase(Constants.ALL_APPLICABLE)) {
|
if (Constants.ALL_APPLICABLE.equalsIgnoreCase(ruleName)) {
|
||||||
getAllApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
getAllApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||||
}
|
}
|
||||||
if (ruleName.equalsIgnoreCase(Constants.HIGHEST_APPLICABLE)) {
|
if (Constants.HIGHEST_APPLICABLE.equalsIgnoreCase(ruleName)) {
|
||||||
getHighestApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
getHighestApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||||
}
|
}
|
||||||
if (ruleName.equalsIgnoreCase(Constants.LOWEST_APPLICABLE)) {
|
if (Constants.LOWEST_APPLICABLE.equalsIgnoreCase(ruleName)) {
|
||||||
getLowestApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
getLowestApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -473,8 +473,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String query = "SELECT * FROM DM_POLICY_CHANGE_MGT WHERE TENANT_ID = ?";
|
String query = "SELECT * FROM DM_POLICY_CHANGE_MGT WHERE TENANT_ID = ?";
|
||||||
stmt.setInt(1, tenantId);
|
|
||||||
stmt = conn.prepareStatement(query);
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
resultSet = stmt.executeQuery();
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
@ -1302,11 +1302,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Policy (" + policyId + ") delete from database.");
|
log.debug("Policy (" + policyId + ") delete from database.");
|
||||||
}
|
}
|
||||||
if (deleted > 0) {
|
return deleted > 0;
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PolicyManagerDAOException("Unable to delete the policy (" + policyId + ") from database", e);
|
throw new PolicyManagerDAOException("Unable to delete the policy (" + policyId + ") from database", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -1584,7 +1580,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
|||||||
byte[] contentBytes;
|
byte[] contentBytes;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
contentBytes = (byte[]) resultSet.getBytes("POLICY_CONTENT");
|
contentBytes = resultSet.getBytes("POLICY_CONTENT");
|
||||||
bais = new ByteArrayInputStream(contentBytes);
|
bais = new ByteArrayInputStream(contentBytes);
|
||||||
ois = new ObjectInputStream(bais);
|
ois = new ObjectInputStream(bais);
|
||||||
policy = (Policy) ois.readObject();
|
policy = (Policy) ois.readObject();
|
||||||
|
|||||||
@ -253,7 +253,7 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
|||||||
Policy policy = complianceData.getPolicy();
|
Policy policy = complianceData.getPolicy();
|
||||||
String compliance = this.getNoneComplianceRule(policy);
|
String compliance = this.getNoneComplianceRule(policy);
|
||||||
|
|
||||||
if (compliance.equals("")) {
|
if ("".equals(compliance)) {
|
||||||
String msg = "Compliance rule is empty for the policy " + policy.getPolicyName() + ". Therefore " +
|
String msg = "Compliance rule is empty for the policy " + policy.getPolicyName() + ". Therefore " +
|
||||||
"Monitoring Engine cannot run.";
|
"Monitoring Engine cannot run.";
|
||||||
throw new PolicyComplianceException(msg);
|
throw new PolicyComplianceException(msg);
|
||||||
|
|||||||
@ -203,7 +203,7 @@ public class PolicyManagerUtil {
|
|||||||
|
|
||||||
if (configuration != null && !configuration.isEmpty()) {
|
if (configuration != null && !configuration.isEmpty()) {
|
||||||
for (ConfigurationEntry cEntry : configuration) {
|
for (ConfigurationEntry cEntry : configuration) {
|
||||||
if (cEntry.getName().equalsIgnoreCase(MONITORING_FREQUENCY)) {
|
if (MONITORING_FREQUENCY.equalsIgnoreCase(cEntry.getName())) {
|
||||||
if (cEntry.getValue() == null) {
|
if (cEntry.getValue() == null) {
|
||||||
throw new PolicyManagementException("Invalid value, i.e. '" + cEntry.getValue() +
|
throw new PolicyManagementException("Invalid value, i.e. '" + cEntry.getValue() +
|
||||||
"', is configured as the monitoring frequency");
|
"', is configured as the monitoring frequency");
|
||||||
|
|||||||
@ -105,7 +105,7 @@ public class WebappAuthenticationValve extends CarbonTomcatValve {
|
|||||||
ctx = tokenizer.nextToken();
|
ctx = tokenizer.nextToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (ctx.equalsIgnoreCase("carbon") || ctx.equalsIgnoreCase("services"));
|
return ("carbon".equalsIgnoreCase(ctx) || "services".equalsIgnoreCase(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNonSecuredEndPoint(Request request) {
|
private boolean isNonSecuredEndPoint(Request request) {
|
||||||
@ -132,10 +132,7 @@ public class WebappAuthenticationValve extends CarbonTomcatValve {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nonSecuredEndpoints.containsKey(uri)) {
|
return nonSecuredEndpoints.containsKey(uri);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processRequest(Request request, Response response, CompositeValve compositeValve,
|
private void processRequest(Request request, Response response, CompositeValve compositeValve,
|
||||||
|
|||||||
@ -65,6 +65,13 @@ public class JWTAuthenticator implements WebappAuthenticator {
|
|||||||
private static final Map<String, PublicKey> publicKeyHolder = new HashMap<>();
|
private static final Map<String, PublicKey> publicKeyHolder = new HashMap<>();
|
||||||
private Properties properties;
|
private Properties properties;
|
||||||
|
|
||||||
|
private static void loadTenantRegistry(int tenantId) throws RegistryException {
|
||||||
|
TenantRegistryLoader tenantRegistryLoader = AuthenticatorFrameworkDataHolder.getInstance().
|
||||||
|
getTenantRegistryLoader();
|
||||||
|
AuthenticatorFrameworkDataHolder.getInstance().getTenantIndexingLoader().loadTenantIndex(tenantId);
|
||||||
|
tenantRegistryLoader.loadTenantRegistry(tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
|
|
||||||
@ -73,10 +80,7 @@ public class JWTAuthenticator implements WebappAuthenticator {
|
|||||||
@Override
|
@Override
|
||||||
public boolean canHandle(Request request) {
|
public boolean canHandle(Request request) {
|
||||||
String authorizationHeader = request.getHeader(JWTAuthenticator.JWT_ASSERTION_HEADER);
|
String authorizationHeader = request.getHeader(JWTAuthenticator.JWT_ASSERTION_HEADER);
|
||||||
if ((authorizationHeader != null) && !authorizationHeader.isEmpty()) {
|
return (authorizationHeader != null) && !authorizationHeader.isEmpty();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -106,7 +110,7 @@ public class JWTAuthenticator implements WebappAuthenticator {
|
|||||||
if (publicKey == null) {
|
if (publicKey == null) {
|
||||||
loadTenantRegistry(tenantId);
|
loadTenantRegistry(tenantId);
|
||||||
KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(tenantId);
|
KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(tenantId);
|
||||||
if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||||
String defaultPublicKey = properties.getProperty("DefaultPublicKey");
|
String defaultPublicKey = properties.getProperty("DefaultPublicKey");
|
||||||
if (defaultPublicKey != null && !defaultPublicKey.isEmpty()) {
|
if (defaultPublicKey != null && !defaultPublicKey.isEmpty()) {
|
||||||
boolean isDefaultPublicKey = Boolean.parseBoolean(defaultPublicKey);
|
boolean isDefaultPublicKey = Boolean.parseBoolean(defaultPublicKey);
|
||||||
@ -182,13 +186,13 @@ public class JWTAuthenticator implements WebappAuthenticator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setProperties(Properties properties) {
|
public Properties getProperties() {
|
||||||
this.properties = properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Properties getProperties() {
|
public void setProperties(Properties properties) {
|
||||||
return properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -198,11 +202,4 @@ public class JWTAuthenticator implements WebappAuthenticator {
|
|||||||
}
|
}
|
||||||
return this.properties.getProperty(name);
|
return this.properties.getProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadTenantRegistry(int tenantId) throws RegistryException {
|
|
||||||
TenantRegistryLoader tenantRegistryLoader = AuthenticatorFrameworkDataHolder.getInstance().
|
|
||||||
getTenantRegistryLoader();
|
|
||||||
AuthenticatorFrameworkDataHolder.getInstance().getTenantIndexingLoader().loadTenantIndex(tenantId);
|
|
||||||
tenantRegistryLoader.loadTenantRegistry(tenantId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user