Create vcs root using Teamcity REST API - continuous-integration

I am trying to create a VCS Root using Teamcity REST API. Following the REST Documentation, I am posting below XML to http://TeamcityServer/httpAuth/app/rest/vcs-roots
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vcs-root name="TestVCS" vcsName="svn" modificationCheckInterval="5" href="/httpAuth/app/rest/vcs-roots/id:TestVCS">
<project id="TestProject" name="<Root project>" href="/httpAuth/app/rest/projects/id:TestProject"/>
<properties>
<property name="externals-mode" value="externals-full"/>
<property name="labelingMessage" value="Labeled automatically by TeamCity"/>
<property name="labelingPatterns" value="trunk=>tags"/>
<property name="svn-config-directory" value="C:\Windows\system32\config\systemprofile\AppData\Roaming\Subversion"/>
<property name="svn-use-default-config-directory" value="true"/>
<property name="url" value="https://svn-uat.net/TestProject"/>
<property name="user" value="testuser"/>
<property name="password" value="testpwd"/>
<property name="working-copy-format" value="1.6"/>
</properties>
<vcsRootInstances href="/httpAuth/app/rest/vcs-root-instances?locator=vcsRoot:(id:TestVCS)"/>
</vcs-root>
This creates VCS root but the password property remains empty. I tried setting password explicitly using http://TeamcityServer/httpAuth/app/rest/vcs-roots/VCSId/properties/password , but even this doesn't seem to set the password for the VCS root.

So I found the answer on Jetbrains Developer Community. This is because Teamcity for security reasons uses "secure:svn-password" for SVN and "secure:passwd" for Perforce rather than simple password. So I changed my XML to something like:
<property name="secure:svn-password" value="testpwd"/>

Related

How to configure Oracle's Database Network Encryption with MyBatis?

I have a requirement to encrypt the data in transit between the web server and the database server using Mybatis as the persistence framework.
The database server is Oracle 12c Enterprise Edition Release 12.1.0.2.0 - 64bit. I am using the ojdbc7.jar driver.
I am able to establish an encrypted connection as described here... https://docs.oracle.com/database/121/DBSEG/asojbdc.htm#DBSEG9613. However, I have not been able to do so through MyBatis. I am setting the connection properties in the mybatis-config.xml file. Below are the contents of that file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC '-//mybatis.org//DTD Config 3.0//EN' 'http://mybatis.org/dtd/mybatis-3-config.dtd'>
<configuration>
<settings>
<setting name="lazyLoadingEnabled" value="false" />
<setting name="jdbcTypeForNull" value="NULL"/>
</settings>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#//<server>:<port>/<service>"/>
<property name="username" value="<username>"/>
<property name="password" value="<password>"/>
<property name="poolMaximumActiveConnections" value="20"/>
<property name="poolMaximumIdleConnections" value="10"/>
<property name="poolMaximumCheckoutTime" value="180000"/>
<property name="poolPingQuery" value="select 0 from dual"/>
<property name="poolPingEnabled" value="true"/>
<property name="poolPingConnectionsNotUsedFor" value="1800000"/>
<property name="CONNECTION_PROPERTY_THIN_NET_ENCRYPTION_LEVEL" value="REQUIRED"/>
<property name="CONNECTION_PROPERTY_THIN_NET_ENCRYPTION_TYPES" value="AES256"/>
</dataSource>
</environment>
</environments>
</configuration>
The last two property elements are my attempt at configuring an encrypted connection. Without them I am able to connect successfully without encryption. With the last two property elements I just get an error:
Caused by: org.apache.ibatis.exceptions.PersistenceException: ###
Error building SqlSession. ### The error may exist in SQL Mapper
Configuration ### Cause: org.apache.ibatis.builder.BuilderException:
Error parsing SQL Mapper Configuration. Cause:
org.apache.ibatis.datasource.DataSourceException: Unknown DataSource
property: CONNECTION_PROPERTY_THIN_NET_ENCRYPTION_TYPES
Does anybody know how to solve this?
The names of the JDBC properties are not quite right. Note that they can be found in the JavaDoc under oracle.jdbc.OracleConnection. You can try these:
EDIT: as Chris explained in this comments MyBatis requires the driver's property name to be prefixed with "driver".
<property name="driver.oracle.net.encryption_client" value="REQUIRED"/>
<property name="driver.oracle.net.encryption_types_client" value="(AES256)"/>

How to use different configuration for deployment?

I am currently dealing with the deployment of my web-server which is why I am facing a presumably very common problem: Configuration files
As a very straight forward example let's take a database. I have a local database.xml which contains the data source which I use on my local machine:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/mz_db" />
<property name="username" value="postgres" />
<property name="password" value="pg" />
</bean>
but of course, I am connecting to a different database once I deploy the server. So what are my options here? I would like to have this as centralized as possible to prevent wrong files being deployed here. I am sure that maven can be used for this somehow.
I was thinking about doing something like creating two config/ directories
WEB-INF/config/
WEB-INF/config-dev/
and use config-dev/ per default without the exception of the deploy phase or something like this. I am not sure if this can be done or if this is the best way of doing it.
Any suggestions?

Spring + Spring Data JPA Configuration

currently I'm fooling around with a Spring setup. My goal is to use JPA to get access to a Websphere datasource using it's JNDI name. I'm using Spring Data JPA to make life easier for me and worked through some tutorials to get the basic idea.
Bad thing: none of those is talking about the Spring configuration for my JPA szenario + I never worked with JPA / JDBC before.
So I hope you can help me out here. I got 2 configuration files:
applicationContext.xml
<bean id="txManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<bean id="eManager" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"></bean>
Since i'm using the #Transactual annotion within my code, i'm using the annotation-driven tag for the txManager. I'm just not really sure what else i should configure for the txManager and what the sessionFactory tag is doing. Is there any documentation for all supported XML tags? Am I missing a importent tag for my szenario?
Same about eManager - not sure if thats right in any way.
persistence.xml
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="spring-jpa">
<jta-data-source>jdbc/myJNDI</jta-data-source>
</persistence-unit>
</persistence>
Same thing here: don't really know what i'm doing. I know i need a persistence unit / provider. I know that many are using hibernate for this, but i would like to stay native and use pure JavaEE / Spring if possible.
I'm just not sure how to configure that.
Currently my project is crashing, telling me: "JPA PersistenceProvider returned null"
The best way is to obtain the EntityManagerFactory from the JNDI via Spring's JNDI support:
<jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/myPersistenceUnit" />
<jpa:repositories base-package="com.acme.repositories" />
<tx:jta-transactionManager />
This will cause the transaction manager being used from the application server as well. You can also try to setup a JpaTransactionManager and wire the EntityManagerFactory obtained from JNDI into it. You can pull even more configuration into your Spring config files if you only lookup the datasource through an <jee:jndi-lookup /> namespace element and follow the further configuration instructions in the Spring Data JPA reference documentation. Nevertheless it's usually better to use the container resources you can actually get if you decide to use container resources at all.
I just started working with Spring, jpa mysql etc... and I might be able to help you out.
I'll show you the way that I have my configuration right know.
I'm using hibernate by the way for my database connection, I've never did it without so no help from me there :)
My configuration:
Spring-config.xml:
<context:component-scan base-package="com.MYPACKAGE"/>
<!-- To find all your controllers -->
<tx:annotation-driven/>
<!-- This will pickup all your #Transactional annotations-->
<import resource="../database/DataSource.xml"/>
<import resource="../database/Hibernate.xml"/>
<!-- These are my database config files-->
Datasource.xml:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/DATABASENAME"/>
<property name="username" value="USERNAME"/>
<property name="password" value="PASSWORD"/>
</bean>
Hibernate.xml:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false"/>
<property name="generateDdl" value="true"/>
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/>
</bean>
</property>
</bean>
I left out the standard xml text that you need to include at the top of your .xml files, but I trust you to work that out yourself ;)
This setup works for me and I hope it can help you out!
If you have any question regarding this post please let me know!
Good luck!
for those using JBoss, the jndi names can be set in persistence.xml properties like this:
<persistence-unit name="punit" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/myDS/jta-data-source>
<class>com.company.model.Document</class>
<class>com.company.model.DocumentIndividual</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create" />
<!-- <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/> -->
<property name="javax.persistence.logging.level" value="INFO" />
<property name="hibernate.show_sql" value="true" />
<property name="jboss.entity.manager.jndi.name" value="java:/my_em"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/my_emf"/>
</properties>
</persistence-unit>
as described in here section 4.4.2

Passing encrypted properties to spring context

I never seen this but I wondering if somebody has come across. Having a web server which access a database. I want to pass the database password encrypted and have spring context decrypting it before setting the datasource. I know the spring security can do some of this like using a salt file in the web server, etc.
The challenge here is that I don't want to give a clear user,password,url to the web server team. Just an encrypted password and have spring decrypted before using it.
Is there something like this already? I know I could code something but is it already done?
Thanks
By using an org.jasypt.properties.EncryptableProperties object, an application would be able to correctly read and use a .properties file like this:
datasource.driver=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://localhost/reportsdb
datasource.username=reportsUser
datasource.password=ENC(G6N718UuyPE5bHyWKyuLQSm02auQPUtm)
Note that the database password is encrypted (in fact, any other property could also be encrypted, be it related with database configuration or not).
More information :
http://www.jasypt.org/encrypting-configuration.html
I actually found exactly what I was looking for in this thread:
How to use encrypted password in apache BasicDataSource?
Here are the details from jasyp http://www.jasypt.org/spring3.html
This problem and solution to it is explained here..(link)
db.Properties.
#driverClassName=oracle.jdbc.driver.OracleDriver
#url=jdbc:oracle:thin:#localhost:1521:XE
#username=ITEM_INVENTORY
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/ITEM_INVENTORY?zeroDateTimeBehavior=convertToNull
username=root
Encrypt db.Properties
##password=cGFzc3dvcmQ=
password=cm9vdA==
The spring beans configuration for the datasource would look like this
(here you may use only password part)
spring-beans.xml
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="db#[driverClassName]" />
<property name="url" value="db#[url]" />
<property name="username" value="db#[username]" />
<property name="password" value="encryptedDb#[password]" />
</bean>
<bean id="dbPropertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:db.properties</value>
</list>
</property>
<property name="placeholderPrefix" value="db#[" />
<property name="placeholderSuffix" value="]" />
</bean>
<bean id="encryptedDbPropertyPlaceholder" class="com.inventory.api.util.DecryptPropertyConfigurer">
<property name="locations">
<list>
<value>classpath:encryped_db.properties</value>
</list>
</property>
<property name="placeholderPrefix" value="encryptedDb#[" />
<property name="placeholderSuffix" value="]" />
</bean>
And so on.. please refer given link for more information..

Setting V$SESSION.program property on Glassfish JDBC Connection Pool

my Java EE App is deployed on Glassfish 3.0.1, and uses a JDBC Connection Pool to Connect to an Oracle 9i database. I am using JPA to read/write data to the database, which is working fine. However, to get better reporting regarding the load this app is putting on the database, I want to set the V$SESSION.program column for use by oracle.
From various google searches (eg. http://forums.oracle.com/forums/thread.jspa?messageID=3271623) it looks like I should just be able to add this as a property, the same as you would set any other property. So I have tried this by changing the domain.xml file for Glassfish (see below), and the V$SESSION.program property is now set on the JDBC connection pool when I view it using the Glassfish Admin Console (When I start up the glassfish server, go to the admin page and browse to Resources->JDBC->Connection Pools->MyConnectionPool->Additional Properties I can see an entry for V$SESSION.program set appropriately).
However, when I query the Oracle Database for the connections (SELECT * FROM V$SESSION), they have the same V$SESSION.program as before (which is "JDBC Thin Client"), rather than the one I set in the domain.xml and which I can see as a property of the JDBC Connection Pool on the Glassfish Admin Page.
The resources section of my domain.xml is below:
<resources>
<jdbc-connection-pool pool-resize-quantity="4" max-pool-size="16" datasource-classname="oracle.jdbc.pool.OracleDataSource" res-type="javax.sql.DataSource" steady-pool-size="4" name="mydatabasename">
<property name="datasourceName" value="OracleConnectionPoolDataSource" />
<property name="databaseName" value="mydatabasename" />
<property name="password" value="mypassword" />
<property name="portNumber" value="1521" />
<property name="serverName" value="myservername" />
<property name="url" value="jdbc:oracle:thin:#myservername:1521:mydatabasename" />
<property name="user" value="myuser" />
<property name="v$session.program" value="MyGlassfishApp" />
</jdbc-connection-pool>
<jdbc-resource pool-name="mydatabasename" jndi-name="jdbc/mydatabasename" />
</resources>
And my Persistence.xml is as below (I've deleted all the <class>...</class> lines):
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="Persistence-ejb" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/mydatabasename</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.query.timeout" value="60"/>
<property name="javax.persistence.lock.timeout" value="60"/>
<property name="javax.persistence.target-server" value="SunAS9"/>
<!-- Disable caching so we always use the DB directly -->
<property name="eclipselink.cache.shared.default" value="false"/>
<property name="eclipselink.query-results-cache" value="false"/>
</properties>
</persistence-unit>
</persistence>
EDIT:
I have tried v$session.program, V$SESSION.PROGRAM and V$SESSION.program - none have worked though... I have also tried setting the V$SESSION.program property on the EntityManager, but that didn't work (I didn't really expect it to since from what I understand the EntityManager properties are only to do with the JPA layer, not the underlying connection to the Database - but I'm trying stuff out of desperation...)
I also tried using a SessionCustomizer as suggested here. The SessionCustomizer code I used is below:
public class ProgramSessionCustomizer implements SessionCustomizer {
private static Logger logger = Logger.getLogger(ProgramSessionCustomizer.class);
#Override
public void customize(Session s) throws Exception {
logger.error("ProgramSessionCustomizer setting v$session.program");
s.getDatasourceLogin().setProperty("v$session.program", "MYprogramTEST");
logger.error("ProgramSessionCustomizer has set v$session.program");
}
}
I then set the SessionCustomizer in the persistence.xml by adding the property:
<property name="eclipselink.session.customizer" value="persistence.config.ProgramSessionCustomizer"/>
I can see the log lines, so the Customizer is definitely being called. However, I don't see the program set in the database, and I don't even see it set when I browse to the JDBC connection pool properties on the Glassfish Admin Console (which, as I said above, I do see when I set the property using the glassfish domain.xml)
Again, any more suggestions would be very welcome as I'm at a loss!
I finally found out how to set this connection property in WebSphere 8 too for a XA datasource. It can be set in the WebSphere admin console:
Resources > JDBC providers > [Oracle JDBC Driver (XA)] > Data Sources > [data source name] > Custom properties
Just add there a property with a key: connectionProperties and its value: v$session.program:PUT_YOUR_NAME_HERE
This works for me using Spring. It should works for yours Java EE app as well. The idea is to set the v$session param indirectly via properties passed to connectionProperties property
<bean class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
<property name="URL" value="${configDb.url}"/>
<property name="user" value="${configDb.user}"/>
<property name="password" value ="${configDb.password}"/>
<property name="connectionCachingEnabled" value="true"/>
<property name="connectionProperties">
<value>v$session.program:PUT_YOUR_NAME_HERE</value>
</property>
</bean>

Resources