Audith login operations.
This commit is contained in:
@@ -20,7 +20,8 @@ package com.wisemapping.dao;
|
||||
|
||||
import com.wisemapping.model.Collaborator;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.model.UserLogin;
|
||||
import com.wisemapping.model.AccessAuditory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -36,7 +37,7 @@ public interface UserManager {
|
||||
|
||||
void createUser(User user);
|
||||
|
||||
void auditLogin(UserLogin userLogin);
|
||||
void auditLogin(@NotNull AccessAuditory accessAuditory);
|
||||
|
||||
void updateUser(User user);
|
||||
|
||||
|
@@ -21,7 +21,7 @@ package com.wisemapping.dao;
|
||||
import com.wisemapping.model.Collaboration;
|
||||
import com.wisemapping.model.Collaborator;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.model.UserLogin;
|
||||
import com.wisemapping.model.AccessAuditory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
import org.springframework.security.authentication.encoding.PasswordEncoder;
|
||||
@@ -121,9 +121,9 @@ public class UserManagerImpl
|
||||
getHibernateTemplate().flush();
|
||||
}
|
||||
|
||||
public void auditLogin(UserLogin userLogin) {
|
||||
assert userLogin != null : "userLogin is null";
|
||||
getHibernateTemplate().save(userLogin);
|
||||
public void auditLogin(@NotNull AccessAuditory accessAuditory) {
|
||||
assert accessAuditory != null : "accessAuditory is null";
|
||||
getHibernateTemplate().save(accessAuditory);
|
||||
}
|
||||
|
||||
public void updateUser(@NotNull User user) {
|
||||
|
59
wise-webapp/src/main/java/com/wisemapping/model/AccessAuditory.java
Executable file
59
wise-webapp/src/main/java/com/wisemapping/model/AccessAuditory.java
Executable file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* 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 com.wisemapping.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class AccessAuditory
|
||||
implements Serializable {
|
||||
|
||||
private int id;
|
||||
private Calendar loginDate = null;
|
||||
private User user = null;
|
||||
|
||||
public AccessAuditory() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setLoginDate(@NotNull Calendar loginDate) {
|
||||
this.loginDate = loginDate;
|
||||
}
|
||||
|
||||
public Calendar getLoginDate() {
|
||||
return loginDate;
|
||||
}
|
||||
|
||||
public void setUser(@NotNull User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return this.user;
|
||||
}
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* 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 com.wisemapping.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class UserLogin
|
||||
implements Serializable
|
||||
{
|
||||
|
||||
private int id;
|
||||
private Calendar loginDate = null;
|
||||
private String email = null;
|
||||
|
||||
public UserLogin()
|
||||
{
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setLoginDate(Calendar loginDate)
|
||||
{
|
||||
this.loginDate = loginDate;
|
||||
}
|
||||
|
||||
public Calendar getLoginDate()
|
||||
{
|
||||
return loginDate;
|
||||
}
|
||||
|
||||
public void setEmail(String email)
|
||||
{
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getEmail()
|
||||
{
|
||||
return email;
|
||||
}
|
||||
/*
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
final UserLogin userLogin = (UserLogin) o;
|
||||
|
||||
if (loginDate.equals(userLogin.loginDate)) return false;
|
||||
if (email.equals(userLogin.email)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = (loginDate!= null ? loginDate.hashCode() : 0);
|
||||
result = 29 * result + (email != null ? email.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
}
|
@@ -26,6 +26,7 @@ public class AuthenticationProvider implements org.springframework.security.auth
|
||||
if (user == null || credentials == null || !encoder.isPasswordValid(user.getPassword(), credentials, null)) {
|
||||
throw new BadCredentialsException("Username/Password does not match for " + auth.getPrincipal());
|
||||
}
|
||||
userDetailsService.getUserService().auditLogin(user);
|
||||
return new UsernamePasswordAuthenticationToken(userDetails, credentials, userDetails.getAuthorities());
|
||||
}
|
||||
|
||||
|
@@ -19,23 +19,27 @@
|
||||
package com.wisemapping.security;
|
||||
|
||||
import com.wisemapping.dao.UserManager;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.service.UserService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
|
||||
public class UserDetailsService
|
||||
implements org.springframework.security.core.userdetails.UserDetailsService {
|
||||
private UserManager userManager;
|
||||
private UserService userService;
|
||||
private String adminUser;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(@NotNull String email) throws UsernameNotFoundException, DataAccessException {
|
||||
final com.wisemapping.model.User model = userManager.getUserBy(email);
|
||||
final User user = userService.getUserBy(email);
|
||||
|
||||
if (model != null) {
|
||||
return new UserDetails(model, isAdmin(email));
|
||||
if (user != null) {
|
||||
return new UserDetails(user, isAdmin(email));
|
||||
} else {
|
||||
throw new UsernameNotFoundException(email);
|
||||
}
|
||||
@@ -45,12 +49,12 @@ public class UserDetailsService
|
||||
return email != null && adminUser != null && email.trim().endsWith(adminUser);
|
||||
}
|
||||
|
||||
public UserManager getUserManager() {
|
||||
return userManager;
|
||||
public UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
public void setUserManager(UserManager userManager) {
|
||||
this.userManager = userManager;
|
||||
public void setUserService(UserService userManager) {
|
||||
this.userService = userManager;
|
||||
}
|
||||
|
||||
public String getAdminUser() {
|
||||
|
@@ -40,7 +40,7 @@ public interface UserService {
|
||||
|
||||
public void resetPassword(@NotNull String email) throws InvalidUserEmailException;
|
||||
|
||||
public User reloadUser(final User user);
|
||||
|
||||
public void deleteUser(@NotNull User user);
|
||||
|
||||
public void auditLogin(@NotNull User user);
|
||||
}
|
||||
|
@@ -20,16 +20,13 @@ package com.wisemapping.service;
|
||||
|
||||
import com.wisemapping.dao.UserManager;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.mail.Mailer;
|
||||
import com.wisemapping.mail.NotificationService;
|
||||
import com.wisemapping.model.AccessAuditory;
|
||||
import com.wisemapping.model.Collaborator;
|
||||
import com.wisemapping.model.User;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserServiceImpl
|
||||
@@ -38,6 +35,7 @@ public class UserServiceImpl
|
||||
private MindmapService mindmapService;
|
||||
private NotificationService notificationService;
|
||||
|
||||
@Override
|
||||
public void activateAccount(long code)
|
||||
throws InvalidActivationCodeException {
|
||||
final User user = userManager.getUserByActivationCode(code);
|
||||
@@ -51,10 +49,7 @@ public class UserServiceImpl
|
||||
}
|
||||
}
|
||||
|
||||
public User reloadUser(final User user) {
|
||||
return this.getUserBy(user.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPassword(@NotNull String email)
|
||||
throws InvalidUserEmailException {
|
||||
final User user = userManager.getUserBy(email);
|
||||
@@ -66,8 +61,6 @@ public class UserServiceImpl
|
||||
|
||||
// Send an email with the new temporal password ...
|
||||
notificationService.resetPassword(user, password);
|
||||
|
||||
|
||||
} else {
|
||||
throw new InvalidUserEmailException("The email '" + email + "' does not exists.");
|
||||
}
|
||||
@@ -90,10 +83,19 @@ public class UserServiceImpl
|
||||
return lo + i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUser(@NotNull User user) {
|
||||
userManager.deleteUser(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auditLogin(@NotNull User user) {
|
||||
final AccessAuditory accessAuditory = new AccessAuditory();
|
||||
accessAuditory.setUser(user);
|
||||
accessAuditory.setLoginDate(Calendar.getInstance());
|
||||
userManager.auditLogin(accessAuditory);
|
||||
}
|
||||
|
||||
public User createUser(@NotNull User user, boolean emailConfirmEnabled) throws WiseMappingException {
|
||||
final UUID uuid = UUID.randomUUID();
|
||||
user.setCreationDate(Calendar.getInstance());
|
||||
@@ -127,23 +129,28 @@ public class UserServiceImpl
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePassword(@NotNull User user) {
|
||||
notificationService.passwordChanged(user);
|
||||
userManager.updateUser(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserBy(String email) {
|
||||
return userManager.getUserBy(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
return userManager.getUserByUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserBy(long id) {
|
||||
return userManager.getUserBy(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(@NotNull User user) {
|
||||
userManager.updateUser(user);
|
||||
}
|
||||
|
Reference in New Issue
Block a user