Check user's password on LDAP from JAVA application - java

I've never used LDAP. I have to write a JAVA class which check if the password given by the user is correct. Users/password are stored in the LDAP server of WSO2IS. This is the configuration:
<UserManager>
<Realm>
<Configuration>
<AddAdmin>true</AddAdmin>
<AdminRole>admin</AdminRole>
<AdminUser>
<UserName>admin</UserName>
<Password>admin</Password>
</AdminUser>
<EveryOneRoleName>everyone</EveryOneRoleName> <!-- By default users in this role sees the registry root -->
<Property name="dataSource">jdbc/WSO2CarbonDB</Property>
<Property name="MultiTenantRealmConfigBuilder">org.wso2.carbon.user.core.config.multitenancy.CommonLDAPRealmConfigBuilder</Property>
</Configuration>
<UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager">
<Property name="TenantManager">org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager</Property>
<Property name="ConnectionURL">ldap://localhost:10389</Property>
<Property name="Disabled">false</Property>
<Property name="ConnectionName">uid=admin,ou=system</Property>
<Property name="ConnectionPassword">admin</Property>
<Property name="passwordHashMethod">SHA</Property>
<Property name="UserNameListFilter">(objectClass=person)</Property>
<Property name="UserEntryObjectClass">identityPerson</Property>
<Property name="UserSearchBase">ou=Users,dc=wso2,dc=org</Property>
<Property name="UserNameSearchFilter">(&(objectClass=person)(uid=?))</Property>
<Property name="UserNameAttribute">uid</Property>
<Property name="UsernameJavaRegEx">[a-zA-Z0-9._-|//]{3,30}$</Property>
<Property name="UsernameJavaScriptRegEx">^[\S]{3,30}$</Property>
<Property name="RolenameJavaScriptRegEx">^[\S]{3,30}$</Property>
<Property name="RolenameJavaRegEx">[a-zA-Z0-9._-|//]{3,30}$</Property>
<Property name="PasswordJavaScriptRegEx">^[\S]{5,30}$</Property>
<Property name="ReadGroups">true</Property>
<Property name="WriteGroups">true</Property>
<Property name="EmptyRolesAllowed">false</Property>
<Property name="GroupSearchBase">ou=Groups,dc=wso2,dc=org</Property>
<Property name="GroupNameListFilter">(objectClass=groupOfNames)</Property>
<Property name="GroupEntryObjectClass">groupOfNames</Property>
<Property name="GroupNameSearchFilter">(&(objectClass=groupOfNames)(cn=?))</Property>
<Property name="GroupNameAttribute">cn</Property>
<Property name="SharedGroupNameAttribute">cn</Property>
<Property name="SharedGroupSearchBase">ou=SharedGroups,dc=wso2,dc=org</Property>
<Property name="SharedGroupEntryObjectClass">groupOfNames</Property>
<Property name="SharedGroupNameListFilter">(objectClass=groupOfNames)</Property>
<Property name="SharedGroupNameSearchFilter">(&(objectClass=groupOfNames)(cn=?))</Property>
<Property name="SharedTenantNameListFilter">(objectClass=organizationalUnit)</Property>
<Property name="SharedTenantNameAttribute">ou</Property>
<Property name="SharedTenantObjectClass">organizationalUnit</Property>
<Property name="MembershipAttribute">member</Property>
<Property name="UserRolesCacheEnabled">true</Property>
<Property name="ReplaceEscapeCharactersAtUserLogin">true</Property>
<Property name="MaxRoleNameListLength">100</Property>
<Property name="MaxUserNameListLength">100</Property>
<Property name="SCIMEnabled">false</Property>
</UserStoreManager>
<AuthorizationManager
class="org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager">
<Property name="AdminRoleManagementPermissions">/permission</Property>
<Property name="AuthorizationCacheEnabled">true</Property>
</AuthorizationManager>
</Realm>
Can you please help me?. I've no idea where to start. Thank you.

You need to check the user/password of the users using some authentication API. There is Web service service called RemoteUserStoreManagerService that you can use to verify user/password of the user. Also this API can be used to manage the users in the LDAP. You can add/update/delete LDAP users. More details about the API can be found from here with simple java client to invoke this API

Related

Problem when uploading XML (mixed properties)

I have a little problem when I try to upload XML file to BaseLinker.
The problem is that the properties in XML are mixed, for example one time property name of price is 4th, next time is 6th or 8th. Because of it BaseLinker didn't upload it correctly.
Some of my XML :
<property name="grubość">1</property>
<property name="grubość ścianki">1</property>
<property name="średnica">400</property>
<property name="wysokość">400</property>
<property name="Pojemność (l)">50</property>
<property name="opis">400</property>
<property name="wymiary zewnętrzne">400</property>
<property name="waga">50</property>
<property name="wymiary">1</property>
<property name="moc">1</property>
<property name="napięcie">400x/400h</property>
<property name="categoryId">194</property>
<property name="productCode">832806</property>
<property name="largeSize">0</property>
<property name="tillStockLasts">0</property>
<property name="basePrice">749.00</property>
<property name="productId">950</property>
other line :
<property name="wysokość">450</property>
<property name="wymiary zewnętrzne">śr. 450x(H) 450 </property>
<property name="Pojemność (l)">70</property>
<property name="wymiary">śr.450x(H)450</property>
<property name="categoryId">194</property>
<property name="productCode">832929</property>
<property name="largeSize">0</property>
<property name="tillStockLasts">0</property>
<property name="basePrice">849.00</property>
<property name="productId">950</property>
Is it possible to parse it or use java program that can sort it in correct order?
For example I wanna have XML of properties like :
property name="wysokość" property name="szerokosc" property name="productCode" property name="productID"
and so on...

Apache Ignite nodes fail: Failed to read magic header

Apache Ignite servers deployed on two machines automatically shut down. No concrete clue in logs. I am able to see following warning message in log file :
[00:35:14,047][WARNING][tcp-disco-sock-reader-#86379%null%][TcpDiscoverySpi] Failed to read magic header (too few bytes received) [rmtAddr=/10.96.36.48:47830, locAddr=/10.96.36.48:47500]
How can i debug and solve this issue ?
Configuration:
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="peerClassLoadingEnabled" value="true"/>
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="xyxCache" />
<property name="writeSynchronizationMode" value="FULL_SYNC" />
<property name="cacheMode" value="REPLICATED" />
<property name="rebalanceMode" value="SYNC" />
<property name="readFromBackup" value="true" />
<property name="startSize" value="150000" />
<property name="evictionPolicy">
<bean class="org.apache.ignite.cache.eviction.lru.LruEvictionPolicy">
<property name="maxSize" value="1000000" />
</bean>
</property>
</bean>
</list>
</property>
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
<property name="addresses">
<list>
<value>10.96.36.48:47500</value>
<value>10.96.36.214:47500</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
Check which process on 10.96.36.48 machine binded to port 47830.
For example, netstat -lnp will list the pid and process name next to each listening port. This will work under Linux.
This usually happens if some other application like telnet connects to the port.
Please share your configuration and setup details, without which it is not possible to answer any further.

Can't retrieve data when using IP address as URL for my web app

I have a working web application built using the following technologies:
Spring MVC, Java, Hibernate, Oracle Database.
It works fine when I use http://localhost:8080/WebAppName. However, when I use http://:8080/WebAppName, it cannot pull any data. Logs show that there no attempt at all to access the database server.
I tried changing the config of the server.xml in tomcat (as I have found in several questions similar to my problem), such as adding useIPVHosts="true", resolveHosts="true", address="0.0.0.0". All didn't work.
Perhaps there are other configuration files that I need to check/change. Any suggestions will be greatly appreciated. Thanks in advance.
Below is my hibernate configuration:
<bean id="dataSourceDEV1" class="org.apache.commons.dbcp2.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#//rac-hr-qa:20001/WBD1" />
<property name="username" value="workbrain" />
<property name="password" value="xxxxxxxxxx" />
</bean>
<bean id="sessionFactoryDEV1"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceDEV1" />
<property name="configLocation"
value="classpath:/com/safeway/web/resources/dev1-hibernate.cfg.xml" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.id.new_generator_mappings">false</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.safeway.web.dao</value>
</list>
</property>
</bean>
<bean id="transactionManagerDEV1"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactoryDEV1" />
</bean>
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">validate</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="show_sql">true</property>
<property name="connection.pool_size">5</property>
<property name="temp.use_jdbc_metadata_defaults">false</property>
<property name="hibernate.jdbc.use_get_generated_keys">true</property>
<mapping class="com.safeway.model.CalculationGroup"></mapping>
<mapping class="com.safeway.model.CalcGroupVesrion"></mapping>
<mapping class="com.safeway.model.CalcGroupHistory"></mapping>
</session-factory>
</hibernate-configuration>
You need to use an ip address with the port.
http://:8080/WebAppName
should be
http://127.0.0.1:8080/WebAppName
for the IP address of localhost.

Hibernate: why c3p0 timeout not working?

I work on web java application using hibernate, and i always get memory low errors for tons of java inactive sessions on my oracle db. i tried to closing this unused sessions with c3p0 timeout config but it's not working at all.
this is my hibernate config and my open sessions after several minutes:
(the commented code below is for when i tried using common dbcp refer to one of answers for similar questions and timeout times set to 30 seconds for test.)
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#localhost:test</property>
<property name="hibernate.connection.username">tams_test</property>
<property name="hibernate.connection.password">test1234</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.connection.isolation">2</property>
<property name="org.hibernate.flushMode">COMMIT</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="hibernate.order_updates">true</property>
<property name="hibernate.order_inserts">true</property>
<!-- <property name="hibernate.dbcp.initialSize">3</property>
<property name="hibernate.dbcp.maxIdle">50</property>
<property name="hibernate.dbcp.minIdle">0</property>
<property name="hibernate.dbcp.maxWait">180000</property>
<property name="hibernate.dbcp.maxConnLifetimeMillis">30000</property>
<property name="hibernate.dbcp.defaultQueryTimeout">1</property>-->
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">150</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.timeout">30</property>
<property name="hibernate.c3p0.idle_test_period">30</property>
<property name="hibernate.c3p0.idleConnectionTestPeriod">30</property>
<property name="c3p0.testConnectionOnCheckout">true</property>
<property name="testConnectionOnCheckin">true</property>
<property name="c3p0.maxConnectionAge">30</property>
<property name="maxIdleTimeExcessConnections">30</property>
<property name="connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</property>
open sessions on oracle db after several minutes
I faced your problem too, and hibernate didn't want to apply my parameters of c3p0, so I changed my datasource and it completly solved my problem of inactive sessions.
Try to setup your dataSource bean like this:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
<property name="jdbcUrl" value="jdbc:oracle:thin:#xxxx:1521:xxx"/>
<property name="user" value="xx"/>
<property name="password" value="xxxx"/>
<property name="maxStatements" value="1000"/>
<property name="maxIdleTime" value="30"/>
<property name="maxPoolSize" value="100"/>
<property name="minPoolSize" value="10"/>
<property name="initialPoolSize" value="10"/>
<property name="idleConnectionTestPeriod" value="20"/>
</bean>

HikariCP - Idle Timout property is not overriding

Inspite of overriding the HikariCP idleTimeout property "hibernate.hikari.idleTimeout", connection is not releasing after threshold. I am using sql command SHOW FULL PROCESSLIST to analyze the connections.
<property name="hibernate.hikari.dataSource.url" value="${DATABASE_URL}"/>
<property name="hibernate.hikari.dataSource.user" value="${DATABASE_USERNAME}"/>
<property name="hibernate.hikari.dataSource.password" value="${DATABASE_PASSWORD}"/>
<property name="hibernate.hikari.dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"/>
<property name="hibernate.connection.provider_class" value="com.zaxxer.hikari.hibernate.HikariConnectionProvider"/>
<property name="hibernate.hikari.maxLifetime" value="1800000"/>
<property name="hibernate.hikari.idleTimeout" value="60000"/>
<property name="hibernate.hikari.connectionTimeout" value="180000" />
<property name="hibernate.hikari.maximumPoolSize" value="10"/>
<property name="hibernate.hikari.minimumIdle" value="5"/>
Is the - at the end of hibernate.hikari.maxLifetime causing you problems?
<property name="hibernate.hikari.maxLifetime" value="1800000"/> -

Categories