Ulsa,
As per your directions i kept it in code tags.
Code:
<beans>
<bean id="contextSourceTarget"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://xxx.xx.xxx.xxx:xxx" />
<property name="base" value="ou=xxx" />
<property name="userName" value="uid=xxx,ou=xxx" />
<property name="password" value="xxx" />
</bean>
<bean id="contextSource" class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
<constructor-arg ref="contextSourceTarget" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="transactionManager" class="org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager">
<property name="contextSource" ref="contextSource"/>
</bean>
<bean id="myDataAccessObjectTarget" class="com.xxx.business.service.adminsecurity.impl.AdminSecurityServiceImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
<bean id="myDataAccessObject"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager" />
<property name="target" ref="myDataAccessObjectTarget" />
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRES_NEW,-AdminSecurityServiceException</prop>
</props>
</property>
</bean>
<bean id="userDAOLdap" class="com.xxx.persistence.adminsecurity.impl.UserDAOLdapImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
<bean id="userGroupDAOLdap" class="com.xxx.persistence.adminsecurity.impl.UserGroupDAOLdapImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
</beans>
Code:
try {
public List saveUserGroupChanges(List userGroups)
throws AdminSecurityServiceException {
myLog
.debug("Executing saveUserGroupChanges(String groupName, String groupDescription)");
Resource resource = new ClassPathResource("springconfig.xml");
factory = new XmlBeanFactory(resource);
ldapUserDAO = (UserDAOLdapImpl) factory.getBean("userDAOLdap");
ldapUserGroupDAO = (UserGroupDAOLdapImpl) factory.getBean("userGroupDAOLdap");
if (userGroups != null) {
Iterator iter = userGroups.iterator();
while (iter.hasNext()) {
i++;
UserGroup userGroup = (UserGroup) iter.next();
if(StringUtils.isEmpty(userGroup.getCommonName())) {
userGroup.setErrorMessage("Error: User Group Common Name is mandatory.");
updatedUserGroups.add(userGroup);
..........................
........................
if(i==2)
throw new AdminSecurityServiceException();
}
}
} catch (Exception ee){}
}
Code:
public UserGroup addUserGroup(UserGroup userGroup) {
Name dn = AdminSecurityUtil.buildUserGroupDn(userGroup);
DirContextOperations context = null;
try {
context = ldapTemplate.lookupContext(dn);
} catch (NameNotFoundException e) {
context = new DirContextAdapter();
ldapTemplate.bind(dn, context, null);
return userGroup;
}
return userGroup;
}
}