w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Configure SSL certificates with Hibernate, Spring and JDBC
The MySQL guide has information on what to do on the client side, this bug also has some detailed information. It basically comes done to the following steps Create a keystore and truststore with your clients certificate Configure your environment (or a MysqlDataSource) to use these keystore and truststore Configure the connection URL properly (which is what you apparently already have done). And that should be it. The key is to have the correct certificates on the client side. More information: Secure JDBC connection to MySQL from GlassFish Secure JDBC connection to MySQL from Java MySQL SSL Documentation

Categories : Mysql

Configure spring security ldap-server attribute to use different url based on deployed environment
I've done that with Spring profiles: In your spring.*.xml config file use this at the end of your file: <beans profile="production"> ... </beans> <beans profile="local"> ... </beans> As VM Arguments the used profile must be provided: -Dspring.profiles.active=production Regards

Categories : Spring

Java spring LDAP - Waring LDAP password expire
Credentials expiration date and time Getting the date and time at which the password was last changed: private final static long DIFF_NET_JAVA_FOR_DATE_AND_TIMES = 11644473600000L; long adDateTime = Long.parseLong(pwdLastSet); long milliseconds = (adDateTime / 10000) - DIFF_NET_JAVA_FOR_DATE_AND_TIMES; Date pwdLastSetDate = new Date(milliseconds); Getting the number of max days that could have the password: private final static int ONE_HUNDRED_NANOSECOND = 10000000; private final static long SECONDS_IN_DAY = 86400; long maxPwdAge = Math.abs(Long.parseLong(maxPwdAgeStr)); long maxPwdAgeSecs = maxPwdAge / ONE_HUNDRED_NANOSECOND; int maxPwdAgeDays = (int) (maxPwdAgeSecs / SECONDS_IN_DAY); Getting the the date and time at which the password will expire Calendar cal = Calendar.getInstan

Categories : Java

Spring JDBC Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
Make sure that you have ojdbc.jar gets added into your class path. If you want, you can also double check it by opening .classpath file and look for ojdbc.jar entry. If you don't have it, download it from the the maven repo as mentioned below: <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.3</version> </dependency> ....... <repositories> <repository> <id>codelds</id> <url>https://code.lds.org/nexus/content/groups/main-repo</url> </repository> </repositories>

Categories : Spring

Configure LDAP certificate dir in PHP 5.5.x (Windows)
I ran a trace with Sysinternals Process Explorer and it revealed that php_ldap was attempting to open the file C:Apache24\%SYSCONFDIR%ldap.conf, where %SYSCONFDIR% is interpreted literally and not expanded from the contents of an environment variable. I have Apache installed in C:Apache24, but obviously the exact path will vary depending on the name of your Apache folder. In the root folder of your Apache installation, create a folder named %SYSCONFDIR% (literally!) and put ldap.conf in there. That solved it for me.

Categories : PHP

how to configure ApacheDSUserStoreManager as an external ldap userstore manager in wso2 identity server
If you are using IS 4.0.0 or a later version ApacheDSUserStoreManager class has been removed from those releases. You need to change your configurations according to your version. You need to un-comment the below section from your user-mgt.xml and change the configurations accordingly. <!--UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager"> <Property name="ConnectionURL">ldap://localhost:10389</Property> <Property name="ConnectionName">uid=admin,ou=system</Property> <Property name="ConnectionPassword">secret</Property> <Property name="passwordHashMethod">PLAIN_TEXT</Property> <Property name="UserNameListFilter">(objectClass=person)</Property>

Categories : Misc

Configure JDBC Data Source for use with JNDI and Tomcat 6 in JSF 2 project
Have a look at Apache Tomcat JNDI How-To There you can read that you just need to modify/create projects context.xml in META-INF and web.xml in WEB-INF ... Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to your Context. <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/javatest"/> Now create a WEB-INF/web.xml for this test application. <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/TestDB</res-ref-name> <res-type>javax.sql.Data

Categories : Java

How to configure Spring BeanPostProcessor to get invoked only for a defined set of spring managed beans
I doubt if you can control purely by xml configuration/annotation. You can however control it within the code of the BeanPostProcessor: public Object postProcessBeforeInitialization(Object bean, String beanName) { if (thisBeanIsOfConcernToMe(bean, beanName){ doPostProcessTasks()... } } If this BeanProcessor is not under your control, then overriding the bean and delegating to the parent for certain custom conditions would be another way to go: public MyBeanProcessor extends NotUnderControlBeanPostProcessor { .... public Object postProcessBeforeInitialization(Object bean, String beanName) { if (thisBeanIsOfConcernToMe(bean, beanName){ return super.postProcessBeforeInitialization(bean, beanName) }else{ return bean; } }

Categories : Java

Spring+ LDAP integration
There is a special project in Spring called Spring Security for this purpose. The core functionality is built as a set of servlet API filters. There are multiple connectors for user's database (LDAP, DB, Active Directory, etc.) Here you can see how to add a basic conf. Your conf may looks like this: <http use-expressions="true"> <intercept-url pattern="/**" access="isAuthenticated()" /> <form-login /> <logout /> </http> Note that I prefer SpEL expressions for security rules. And here you can see how to add LDAP. Hope it helps.

Categories : Spring

Using Spring Security in Grails with CAS and LDAP
I've shared (GitHub) a sample app that integrates Grails (2.2.0) + Spring Security Plugin + CAS + LDAP. My work is based on this link: http://dominikschuermann.de/index.php/2010/11/using-grails-with-cas-and-ldap/, but unfortunately the link is not active. https://github.com/luizcantoni/TestCAS-LDAP-Grails This App authenticates using CAS. After authenticated, CAS redirect to Grails that populates (through ldap) the User with some Active Directory information (email and name). This is the file that populates the user with some AD information: https://github.com/luizcantoni/TestCAS-LDAP-Grails/blob/master/src/groovy/example/PrepopulateUserDetailsService.groovy Check the resources.groovy: https://github.com/luizcantoni/TestCAS-LDAP-Grails/blob/master/grails-app/conf/spring/resources.groo

Categories : Grails

Disable Spring Security (ldap auth) Temporarily
I know this is a year old, but I ran across wanting to do this exact same thing. I could not find any way to do it dynamically but I did find a way so that a simple change that could be done on one line in Config.groovy and a restart of the app that worked for me. grails.plugin.springsecurity.ldap.active = false and then put the other ldap config options in an if statement if (grails.plugin.springsecurity.ldap.active) { //All of the ldap options }

Categories : Java

Spring Security + LDAP: session is cleared right after Login
Solved. The problem was related to the redirection of the page after the login. I used the following line of code: FacesContext.getCurrentInstance().getExternalContext().redirect("inicio.xhtml"); I got the idea after reading this post The LoginBean.java looks as follows: public String doLogin() throws IOException, ServletException { try { ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); RequestDispatcher dispatcher = ((ServletRequest)context.getRequest()).getRequestDispatcher("/j_spring_security_check"); dispatcher.forward((ServletRequest)context.getRequest(), (ServletResponse)context.getResponse()); FacesContext.getCurrentInstance().responseComplete(); FacesContext.getCurre

Categories : JSF

Grails Spring Security & LDAP Auth Failure
Try these settings: grails.plugins.springsecurity.ldap.authorities.groupSearchBase ='DC=example,dc=org' grails.plugins.springsecurity.ldap.authorities.groupSearchFilter = 'member={0}'

Categories : Spring

Spring, Active Directory and workstation : Ldap Error code 351
This should help. 49 531 1329 ERROR_INVALID_WORKSTATION Entry not allowed to log on to this computer. We have some JNDI Samples that work with AD (Assuming you know the proper parameters) You may find it easier to utilize a LDAP Browser and authenticate with that first then you know what parameters will work. We like Apache Studio. -jim

Categories : Spring

Authenticate via spring LDAP with additional security check in database
You have to change your way of having the user Prancipal : You will keep you ldapProvider : <beans:bean id="ldapProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"> .... <beans:bean id="customUserDetailsMapper" class="xxxxx.CustomUserDetailsMapper"> <beans:constructor-arg ref="customUserDetailService" /> </beans:bean> <beans:bean id="customUserDetailService" class="xxxxxx.CustomUserDetailService"> </beans:bean> define a custom UserDatailsMapper : public class CustomUserDetailsMapper extends LdapUserDetailsMapper { private UserDetailsService userDetailService; public CustomUserDetailsMapper (UserDetailsService userDetailService) { this.userDetailService = userDetailService; } @Override p

Categories : Spring

Disabling SSL Certificate Validation for Active Directory server using spring-ldap 1.3.1
Well, Thanks to Darren Hauge for providing a tricky solution that will not care about ssl certificate. Rewriting the solution here : public static void trustSelfSignedSSL() { try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[]{tm}, null); SSLContext.setDefault(ctx); } catch (Exception ex) { ex.printStackTrace(); } } All we need to create a utility class

Categories : Java

What is the equivalent of Spring-JDBC in CDI?
CDI stands for Contexts/Dependency Injection (if I'm not mistaken). By itself it has nothing to do with SQL. Using CDI with JPA allows you to work with the database, but even in this case JPA does all the work. CDI has very little to do with it. If you want to work with native queries and JPA's nativeQuery isn't enough, you'll have to either add the Spring-JDBC dependency to your project, or since you're moving away from Spring, another smaller library that would give you things similar to JdbcTemplate and such. So to sum it up, CDI has no equivalent of Spring-JDBC, just as Spring doesn't have an equivalent of Swing GUI.

Categories : Java

Spring Security AD LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0906E8
Lets assume user is trying to login with username XXX and password YYY. Usually LDAP authentication works like this: Bind to the LDAP with technical account Search for the user with the username XXX => get his DN Try to bind to the LDAP using found DN and password YYY Your error is suggesting that you didnt't do the first step (technical account binding) correctly. Try adding userDn and password to your context source (this is from the official JavaDoc): <bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"> <constructor-arg value="ldap://monkeymachine:389/dc=springframework,dc=org"/> <property name="userDn" value="cn=manager,dc=springframework,dc=org"/> <property name="password" value="password"

Categories : Spring

Spring JDBC : unable to get dataSource
It thinks your class JDBCTemplate does not have a property named dataSource Perhaps you don't have a public method setDataSource() that has a single argument of the right type. Perhaps it is private. Perhaps it is spelled wrong.

Categories : Java

How to use transaction in Spring JDBC with Guice
You're using Spring JDBC, Spring transactions, but Guice for DI? Why? You're making things much more complex than needed. Your objects are probably not Spring beans, since Spring doesn't create and inject them, so @Transactional has no effect: Spring doesn't create and inject the objects, so it doesn't create and inject transactional proxies, so the annotation is never used by anything.

Categories : Java

Sql Sever with spring jdbc template
You can try this SQL String: String sql = "SELECT Mon, "CC Flag" FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY Msisdn)AS RowNum FROM ME_PREPAID) AS MyDerivedTable WHERE MyDerivedTable.RowNum BETWEEN 2 AND 100";

Categories : Java

tomcat jdbc and spring version compatability
These two stack overflow links will solve your problems. org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class Spring Web App - CannotLoadBeanClassException caused by Java.lang.ClassNotFoundException

Categories : Java

How to implement Generics DAO with Spring JDBC template
you can use generic CrudRepository from spring-data. or write something simillar: http://www.codeproject.com/Articles/251166/The-Generic-DAO-pattern-in-Java-with-Spring-3-and

Categories : Spring

Spring JDBC Adapter in Cluster mode
Unfortunately this will not be possible without some sort of syncing. Additionally using the database as some sort of message queue is not a good idea (http://mikehadlow.blogspot.de/2012/04/database-as-queue-anti-pattern.html). I'd try to follow different approaches: Use some sort of message bus + message store to store the jobs objects rather than executing SQL directly. In this case you'll have to change the way jobs are being stored. Either by using some sort of message store backed channel (Spring integration only) or push them to a message queue like RabbitMQ to store these jobs. I'm not 100% sure but remember that Spring Batch offers something similar like Master-Slave-Job splitting and synchronization. Maybe you have a look there.

Categories : Java

Java Spring Application JDBC database url
1) jdbc.host needs to be present in the properties file along with other properties 2) this property file needs to be mentioned in the application context.xml file and be read using PropertyPlaceholderConfigurer When the application context is loaded it reads from this property file and so in this code when it tries to do a ${jdbc.host} it gets it from the context as it is available in the memory. You do not have to make any code change if the above two things are checked.

Categories : Java

Why does Spring's throw a SQLSyntaxErrorException?
In the data.sql file there is an error: insert into tuser (userid, admin) values ("testUser0", 0); should be (Sql uses single quotes): insert into tuser (userid, admin) values ('testUser0', 0); This may be the source of the java.sql.SQLSyntaxErrorException: user lacks privilege or object not found error. I get burnt by this one all the time, I really wish SQL and Java's string literals used the same terminators.

Categories : Java

Spring config XML file with context/jdbc/tx schemalocation
You are missing spring-jdbc jar (that is hosting spring-jdbc-3.0.xsd) and spring-tx jar (that is hosting spring-tx.-3.0.xsd). If you are using Maven to build your project add the following dependency declarations: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring-framework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring-framework.version}</version> </dependency> where spring-framework.version the version of 3.0.X.RELEASE you might be using.

Categories : Xml

Python-ldap ldap.initialize rejects a URL that ldapurl considers valid
You can programatically encode the last part of the URL: from urllib import quote # works in Python 2.x from urllib.parse import quote # works in Python 3.x url = 'ldap://192.168.2.151/dc=directory,dc=paralint,dc=com' idx = url.rindex('/') + 1 url[:idx] + quote(url[idx:], '=') => 'ldap://192.168.2.151/dc=directory%2Cdc=paralint%2Cdc=com'

Categories : Python

how to configure multisupport dao using spring
This blog has a tutorial on mixing them : http://hibernatebp.blogspot.co.uk/2012/02/mixing-spring-hibernate-jpa-and-plain.html (including a great 'when whould you choose to do this?' discussion)

Categories : Java

Spring MVC configure url-pattern
Spring is working with the information how the servlet mapping is defined. If you are using suffix mapping (*.something), then Spring uses just the first part (without the suffix). This means you shuold map just /index in your url-pattern (without the suffix). JavaDoc in Spring's UrlPathHelper#getPathWithinServletMapping gives a better description what is being used in the mapping process: Return the path within the servlet mapping for the given request, i.e. the part of the request's URL beyond the part that called the servlet, or "" if the whole URL has been used to identify the servlet. Detects include request URL if called within a RequestDispatcher include. E.g.: servlet mapping = "/test/*"; request URI = "/test/a" -> "/a". E.g.: servlet mapping = "/test"; re

Categories : Java

Can I configure tiles 3.0 with Spring 3.1.1
If you can upgrade to spring-3.2 it's all easy as it provides tiles-3 integration for you. see http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/new-in-3.2.html ( ref: https://jira.springsource.org/browse/SPR-8825 ) If you can't upgrade to spring-3.2 you can download just the new spring-tiles-3 integration classes from the above jira issue and integrate as described in http://tech.finn.no/2012/07/25/the-ultimate-view-tiles-3/2/

Categories : Spring

How do I find all the roles a user has in LDAP using the UnboundID LDAP SDK?
Use the following function. Assumption that you works with SUN LDAP (you use uid): Edited private boolean isGroupContainUser(LDAPConnection ldapConnection, String groupDn, String userDn) throws LDAPException { boolean ret = false; Entry groupEntry = ldapConnection.getEntry(groupDn); String[] memberValues = groupEntry.getAttributeValues("uniquemember"); if (memberValues != null) { DN ldapUserDn = new DN(userDn); for (String memberEntryDnString : memberValues) { DN memberEntryDn = new DN(memberEntryDnString); if (memberEntryDn.equals(ldapUserDn)) { ret = true; break; } } } return ret; }

Categories : Java

How to configure Spring with Neo4j Ha cluster?
Issue resolved, just by implementing below changes in my applicationContext.xml spring configuration: <bean id="graphDatabaseService" class="org.neo4j.kernel.HighlyAvailableGraphDatabase" destroy-method="shutdown"> <constructor-arg index="0" value="/opt/build/mydb/graph.db"/> <constructor-arg index="1"> <map> <entry key="ha.server_id" value="1"/> <entry key="ha.server" value="192.168.1.10:6001"/> <entry key="ha.coordinators" value="192.168.1.10:2181,192.168.1.9:2182,192.168.1.8:2183"/> </map> </constructor-arg> </bean> <neo4j:config graphDatabaseService="graphDatabaseService"/> As per my understanding, We need to mention at least primary location of graph.db followed by ha configuration with coordinators details. Wo

Categories : Java

Spring MVC + Maven + JBoss: can't deploy (The application must supply JDBC connections)
You configured JPA to be initialized by Spring (using LocalContainerEntityManagerFactoryBean), but JBoss also sees your persistence.xml and tries to initialize JPA on its own (as required by JPA Specification for application server environments). Obviously, it fails, because you didn't configure a data source in persistence.xml. To avoid this problem Spring allows you to use different name for persistence.xml: <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> ... <property name = "persistenceXmlLocation" value = "classpath:/META-INF/spring-persistence.xml" /> </bean> Alternatively, since Spring 3.1 you can configure JPA without persistence.xml at all. See also: LocalContainerEntityManage

Categories : Postgresql

How to use Spring BoneCPDataSource bean as data source for Log4j 2 JDBC appender?
You can do it in 4 steps (step 2 & 3 are log4j2 config for web app): Step 1: Create log4j2.xml file (without JDBC appender) and put it in WEB-INF folder <?xml version="1.0" encoding="UTF-8"?> <Configuration status="INFO"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </Console> </Appenders> <Loggers> <Root level="info"> <AppenderRef ref="Console"/> </Root> </Loggers> </Configuration> Step 2 : Add log4j2-web-2.x.jar to WEB-INF/lib. Here is the maven repository, you can download the jar from there or copy paste the dependency to your pom.xml i

Categories : Spring

Import mysql Data in excel using Apache Poi and Spring JDBC template
POI usage is not very extensive, but still there are decent amount of resources out there. play with it and it should be fine. i have used POI and though there is some lack of documentation and usage, with some hit and trials, you should be good to go ! POI usage tutorial

Categories : Java

Where Should I put beans.xml content (Jdbc Connect with Spring-Eclipse Dynamic webapplication)
Add in your spring-servlet.xml file like below. http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-factory-xml-import <beans -------------------------- ------------------------------ <import resource="classpath:Beans.xml" /> <context:component-scan base-package="Ekle" /> </beans>

Categories : Java

Solution to dynamic configure Spring aplication
You may use Spring's dynamic language support. http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/dynamic-language.html It allows you to change your app's behavior at runtime. Below is an answer for the updated question. Assuming you are using Spring MVC, IMO you can implement your configuration setting page as a part of Spring MVC app. However, if you stick to implementing regular JSP that is executed outside the Spring MVC framework, you can put a JSP file to any location in your webapp (except under the WEB-INF directory) and execute the JSP directly. (e.g. http://yourhost/yourcontextroot/foo.jsp.) To make above work, you may need to configure the <url-pattern> for the DispatcherServlet like below to have servlet container handle a jsp request:

Categories : Spring

Configure Spring mail sender dynamically
Spring EMail function is just a thin wrapper around java's standard mail function (javax.mail) https://javamail.java.net/nonav/docs/api/. You do not need to use the spring mail function if you do not want, you can use java.mail directly. There it should be relative easily to use different configuration for every mail.

Categories : Database

Configure Neo4j 1.9.3 in Spring for HighlyAvailableGraphDatabase (embedded)
To overcome I did 2 changes: I replaced <entry key="ha.coordinators" with <entry key="ha.initial_hosts". Updated my pom.xml for neo4j-ha, neo4j-kernel, and neo4j-management and other neo4j related libs to latest one i.e. 1.9.3 (initially it was 1.8.2) and thats it. :) Thanks

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.