Update of
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community
In directory
james.mmbase.org:/tmp/cvs-serv12548/community/src/java/com/finalist/cmsc/services/community
Modified Files:
Tag: b1_4
CommunityServiceImpl.java
Log Message:
CMSC-830 - Add Send Password functionality and improve Community source code,
not fully ready, but big steps are made.
See also:
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community
See also: http://www.mmbase.org/jira/browse/CMSC-830
Index: CommunityServiceImpl.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/CommunityServiceImpl.java,v
retrieving revision 1.7.2.2
retrieving revision 1.7.2.3
diff -u -b -r1.7.2.2 -r1.7.2.3
--- CommunityServiceImpl.java 3 Mar 2008 08:43:00 -0000 1.7.2.2
+++ CommunityServiceImpl.java 21 Mar 2008 16:46:29 -0000 1.7.2.3
@@ -9,13 +9,13 @@
*/
package com.finalist.cmsc.services.community;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletConfig;
-import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.GrantedAuthority;
@@ -23,6 +23,7 @@
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.acegisecurity.userdetails.User;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowire;
@@ -30,8 +31,14 @@
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
+import com.finalist.cmsc.mmbase.EmailUtil;
import com.finalist.cmsc.services.Properties;
+import com.finalist.cmsc.services.community.person.Person;
+import com.finalist.cmsc.services.community.person.PersonService;
import com.finalist.cmsc.services.community.preferences.PreferenceService;
+import com.finalist.cmsc.services.community.security.Authentication;
+import com.finalist.cmsc.services.community.security.AuthenticationService;
+import com.finalist.cmsc.util.NameUtil;
/**
* CommunityServiceImpl, a CMSc service class.
@@ -44,6 +51,8 @@
private AuthenticationManager authenticationManager;
private PreferenceService preferenceService;
+ private PersonService personService;
+ private AuthenticationService authenticationService;
@Override
protected void init(ServletConfig config, Properties properties) throws
Exception {
@@ -56,7 +65,7 @@
public void login(String userName, String password) {
UsernamePasswordAuthenticationToken authRequest = new
UsernamePasswordAuthenticationToken(userName, password);
try {
- Authentication authentication =
authenticationManager.authenticate(authRequest);
+ org.acegisecurity.Authentication authentication =
authenticationManager.authenticate(authRequest);
SecurityContextHolder.getContext().setAuthentication(authentication);
} catch (AuthenticationException ae) {
SecurityContextHolder.clearContext();
@@ -72,7 +81,7 @@
@Override
public boolean isAuthenticated() {
SecurityContext context = SecurityContextHolder.getContext();
- Authentication authentication = context.getAuthentication();
+ org.acegisecurity.Authentication authentication =
context.getAuthentication();
return (authentication != null) && authentication.isAuthenticated();
}
@@ -111,7 +120,7 @@
private User getPrincipal() {
SecurityContext context = SecurityContextHolder.getContext();
- Authentication authentication = context.getAuthentication();
+ org.acegisecurity.Authentication authentication =
context.getAuthentication();
return authentication != null ? (User)authentication.getPrincipal() :
null;
}
@@ -166,6 +175,35 @@
return null;
}
+ @Override
+ public boolean sendPassword(String email, String emailText, String
emailHeader) {
+ if (StringUtils.isEmpty(email)) {
+ throw new IllegalArgumentException("Username not found.");
+ }
+ if (StringUtils.isEmpty(emailText)) {
+ emailText = "Email text is missing";
+ }
+ if (StringUtils.isEmpty(emailHeader)) {
+ emailHeader = "Email header is missing";
+ }
+ Person person = new Person();
+ person.setEmail(email);
+ List<Person> persons = personService.getPerson(person);
+ List<Authentication> authList = new ArrayList<Authentication>();
+ StringBuilder body = new StringBuilder();
+
+ for (Person person2 : persons) {
+ Authentication auth =
authenticationService.getAuthenticationById(person2.getAuthenticationId());
+ authList.add(auth);
+ String name = NameUtil.getFullName(person2.getFirstName(),
person2.getInfix(), person2.getLastName());
+ body.append(name + "\n" + auth.getUserId() + "\n" +
auth.getPassword() + "\n\n");
+ }
+ String finalBody = MessageFormat.format(emailText, body.toString());
+ String name = NameUtil.getFullName(person.getFirstName(),
person.getInfix(), person.getLastName());
+ EmailUtil.send(name, email, emailHeader, finalBody);
+ return true;
+ }
+
/**
* @deprecated please try to use another service
*/
@@ -186,4 +224,14 @@
public void setPreferenceService(PreferenceService preferenceService) {
this.preferenceService = preferenceService;
}
+
+ @Required
+ public void setPersonService(PersonService personService) {
+ this.personService = personService;
+ }
+
+ @Required
+ public void setAuthenticationService(AuthenticationService
authenticationService) {
+ this.authenticationService = authenticationService;
+ }
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs