Rolled back previous screwup in spring-ldap-person
This commit is contained in:
@@ -13,11 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package se.jayway.demo.spring.ldap.service;
|
||||
package org.springframework.ldap.samples.person.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import se.jayway.demo.spring.ldap.domain.Group;
|
||||
import org.springframework.ldap.samples.person.domain.Group;
|
||||
import org.springframework.ldap.samples.person.domain.SearchCriteria;
|
||||
|
||||
/**
|
||||
* Example interface for a Group service.
|
||||
@@ -26,7 +28,15 @@ import se.jayway.demo.spring.ldap.domain.Group;
|
||||
*/
|
||||
public interface GroupService {
|
||||
|
||||
Group findByPrimaryKey(String name);
|
||||
void create(String name, Set members);
|
||||
|
||||
public List<Group> findAll();
|
||||
void update(Group group);
|
||||
|
||||
void delete(Group group);
|
||||
|
||||
Group findByPrimaryKey(String name);
|
||||
|
||||
List find(SearchCriteria criteria);
|
||||
|
||||
List findAll();
|
||||
}
|
||||
|
||||
@@ -13,12 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package se.jayway.demo.spring.ldap.service;
|
||||
package org.springframework.ldap.samples.person.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import se.jayway.demo.spring.ldap.dao.GroupDao;
|
||||
import se.jayway.demo.spring.ldap.domain.Group;
|
||||
import org.springframework.ldap.samples.person.dao.GroupDao;
|
||||
import org.springframework.ldap.samples.person.domain.Group;
|
||||
import org.springframework.ldap.samples.person.domain.SearchCriteria;
|
||||
|
||||
/**
|
||||
* Service implementation for managing the Group entity.
|
||||
@@ -27,24 +29,57 @@ import se.jayway.demo.spring.ldap.domain.Group;
|
||||
*/
|
||||
public class GroupServiceImpl implements GroupService {
|
||||
|
||||
private GroupDao groupDao;
|
||||
private GroupDao groupDao;
|
||||
|
||||
public void setGroupDao(GroupDao groupDao) {
|
||||
this.groupDao = groupDao;
|
||||
}
|
||||
public void setGroupDao(GroupDao groupDao) {
|
||||
this.groupDao = groupDao;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.GroupService#findByPrimaryKey(java.lang.String)
|
||||
*/
|
||||
public Group findByPrimaryKey(String name) {
|
||||
return groupDao.findByPrimaryKey(name);
|
||||
}
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.GroupService#create(java.lang.String,
|
||||
* java.util.Set)
|
||||
*/
|
||||
public void create(String name, Set members) {
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.GroupService#findAll()
|
||||
*/
|
||||
public List<Group> findAll() {
|
||||
return groupDao.findAll();
|
||||
}
|
||||
Group group = new Group();
|
||||
group.setName(name);
|
||||
group.setMembers(members);
|
||||
|
||||
groupDao.create(group);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.GroupService#update(org.springframework.ldap.samples.person.domain.Group)
|
||||
*/
|
||||
public void update(Group group) {
|
||||
groupDao.update(group);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.GroupService#delete(org.springframework.ldap.samples.person.domain.Group)
|
||||
*/
|
||||
public void delete(Group group) {
|
||||
groupDao.delete(group);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.GroupService#findByPrimaryKey(java.lang.String)
|
||||
*/
|
||||
public Group findByPrimaryKey(String name) {
|
||||
return groupDao.findByPrimaryKey(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.GroupService#findAll()
|
||||
*/
|
||||
public List findAll() {
|
||||
return groupDao.findAll();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.GroupService#find(org.springframework.ldap.samples.person.domain.SearchCriteria)
|
||||
*/
|
||||
public List find(SearchCriteria criteria) {
|
||||
return groupDao.find(criteria);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package se.jayway.demo.spring.ldap.service;
|
||||
package org.springframework.ldap.samples.person.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import se.jayway.demo.spring.ldap.domain.Person;
|
||||
import org.springframework.ldap.samples.person.domain.Person;
|
||||
import org.springframework.ldap.samples.person.domain.SearchCriteria;
|
||||
|
||||
/**
|
||||
* Example interface for a Person service.
|
||||
@@ -27,9 +28,16 @@ import se.jayway.demo.spring.ldap.domain.Person;
|
||||
*/
|
||||
public interface PersonService {
|
||||
|
||||
void create(String country, String company, String fullname,
|
||||
String lastname, String[] description);
|
||||
|
||||
void update(Person person);
|
||||
|
||||
void delete(Person person);
|
||||
|
||||
Person findByPrimaryKey(String country, String company, String name);
|
||||
|
||||
public List<Person> findAll();
|
||||
List find(SearchCriteria criteria);
|
||||
|
||||
List findAll();
|
||||
}
|
||||
|
||||
@@ -1,38 +1,107 @@
|
||||
package se.jayway.demo.spring.ldap.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
import se.jayway.demo.spring.ldap.dao.PersonDao;
|
||||
import se.jayway.demo.spring.ldap.domain.Person;
|
||||
|
||||
public class PersonServiceImpl implements PersonService {
|
||||
|
||||
private PersonDao personDao;
|
||||
|
||||
public final void setPersonDao(PersonDao personDao) {
|
||||
this.personDao = personDao;
|
||||
}
|
||||
|
||||
public List<Person> findAll() {
|
||||
return personDao.findAll();
|
||||
}
|
||||
|
||||
public Person findByPrimaryKey(String country, String company, String name) {
|
||||
return personDao.findByPrimaryKey(buildDn(country, company, name));
|
||||
}
|
||||
|
||||
public void update(Person person) {
|
||||
personDao.update(person);
|
||||
}
|
||||
|
||||
private String buildDn(String country, String company, String fullName) {
|
||||
DistinguishedName dn = new DistinguishedName();
|
||||
dn.add("c", country);
|
||||
dn.add("ou", company);
|
||||
dn.add("cn", fullName);
|
||||
return dn.toString();
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.samples.person.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.ldap.samples.person.dao.GroupDao;
|
||||
import org.springframework.ldap.samples.person.dao.PersonDao;
|
||||
import org.springframework.ldap.samples.person.domain.Person;
|
||||
import org.springframework.ldap.samples.person.domain.SearchCriteria;
|
||||
|
||||
/**
|
||||
* Service implementation for managing the Person entity.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PersonServiceImpl implements PersonService {
|
||||
|
||||
private PersonDao personDao;
|
||||
|
||||
private GroupDao groupDao;
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.PersonService#create(java.lang.String,
|
||||
* java.lang.String, java.lang.String, java.lang.String,
|
||||
* java.lang.String[])
|
||||
*/
|
||||
public void create(String country, String company, String fullname,
|
||||
String lastname, String[] description) {
|
||||
|
||||
Person person = new Person();
|
||||
person.setCountry(country);
|
||||
person.setCompany(company);
|
||||
person.setFullName(fullname);
|
||||
person.setLastName(lastname);
|
||||
person.setDescription(description);
|
||||
|
||||
personDao.create(person);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.PersonService#update(org.springframework.ldap.samples.person.domain.Person)
|
||||
*/
|
||||
public void update(Person person) {
|
||||
String originalDn = person.getDn();
|
||||
personDao.update(person);
|
||||
String newDn = person.getDn();
|
||||
|
||||
// If the DN has changed (i.e. if the user has been moved in the tree,
|
||||
// also modify all referring groups.
|
||||
// Unfortunately this doesn't work with the current version of ApacheDS,
|
||||
// as the format of the DN produced by DistinguishedName is different
|
||||
// from the one present in the DB (and recognized by acegi).
|
||||
if (!StringUtils.equals(originalDn, newDn)) {
|
||||
groupDao.updateMemberDn(originalDn, newDn);
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(Person person) {
|
||||
personDao.delete(person);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.PersonService#findByPrimaryKey(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public Person findByPrimaryKey(String country, String company, String name) {
|
||||
return personDao.findByPrimaryKeyData(country, company, name);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.PersonService#findAll()
|
||||
*/
|
||||
public List findAll() {
|
||||
return personDao.findAll();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.ldap.samples.person.service.PersonService#find(org.springframework.ldap.samples.person.domain.SearchCriteria)
|
||||
*/
|
||||
public List find(SearchCriteria criteria) {
|
||||
return personDao.find(criteria);
|
||||
}
|
||||
|
||||
public void setPersonDao(PersonDao personDao) {
|
||||
this.personDao = personDao;
|
||||
}
|
||||
|
||||
public void setGroupDao(GroupDao groupDao) {
|
||||
this.groupDao = groupDao;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.ldap.samples.person.web;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.ldap.samples.person.domain.Group;
|
||||
import org.springframework.ldap.samples.person.service.GroupService;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.webflow.action.FormAction;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
|
||||
/**
|
||||
* Action implementation that handles edit of a group. This action has the
|
||||
* capability to add and remove members of the current Group form object.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class EditGroupFormAction extends FormAction {
|
||||
|
||||
private GroupService groupService;
|
||||
|
||||
public void setGroupService(GroupService groupService) {
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.webflow.action.FormAction#initAction()
|
||||
*/
|
||||
protected void initAction() {
|
||||
super.initAction();
|
||||
Assert.notNull(groupService, "A GroupService object is required");
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.webflow.action.FormAction#createFormObject(org.springframework.webflow.execution.RequestContext)
|
||||
*/
|
||||
protected Object createFormObject(RequestContext context) throws Exception {
|
||||
String name = context.getFlowScope().getRequiredString("name");
|
||||
Group group = groupService.findByPrimaryKey(name);
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the member in the <code>member</code> property to the form object
|
||||
* <code>members</code> property.
|
||||
*
|
||||
* @param context
|
||||
* RequestContext with parameters and attributes.
|
||||
* @return The <code>success</code> event if member was added successfully
|
||||
* @throws Exception
|
||||
* if an unexpected error occurs
|
||||
*/
|
||||
public Event add(RequestContext context) throws Exception {
|
||||
Group group = (Group) getFormObject(context);
|
||||
Set members = group.getMembers();
|
||||
String member = (String) context.getRequestParameters().get("member");
|
||||
members.add(member);
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the members in the <code>selectedMembers</code> property from
|
||||
* the form object <code>members</code> property.
|
||||
*
|
||||
* @param context
|
||||
* RequestContext with parameters and attributes.
|
||||
* @return The <code>success</code> event if members were removed
|
||||
* successfully
|
||||
* @throws Exception
|
||||
* if an unexpected error occurs
|
||||
*/
|
||||
public Event remove(RequestContext context) throws Exception {
|
||||
Group group = (Group) getFormObject(context);
|
||||
Set members = group.getMembers();
|
||||
String[] selectedMembers = (String[]) context.getRequestParameters()
|
||||
.getArray("selectedMembers");
|
||||
List membersToRemove = Arrays.asList(selectedMembers);
|
||||
Collection adjustedMembers = CollectionUtils.subtract(members,
|
||||
membersToRemove);
|
||||
group.setMembers(new TreeSet(adjustedMembers));
|
||||
return success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2005-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.samples.person.web;
|
||||
|
||||
import net.sf.chainedoptions.ChainedOptionManager;
|
||||
|
||||
import org.springframework.beans.PropertyEditorRegistry;
|
||||
import org.springframework.beans.propertyeditors.StringArrayPropertyEditor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.webflow.action.FormAction;
|
||||
import org.springframework.webflow.execution.Event;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
|
||||
/**
|
||||
* Action implementation that handles edit of a person. Registers appropriate
|
||||
* property editors, and provides an action method for setting up reference
|
||||
* data.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class EditPersonFormAction extends FormAction {
|
||||
|
||||
private ChainedOptionManager chainedOptionManager;
|
||||
|
||||
/*
|
||||
* @see org.springframework.webflow.action.FormAction#registerPropertyEditors(org.springframework.webflow.execution.RequestContext,
|
||||
* org.springframework.beans.PropertyEditorRegistry)
|
||||
*/
|
||||
protected void registerPropertyEditors(RequestContext context,
|
||||
PropertyEditorRegistry registry) {
|
||||
registry.registerCustomEditor(String[].class,
|
||||
new StringArrayPropertyEditor());
|
||||
}
|
||||
|
||||
public Event referenceData(RequestContext context) throws Exception {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing referenceData");
|
||||
}
|
||||
|
||||
Object formObject = getFormObject(context);
|
||||
chainedOptionManager.referenceData(context.getRequestScope().asMap(),
|
||||
formObject, null);
|
||||
return success();
|
||||
}
|
||||
|
||||
protected void initAction() {
|
||||
Assert.notNull(chainedOptionManager,
|
||||
"The property 'chainedOptionManager' must not be null");
|
||||
}
|
||||
|
||||
public void setChainedOptionManager(
|
||||
ChainedOptionManager chainedOptionManager) {
|
||||
this.chainedOptionManager = chainedOptionManager;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package se.jayway.demo.spring.ldap.web;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.AbstractController;
|
||||
|
||||
import se.jayway.demo.spring.ldap.service.GroupService;
|
||||
|
||||
public class GroupController extends AbstractController {
|
||||
|
||||
private GroupService groupService;
|
||||
|
||||
public final void setGroupService(GroupService groupService) {
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelAndView handleRequestInternal(HttpServletRequest request,
|
||||
HttpServletResponse response) throws Exception {
|
||||
|
||||
String name = request.getParameter("name");
|
||||
return new ModelAndView("showgroup", "group", groupService
|
||||
.findByPrimaryKey(name));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package se.jayway.demo.spring.ldap.web;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.AbstractController;
|
||||
|
||||
import se.jayway.demo.spring.ldap.service.GroupService;
|
||||
import se.jayway.demo.spring.ldap.service.PersonService;
|
||||
|
||||
public class ListController extends AbstractController {
|
||||
|
||||
private GroupService groupService;
|
||||
private PersonService personService;
|
||||
|
||||
public final void setGroupService(GroupService groupService) {
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
public final void setPersonService(PersonService personService) {
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelAndView handleRequestInternal(HttpServletRequest request,
|
||||
HttpServletResponse response) throws Exception {
|
||||
ModelMap map = new ModelMap();
|
||||
map.addObject("groups", groupService.findAll()).addObject("persons",
|
||||
personService.findAll());
|
||||
|
||||
return new ModelAndView("list", map);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package se.jayway.demo.spring.ldap.web;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.web.servlet.mvc.SimpleFormController;
|
||||
|
||||
import se.jayway.demo.spring.ldap.domain.Person;
|
||||
import se.jayway.demo.spring.ldap.service.PersonService;
|
||||
|
||||
public class PersonFormController extends SimpleFormController {
|
||||
|
||||
private PersonService personService;
|
||||
|
||||
@Override
|
||||
protected Object formBackingObject(HttpServletRequest request)
|
||||
throws Exception {
|
||||
|
||||
String fullName = (String) request.getParameter("name");
|
||||
String country = (String) request.getParameter("country");
|
||||
String company = (String) request.getParameter("company");
|
||||
|
||||
return personService.findByPrimaryKey(country, company, fullName);
|
||||
}
|
||||
|
||||
public final void setPersonService(PersonService personService) {
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doSubmitAction(Object command) throws Exception {
|
||||
personService.update((Person)command);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user