Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/main/java/com/iemr/common/CommonApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,20 @@

import com.iemr.common.utils.IEMRApplBeans;

/**
* @author VI314759
*
*/
@SpringBootApplication
public class CommonApplication extends SpringBootServletInitializer {
/**
* @return
*/

@Bean
public IEMRApplBeans instantiateBeans() {
return new IEMRApplBeans();
}

/**
* @param args
*/
public static void main(String[] args) {
SpringApplication.run(commonApplication, args);
SpringApplication.run(CommonApplication.class, args);
}

protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(new Class[] { CommonApplication.class });
}

private static Class<CommonApplication> commonApplication = CommonApplication.class;
}
4 changes: 1 addition & 3 deletions src/main/java/com/iemr/common/config/PrimaryDBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", basePackages = { "com.iemr.common.repository",
"com.iemr.common.repo", "com.iemr.common.notification.agent", "com.iemr.common.covidVaccination" })
public class PrimaryDBConfig {

@Autowired
private CryptoUtil cryptoUtil;
Logger logger = LoggerFactory.getLogger(this.getClass().getName());
Expand All @@ -52,8 +52,6 @@ public DataSource dataSource() {
org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource();
datasource.setPoolProperties(p);



datasource.setUsername(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbUserName")));
datasource.setPassword(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbPass")));

Expand Down
90 changes: 39 additions & 51 deletions src/main/java/com/iemr/common/config/SecondaryDBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
Expand All @@ -25,60 +24,49 @@

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "secondaryEntityManagerFactory",
transactionManagerRef = "secondaryTransactionManager",
basePackages = { "com.iemr.common.secondary.repository.callreport" }
)
@EnableJpaRepositories(entityManagerFactoryRef = "secondaryEntityManagerFactory", transactionManagerRef = "secondaryTransactionManager", basePackages = {
"com.iemr.common.secondary.repository.callreport" })
public class SecondaryDBConfig {

@Autowired
private CryptoUtil cryptoUtil;

Logger logger = LoggerFactory.getLogger(this.getClass().getName());

@Bean(name = "secondaryDataSource")
@ConfigurationProperties(prefix = "secondary.datasource")
public DataSource dataSource() {
PoolConfiguration p = new PoolProperties();
p.setMaxActive(30);
p.setMaxIdle(15);
p.setMinIdle(5);
p.setInitialSize(5);
p.setMaxWait(10000);
p.setMinEvictableIdleTimeMillis(15000);
p.setRemoveAbandoned(true);
p.setLogAbandoned(true);
p.setRemoveAbandonedTimeout(600);
p.setTestOnBorrow(true);
p.setValidationQuery("SELECT 1");
org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource();
datasource.setPoolProperties(p);

@ConfigurationProperties(prefix = "secondary.datasource")
public DataSource dataSource() {
PoolConfiguration p = new PoolProperties();
p.setMaxActive(30);
p.setMaxIdle(15);
p.setMinIdle(5);
p.setInitialSize(5);
p.setMaxWait(10000);
p.setMinEvictableIdleTimeMillis(15000);
p.setRemoveAbandoned(true);
p.setLogAbandoned(true);
p.setRemoveAbandonedTimeout(600);
p.setTestOnBorrow(true);
p.setValidationQuery("SELECT 1");
org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource();
datasource.setPoolProperties(p);

datasource.setUsername(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbUserNameSec")));
datasource.setPassword(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbPassSec")));

return datasource;
}

@Bean(name = "secondaryEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean barEntityManagerFactory(EntityManagerFactoryBuilder builder,
@Qualifier("secondaryDataSource") DataSource dataSource) {
return builder.dataSource(dataSource).packages("common.iemr.common.secondary.data.report")
.persistenceUnit("db_reporting").build();
}

datasource.setUsername(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbUserNameSec")));
datasource.setPassword(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbPassSec")));

return datasource;
}

@Bean(name = "secondaryEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean
barEntityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier("secondaryDataSource") DataSource dataSource
) {
return
builder
.dataSource(dataSource)
.packages("common.iemr.common.secondary.data.report")
.persistenceUnit("db_reporting")
.build();
}
@Bean(name = "secondaryTransactionManager")
public PlatformTransactionManager barTransactionManager(
@Qualifier("secondaryEntityManagerFactory") EntityManagerFactory
secondaryEntityManagerFactory
) {
return new JpaTransactionManager(secondaryEntityManagerFactory);
}
@Bean(name = "secondaryTransactionManager")
public PlatformTransactionManager barTransactionManager(
@Qualifier("secondaryEntityManagerFactory") EntityManagerFactory secondaryEntityManagerFactory) {
return new JpaTransactionManager(secondaryEntityManagerFactory);
}
}
30 changes: 10 additions & 20 deletions src/main/java/com/iemr/common/config/encryption/SecurePassword.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import org.springframework.stereotype.Service;

@Service
public class SecurePassword
{
public String generateStrongPassword(String password) throws NoSuchAlgorithmException, InvalidKeySpecException
{
public class SecurePassword {
public String generateStrongPassword(String password) throws NoSuchAlgorithmException, InvalidKeySpecException {
int iterations = 1000;
char[] chars = password.toCharArray();
byte[] salt = getSalt();
Expand All @@ -25,31 +23,26 @@ public String generateStrongPassword(String password) throws NoSuchAlgorithmExce
return iterations + ":" + toHex(salt) + ":" + toHex(hash);
}

private byte[] getSalt() throws NoSuchAlgorithmException
{
private byte[] getSalt() throws NoSuchAlgorithmException {
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
byte[] salt = new byte[16];
sr.nextBytes(salt);
return salt;
}

private String toHex(byte[] array) throws NoSuchAlgorithmException
{
private String toHex(byte[] array) {
BigInteger bi = new BigInteger(1, array);
String hex = bi.toString(16);
int paddingLength = array.length * 2 - hex.length();
if (paddingLength > 0)
{
if (paddingLength > 0) {
return String.format(new StringBuilder().append("%0").append(paddingLength).append("d").toString(),
new Object[]
{ Integer.valueOf(0) }) + hex;
new Object[] { Integer.valueOf(0) }) + hex;
}
return hex;
}

public boolean validatePassword(String originalPassword, String storedPassword)
throws NoSuchAlgorithmException, InvalidKeySpecException
{
throws NoSuchAlgorithmException, InvalidKeySpecException {
String[] parts = storedPassword.split(":");
int iterations = Integer.parseInt(parts[0]);
byte[] salt = fromHex(parts[1]);
Expand All @@ -60,18 +53,15 @@ public boolean validatePassword(String originalPassword, String storedPassword)
byte[] testHash = skf.generateSecret(spec).getEncoded();

int diff = hash.length ^ testHash.length;
for (int i = 0; (i < hash.length) && (i < testHash.length); i++)
{
for (int i = 0; (i < hash.length) && (i < testHash.length); i++) {
diff |= hash[i] ^ testHash[i];
}
return diff == 0;
}

private byte[] fromHex(String hex) throws NoSuchAlgorithmException
{
private byte[] fromHex(String hex) {
byte[] bytes = new byte[hex.length() / 2];
for (int i = 0; i < bytes.length; i++)
{
for (int i = 0; i < bytes.length; i++) {
bytes[i] = ((byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16));
}
return bytes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
package com.iemr.common.config.prototype;

import lombok.Data;

@Data
/**
* @author VI314759
*
*/
public class BeneficiaryOccupation
{
public class BeneficiaryOccupation {
private Long occupationID;
private String occupationType;
private Boolean deleted;
Expand All @@ -17,8 +9,60 @@ public class BeneficiaryOccupation
private String key;
private String operation;

public BeneficiaryOccupation()
{
public Long getOccupationID() {
return occupationID;
}

public String getOccupationType() {
return occupationType;
}

public Boolean getDeleted() {
return deleted;
}

public String getCreatedby() {
return createdby;
}

public String getModifiedby() {
return modifiedby;
}

public String getKey() {
return key;
}

public String getOperation() {
return operation;
}

public void setOccupationID(Long occupationID) {
this.occupationID = occupationID;
}

public void setOccupationType(String occupationType) {
this.occupationType = occupationType;
}

public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}

public void setCreatedby(String createdby) {
this.createdby = createdby;
}

public void setModifiedby(String modifiedby) {
this.modifiedby = modifiedby;
}

public void setKey(String key) {
this.key = key;
}

public void setOperation(String operation) {
this.operation = operation;
}

}
Loading