Outh working!. Pending:

- Test all databases
- Migration Scripts
- Manage error due to changing of authentication schemas.
- Link from the login page.
- What happend with the logout ?.
This commit is contained in:
Paulo Gustavo Veiga 2013-03-17 18:51:33 -03:00
parent 2f8df725c9
commit 94356a5773
13 changed files with 113 additions and 40 deletions

View File

@ -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,

View File

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

View File

@ -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<String> tags = new HashSet<String>();
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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 ...

View File

@ -27,6 +27,8 @@
<property name="activationDate" column="activation_date"/>
<property name="activationCode" column="activation_code"/>
<property name="allowSendEmail" column="allow_send_email"/>
<property name="autheticationCode" column="auth_schema"/>
<property name="locale"/>
<set name="tags" table="TAG">
<key column="user_id"/>

View File

@ -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: <ul><li>Embed mind map it in web pages and blogs</li><li>Link mind map and documents</li><li>Share your maps with friend and colleagues</li><li>Export your maps SVG,PNG,JPG and FreeMind</li></ul>.
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.</br>Do you already have an account on one of these sites? Click the logo to <b>log in</b> 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 <b>log in</b> 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.

View File

@ -3,15 +3,15 @@
<div>
<ul class="nav nav-tabs">
<c:if test="${requestScope['security.type']=='db'}">
<li class="active"><a href="#changeUserPanel" data-toggle="pill"><spring:message code="GENERAL"/></a></li>
<li><a href="#changePasswordPanel" data-toggle="pill"><spring:message code="SECURITY"/></a></li>
</c:if>
<c:if test="${principal.databaseSchema}">
<li class="active"><a href="#changeUserPanel" data-toggle="pill"><spring:message code="GENERAL"/></a></li>
<li><a href="#changePasswordPanel" data-toggle="pill"><spring:message code="SECURITY"/></a></li>
</c:if>
<li><a href="#languagePanel" data-toggle="pill"><spring:message code="LANGUAGE"/></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane fade active in" id="changeUserPanel">
<div class="tab-pane fade ${principal.databaseSchema?'active in':''}" id="changeUserPanel">
<div id="changeInfoMsg" class="alert">
</div>
<form action="#" method="POST" id="changeUserForm">
@ -48,7 +48,7 @@
</fieldset>
</form>
</div>
<div class="tab-pane fade" id="languagePanel">
<div class="tab-pane fade ${principal.databaseSchema?'':'active in'}" id="languagePanel">
<div id="languageMsg" class="alert">
</div>
<form action="#" method="POST" id="languageForm">
@ -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);
}