Audith login operations.

This commit is contained in:
Paulo Gustavo Veiga 2012-06-23 16:15:59 -03:00
parent c8837baadd
commit 3349f2e567
15 changed files with 146 additions and 128 deletions

View File

@ -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);

View File

@ -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) {

View 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;
}
}

View File

@ -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;
}
*/
}

View File

@ -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());
}

View File

@ -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() {

View File

@ -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);
}

View File

@ -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);
}

View File

@ -5,12 +5,16 @@
<hibernate-mapping>
<class name="com.wisemapping.model.UserLogin" table="USER_LOGIN">
<class name="com.wisemapping.model.AccessAuditory" table="ACCESS_AUDITORY">
<id name="id">
<generator class="increment"/>
</id>
<property name="loginDate" column="login_Date"/>
<property name="email"/>
<many-to-one name="user"
column="USER_ID"
not-null="true"
class="com.wisemapping.model.User"
/>
</class>
</hibernate-mapping>

View File

@ -28,7 +28,7 @@
<value>com/wisemapping/model/MindMap.hbm.xml</value>
<value>com/wisemapping/model/Collaboration.hbm.xml</value>
<value>com/wisemapping/model/CollaborationProperties.hbm.xml</value>
<value>com/wisemapping/model/UserLogin.hbm.xml</value>
<value>com/wisemapping/model/AccessAuditory.hbm.xml</value>
<value>com/wisemapping/model/MindMapHistory.hbm.xml</value>
</list>
</property>

View File

@ -68,7 +68,7 @@
</bean>
<bean id="userDetailsService" class="com.wisemapping.security.UserDetailsService">
<property name="userManager" ref="userManager"/>
<property name="userService" ref="userService"/>
<property name="adminUser" value="${admin.user}"/>
</bean>

View File

@ -53,6 +53,8 @@
<script type="text/javascript">
$('#changePasswordMsg').hide();
$('#changeInfoMsg').hide();
function postChange(url, postBody, msgContainerId, successMsg) {
// Change success message ...
jQuery.ajax(url, {

View File

@ -62,9 +62,12 @@ user_id INTEGER NOT NULL,
--FOREIGN KEY(user_id) REFERENCES USER(colaborator_id)
);
CREATE TABLE USER_LOGIN
(id INTEGER NOT NULL IDENTITY,
email varchar(255),
login_date date);
CREATE TABLE ACCESS_AUDITORY (
id INTEGER NOT NULL IDENTITY,
user_id INTEGER NOT NULL,
login_date date,
FOREIGN KEY(user_id) REFERENCES USER(id)
);
COMMIT;
SHUTDOWN;

View File

@ -14,7 +14,7 @@ password varchar(255) CHARACTER SET utf8 NOT NULL,
activationCode BIGINT(20) NOT NULL,
activation_date date,
allowSendEmail char(1) CHARACTER SET utf8 NOT NULL default 0,
FOREIGN KEY(colaborator_id) REFERENCES COLLABORATOR(id)
FOREIGN KEY(colaborator_id) REFERENCES COLLABORATOR(id) ON DELETE CASCADE ON UPDATE NO ACTION
) CHARACTER SET utf8 ;
CREATE TABLE MINDMAP (
@ -28,7 +28,7 @@ edition_date datetime,
creator_id INTEGER not null,
tags varchar(1014) CHARACTER SET utf8 ,
last_editor varchar(255) CHARACTER SET utf8 ,
FOREIGN KEY(creator_id) REFERENCES USER(colaborator_id)
FOREIGN KEY(creator_id) REFERENCES USER(colaborator_id) ON DELETE CASCADE ON UPDATE NO ACTION
) CHARACTER SET utf8 ;
@ -53,20 +53,22 @@ properties_id INTEGER NOT NULL,
mindmap_id INTEGER NOT NULL,
role_id INTEGER NOT NULL,
FOREIGN KEY(colaborator_id) REFERENCES COLLABORATOR(id),
FOREIGN KEY(mindmap_id) REFERENCES MINDMAP(id)
FOREIGN KEY(properties_id) REFERENCES COLLABORATION_PROPERTIES(id),
FOREIGN KEY(mindmap_id) REFERENCES MINDMAP(id) ON DELETE CASCADE ON UPDATE NO ACTION,
FOREIGN KEY(properties_id) REFERENCES COLLABORATION_PROPERTIES(id) ON DELETE CASCADE ON UPDATE NO ACTION
) CHARACTER SET utf8 ;
CREATE TABLE TAG(
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
name varchar(255) CHARACTER SET utf8 NOT NULL,
user_id INTEGER NOT NULL,
FOREIGN KEY(user_id) REFERENCES USER(colaborator_id)
FOREIGN KEY(user_id) REFERENCES USER(colaborator_id) ON DELETE CASCADE ON UPDATE NO ACTION
) CHARACTER SET utf8 ;
CREATE TABLE USER_LOGIN (
CREATE TABLE ACCESS_AUDITORY (
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
email varchar(255) CHARACTER SET utf8 ,
login_date date
login_date date,
user_id INTEGER NOT NULL,
FOREIGN KEY(user_id) REFERENCES USER(id) ON DELETE CASCADE ON UPDATE NO ACTION
) CHARACTER SET utf8 ;
COMMIT;

View File

@ -13,7 +13,25 @@ ALTER TABLE `wisemapping`.`mindmap` DROP COLUMN `editor_properties` , DROP COLUM
ALTER TABLE `wisemapping`.`mindmap` CHANGE COLUMN `owner_id` `creator_id` INT(11) NOT NULL
, DROP INDEX `owner_id`
, ADD INDEX `owner_id` (`creator_id` ASC) ;
ALTER TABLE `wisemapping`.`collaboration` ADD COLUMN `properties_id` INT(11) NULL DEFAULT NULL AFTER `role_id` ;
DROP TABLE USER_LOGIN;
CREATE TABLE ACCESS_AUDITORY (
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
user_id INTEGER NOT NULL,
login_date date
) CHARACTER SET utf8 ;
ALTER TABLE ACCESS_AUDITORY
ADD CONSTRAINT `user_id`
FOREIGN KEY ()
REFERENCES `wisemapping`.`USER` ()
ON DELETE CASCADE
ON UPDATE NO ACTION
, ADD INDEX `user_id` () ;
# INSERT INTO `wisemapping`.`collaborator` (`id`, `email`, `creation_date`) VALUES (8081, 'fake@wisemapping.com', '2007-10-09');
# DELETE FROM `wisemapping`.`USER` where activation_date is null;
# DROP TABLE FEEDBACK;
#INSERT INTO `wisemapping`.`collaborator` (`id`, `email`, `creation_date`) VALUES (8081, 'fake@wisemapping.com', '2007-10-09');