diff --git a/config/database/hsql/create-schemas.sql b/config/database/hsql/create-schemas.sql index 7102b72b..6061afc1 100644 --- a/config/database/hsql/create-schemas.sql +++ b/config/database/hsql/create-schemas.sql @@ -6,6 +6,7 @@ creation_date date); CREATE TABLE USER ( id INTEGER NOT NULL IDENTITY, colaborator_id INTEGER NOT NULL, +auth_schema CHAR(1) NOT NULL, firstname varchar(255) NOT NULL, lastname varchar(255) NOT NULL, password varchar(255) NOT NULL, diff --git a/wise-webapp/src/main/java/com/wisemapping/model/AuthenticationSchema.java b/wise-webapp/src/main/java/com/wisemapping/model/AuthenticationSchema.java index 4a16afd2..71272be0 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/AuthenticationSchema.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/AuthenticationSchema.java @@ -1,17 +1,33 @@ package com.wisemapping.model; -public enum AuthenticationSchema -{ - DATABASE(0), - LDAP(1), - OPENID(2); - private final int schemaCode; +public enum AuthenticationSchema { + DATABASE('D'), + LDAP('L'), + OPENID('O'); + private final char schemaCode; - AuthenticationSchema(int schemaCode) { + AuthenticationSchema(char schemaCode) { this.schemaCode = schemaCode; } - public int getSchemaCode() { + public char getCode() { return schemaCode; } + + public static AuthenticationSchema valueOf(char code) { + AuthenticationSchema result = null; + AuthenticationSchema[] values = AuthenticationSchema.values(); + for (AuthenticationSchema value : values) { + if (value.getCode() == code) { + result = value; + break; + } + } + + if (result == null) { + throw new IllegalStateException("Could not find auth with code:" + code); + } + + return result; + } } diff --git a/wise-webapp/src/main/java/com/wisemapping/model/User.java b/wise-webapp/src/main/java/com/wisemapping/model/User.java index b0645060..dbc29c2e 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/User.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/User.java @@ -18,6 +18,7 @@ package com.wisemapping.model; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.Serializable; @@ -36,9 +37,8 @@ public class User private Calendar activationDate; private Set tags = new HashSet(); private boolean allowSendEmail = false; - private int schema; private String locale; - + private AuthenticationSchema authenticationSchema; public User() { } @@ -116,11 +116,25 @@ public class User this.locale = locale; } - public int getAutheticationCode() { - return this.schema; + public char getAutheticationCode() { + return this.authenticationSchema != null ? this.authenticationSchema.getCode() : null; } - public void setAuthenticationCode(int code) { - this.schema = code; + public void setAutheticationCode(char code) { + this.authenticationSchema = AuthenticationSchema.valueOf(code); } + + public AuthenticationSchema getAuthenticationSchema() { + return authenticationSchema; + } + + public void setAuthenticationSchema(@NotNull AuthenticationSchema authenticationSchema) { + this.authenticationSchema = authenticationSchema; + } + + public boolean isDatabaseSchema(){ + return this.authenticationSchema==AuthenticationSchema.DATABASE; + } + + } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java b/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java index bd636ea2..581e0eee 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/AdminController.java @@ -18,8 +18,8 @@ package com.wisemapping.rest; -import com.wisemapping.exceptions.ClientException; import com.wisemapping.exceptions.WiseMappingException; +import com.wisemapping.model.AuthenticationSchema; import com.wisemapping.model.User; import com.wisemapping.rest.model.RestUser; import com.wisemapping.service.UserService; @@ -85,13 +85,14 @@ public class AdminController extends BaseController { } // Finally create the user ... - userService.createUser(delegated, false,true); + delegated.setAuthenticationSchema(AuthenticationSchema.DATABASE); + userService.createUser(delegated, false, true); response.setHeader("Location", "/service/admin/users/" + user.getId()); } @RequestMapping(method = RequestMethod.PUT, value = "admin/users/{id}/password", consumes = {"text/plain"}) @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void changePassword(@RequestBody String password, @PathVariable long id) throws WiseMappingException { + public void changePassword(@RequestBody String password, @PathVariable long id) throws WiseMappingException { if (password == null) { throw new IllegalArgumentException("Password can not be null"); } @@ -104,7 +105,7 @@ public class AdminController extends BaseController { userService.changePassword(user); } - @RequestMapping(method = RequestMethod.DELETE,value = "admin/users/{id}") + @RequestMapping(method = RequestMethod.DELETE, value = "admin/users/{id}") @ResponseStatus(value = HttpStatus.NO_CONTENT) public void getUserByEmail(@PathVariable long id) throws WiseMappingException { final User user = userService.getUserBy(id); diff --git a/wise-webapp/src/main/java/com/wisemapping/security/UserDetailsService.java b/wise-webapp/src/main/java/com/wisemapping/security/UserDetailsService.java index fcabfda1..56bcf226 100644 --- a/wise-webapp/src/main/java/com/wisemapping/security/UserDetailsService.java +++ b/wise-webapp/src/main/java/com/wisemapping/security/UserDetailsService.java @@ -20,6 +20,7 @@ package com.wisemapping.security; import com.wisemapping.exceptions.WiseMappingException; +import com.wisemapping.model.AuthenticationSchema; import com.wisemapping.model.User; import com.wisemapping.service.UserService; import org.jetbrains.annotations.NotNull; @@ -62,6 +63,7 @@ public class UserDetailsService result = dbUser; } else { try { + tUser.setAuthenticationSchema(AuthenticationSchema.OPENID); result = userService.createUser(tUser, false, false); } catch (WiseMappingException e) { throw new IllegalStateException(e); diff --git a/wise-webapp/src/main/java/com/wisemapping/security/ldap/LdapUserDetailsContextMapper.java b/wise-webapp/src/main/java/com/wisemapping/security/ldap/LdapUserDetailsContextMapper.java index 7f6a61ce..15c6eb30 100644 --- a/wise-webapp/src/main/java/com/wisemapping/security/ldap/LdapUserDetailsContextMapper.java +++ b/wise-webapp/src/main/java/com/wisemapping/security/ldap/LdapUserDetailsContextMapper.java @@ -2,6 +2,7 @@ package com.wisemapping.security.ldap; import com.wisemapping.exceptions.WiseMappingException; +import com.wisemapping.model.AuthenticationSchema; import com.wisemapping.model.User; import com.wisemapping.security.UserDetails; import com.wisemapping.service.UserService; @@ -64,6 +65,7 @@ public class LdapUserDetailsContextMapper implements UserDetailsContextMapper { user.setActivationDate(now); try { + user.setAuthenticationSchema(AuthenticationSchema.LDAP); user = userService.createUser(user, false, false); } catch (WiseMappingException e) { throw new IllegalStateException(e); diff --git a/wise-webapp/src/main/java/com/wisemapping/service/InvalidAuthSchemaException.java b/wise-webapp/src/main/java/com/wisemapping/service/InvalidAuthSchemaException.java new file mode 100755 index 00000000..d812c146 --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/service/InvalidAuthSchemaException.java @@ -0,0 +1,29 @@ +/* +* Copyright [2012] [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.service; + +import com.wisemapping.exceptions.WiseMappingException; + +public class InvalidAuthSchemaException extends WiseMappingException +{ + public InvalidAuthSchemaException(String msg) + { + super(msg); + } +} diff --git a/wise-webapp/src/main/java/com/wisemapping/service/UserService.java b/wise-webapp/src/main/java/com/wisemapping/service/UserService.java index fd9e0cd7..9426d246 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/UserService.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/UserService.java @@ -36,7 +36,7 @@ public interface UserService { public void updateUser(User user); - public void resetPassword(@NotNull String email) throws InvalidUserEmailException; + public void resetPassword(@NotNull String email) throws InvalidUserEmailException, InvalidAuthSchemaException; public void deleteUser(@NotNull User user); diff --git a/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java b/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java index e0849650..67a9c620 100755 --- a/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/service/UserServiceImpl.java @@ -19,12 +19,10 @@ package com.wisemapping.service; import com.wisemapping.dao.UserManager; +import com.wisemapping.exceptions.ClientException; import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.mail.NotificationService; -import com.wisemapping.model.AccessAuditory; -import com.wisemapping.model.Collaborator; -import com.wisemapping.model.Mindmap; -import com.wisemapping.model.User; +import com.wisemapping.model.*; import org.apache.velocity.app.VelocityEngine; import org.jetbrains.annotations.NotNull; import org.springframework.context.MessageSource; @@ -59,9 +57,14 @@ public class UserServiceImpl @Override public void resetPassword(@NotNull String email) - throws InvalidUserEmailException { + throws InvalidUserEmailException, InvalidAuthSchemaException { final User user = userManager.getUserBy(email); if (user != null) { + + if (user.getAuthenticationSchema() != AuthenticationSchema.DATABASE) { + throw new InvalidAuthSchemaException("Could not change password for " + user.getAuthenticationSchema().getCode()); + } + // Generate a random password ... final String password = randomstring(8, 10); user.setPassword(password); @@ -107,6 +110,7 @@ public class UserServiceImpl userManager.auditLogin(accessAuditory); } + @NotNull public User createUser(@NotNull User user, boolean emailConfirmEnabled, boolean welcomeEmail) throws WiseMappingException { final UUID uuid = UUID.randomUUID(); user.setCreationDate(Calendar.getInstance()); diff --git a/wise-webapp/src/main/java/com/wisemapping/webmvc/UsersController.java b/wise-webapp/src/main/java/com/wisemapping/webmvc/UsersController.java index 9835f4b3..c394a978 100644 --- a/wise-webapp/src/main/java/com/wisemapping/webmvc/UsersController.java +++ b/wise-webapp/src/main/java/com/wisemapping/webmvc/UsersController.java @@ -19,6 +19,8 @@ package com.wisemapping.webmvc; +import com.wisemapping.model.AuthenticationSchema; +import com.wisemapping.service.InvalidAuthSchemaException; import com.wisemapping.validator.Messages; import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.model.User; @@ -72,9 +74,8 @@ public class UsersController { userService.resetPassword(email); result = new ModelAndView("forgotPasswordSuccess"); - } catch (InvalidUserEmailException e) { + } catch (InvalidUserEmailException|InvalidAuthSchemaException e) { result = new ModelAndView("forgotPasswordError"); - } return result; } @@ -110,6 +111,7 @@ public class UsersController { user.setPassword(userBean.getPassword()); boolean confirmRegistrationByEmail = false; + user.setAuthenticationSchema(AuthenticationSchema.DATABASE); userService.createUser(user, confirmRegistrationByEmail,true); // Forward to the success view ... diff --git a/wise-webapp/src/main/resources/com/wisemapping/model/Collaborator.hbm.xml b/wise-webapp/src/main/resources/com/wisemapping/model/Collaborator.hbm.xml index 77cbdb99..581fc36a 100755 --- a/wise-webapp/src/main/resources/com/wisemapping/model/Collaborator.hbm.xml +++ b/wise-webapp/src/main/resources/com/wisemapping/model/Collaborator.hbm.xml @@ -27,6 +27,8 @@ + + diff --git a/wise-webapp/src/main/resources/messages_en.properties b/wise-webapp/src/main/resources/messages_en.properties index 86a68777..da269271 100644 --- a/wise-webapp/src/main/resources/messages_en.properties +++ b/wise-webapp/src/main/resources/messages_en.properties @@ -246,7 +246,7 @@ LICENSE=License WELCOME_TO_WISEMAPPING=Welcome to WiseMapping WELCOME_DETAILS=WiseMapping will enable you to create and read your mind maps everywhere. With WiseMapping you can:
  • Embed mind map it in web pages and blogs
  • Link mind map and documents
  • Share your maps with friend and colleagues
  • Export your maps SVG,PNG,JPG and FreeMind
. OPEN_ID_LOGIN=Open Id Login -LOGING_OPENID_DETAILS=Why OpenID? It's a single username and password that allows you to log in to any OpenID-enabled site. It works on thousands of websites.ItŐs an open standard.
Do you already have an account on one of these sites? Click the logo to log in with it here: +LOGING_OPENID_DETAILS=Why OpenID? It's a single username and password that allows you to log in to any OpenID-enabled site. It works on thousands of websites.ItŐs an open standard. Do you already have an account on one of these sites? Click the logo to log in with it here: DIRECT_LINK_EXPLANATION=Copy and paste the link below to share your map with colleagues TEMPORAL_PASSWORD_SENT=Your temporal password has been sent TEMPORAL_PASSWORD_SENT_DETAILS=We've sent you an email that will allow you to reset your password. Please check your email now. diff --git a/wise-webapp/src/main/webapp/jsp/accountSettings.jsp b/wise-webapp/src/main/webapp/jsp/accountSettings.jsp index 3785db23..5c1bf789 100755 --- a/wise-webapp/src/main/webapp/jsp/accountSettings.jsp +++ b/wise-webapp/src/main/webapp/jsp/accountSettings.jsp @@ -3,15 +3,15 @@
-
+
@@ -48,7 +48,7 @@
-
+
@@ -99,16 +99,16 @@ function postChange(url, postBody, msgContainerId, successMsg) { // Change success message ... jQuery.ajax(url, { - async:false, - dataType:'json', - data:postBody, - type:'PUT', - contentType:"text/plain; charset=utf-8", - success:function (data, textStatus, jqXHR) { + async: false, + dataType: 'json', + data: postBody, + type: 'PUT', + contentType: "text/plain; charset=utf-8", + success: function (data, textStatus, jqXHR) { $('#' + msgContainerId).removeClass('alert-error').addClass('alert-info').show(); $('#' + msgContainerId).text(successMsg); }, - error:function (jqXHR, textStatus, errorThrown) { + error: function (jqXHR, textStatus, errorThrown) { $('#' + msgContainerId).removeClass('alert-info').addClass('alert-error').show(); $('#' + msgContainerId).text(textStatus); }