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

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