Update of
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community
In directory
james.mmbase.org:/tmp/cvs-serv10025/community/src/java/com/finalist/cmsc/services/community
Modified Files:
CommunityServiceImpl.java
Log Message:
CMSC-617 Personal Pages module
Synced branch 1.4 fixes to head
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-617
Index: CommunityServiceImpl.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/CommunityServiceImpl.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- CommunityServiceImpl.java 12 Mar 2008 15:38:56 -0000 1.10
+++ CommunityServiceImpl.java 31 Mar 2008 19:49:02 -0000 1.11
@@ -6,7 +6,7 @@
The license (Mozilla version 1.0) can be read at the MMBase site.
See http://www.MMBase.org/license
-*/
+ */
package com.finalist.cmsc.services.community;
import java.util.ArrayList;
@@ -15,7 +15,6 @@
import javax.servlet.ServletConfig;
-import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
import org.acegisecurity.GrantedAuthority;
@@ -23,6 +22,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 +30,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 +50,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 +64,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 +80,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,8 +119,8 @@
private User getPrincipal() {
SecurityContext context = SecurityContextHolder.getContext();
- Authentication authentication = context.getAuthentication();
- return authentication != null ? (User)authentication.getPrincipal() :
null;
+ org.acegisecurity.Authentication authentication =
context.getAuthentication();
+ return authentication != null ? (User) authentication.getPrincipal() :
null;
}
public Map<Long, Map<String, String>> getPreferencesByModule(String
module) {
@@ -136,7 +144,7 @@
preferenceService.deletePreference(module, userId, key, value);
}
- //TODO: replace the previous methods by methods who accept the following
+ // TODO: replace the previous methods by methods who accept the following
// properties!
/**
@@ -144,7 +152,7 @@
*/
@Override
public void createPreference(String module, String userId, String key,
List<String> values) {
- for(String value : values) {
+ for (String value : values) {
preferenceService.createPreference(module, userId, key,
value);
}
}
@@ -153,8 +161,7 @@
* @deprecated please try to use another service
*/
@Override
- public Map<String, Map<String, List<String>>> getPreferences(String
module,
- String userId, String key, String value) {
+ public Map<String, Map<String, List<String>>> getPreferences(String module,
String userId, String key, String value) {
return null;
}
@@ -163,10 +170,57 @@
*/
@Override
public Map<String, Map<String, String>> getUserProperty(String userId) {
-// return preferenceService.getPreferencesByUserId(userId);
+ // return preferenceService.getPreferencesByUserId(userId);
return null;
}
+ /** [EMAIL PROTECTED] */
+ @Override
+ boolean sendPassword(String email, String senderName, String senderEmail,
String emailSubject, String emailBody) {
+ boolean authenticationFound = false;
+
+ if (StringUtils.isEmpty(email)) {
+ throw new IllegalArgumentException("Username not found.");
+ }
+ if (StringUtils.isEmpty(emailSubject)) {
+ emailSubject = "<email subject is missing>";
+ }
+ if (StringUtils.isEmpty(emailBody)) {
+ emailBody = "<email body is missing>";
+ }
+
+ String name = "";
+ StringBuilder body = new StringBuilder(emailBody);
+
+ Person example = new Person();
+ example.setEmail(email);
+ // Retrieve a list of persons that match this example
+ List<Person> persons = personService.getPersons(example);
+
+ for (Person person : persons) {
+ Authentication authentication =
authenticationService.getAuthenticationById(person.getAuthenticationId());
+
+ if (authentication != null) {
+ if ("".equals(name)) {
+ name = NameUtil.getFullName(person.getFirstName(),
person.getInfix(), person.getLastName());
+ }
+
+ body.append("\n---\n");
+ body.append("Gebruikersnaam: ").append(authentication.getUserId());
+ body.append("\n");
+ body.append("Wachtwoord :
").append(authentication.getPassword());
+
+ authenticationFound = true;
+ }
+ }
+
+ if (authenticationFound) {
+ EmailUtil.send(null, name, email, senderName, senderEmail,
emailSubject, body.toString());
+ }
+
+ return authenticationFound;
+ }
+
/**
* @deprecated please try to use another service
*/
@@ -187,4 +241,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