Finish OpenId implementation.

This commit is contained in:
Paulo Gustavo Veiga
2013-03-17 23:17:55 -03:00
parent 94356a5773
commit 9b21c77485
16 changed files with 80 additions and 47 deletions

View File

@@ -1,12 +1,15 @@
package com.wisemapping.model;
public enum AuthenticationSchema {
import org.jetbrains.annotations.NotNull;
public enum AuthenticationType {
DATABASE('D'),
LDAP('L'),
OPENID('O');
private final char schemaCode;
AuthenticationSchema(char schemaCode) {
AuthenticationType(char schemaCode) {
this.schemaCode = schemaCode;
}
@@ -14,10 +17,11 @@ public enum AuthenticationSchema {
return schemaCode;
}
public static AuthenticationSchema valueOf(char code) {
AuthenticationSchema result = null;
AuthenticationSchema[] values = AuthenticationSchema.values();
for (AuthenticationSchema value : values) {
@NotNull
public static AuthenticationType valueOf(char code) {
AuthenticationType result = null;
AuthenticationType[] values = AuthenticationType.values();
for (AuthenticationType value : values) {
if (value.getCode() == code) {
result = value;
break;

View File

@@ -38,7 +38,10 @@ public class User
private Set<String> tags = new HashSet<String>();
private boolean allowSendEmail = false;
private String locale;
private AuthenticationSchema authenticationSchema;
private AuthenticationType authenticationType;
private String authenticatorUri;
public User() {
}
@@ -116,24 +119,32 @@ public class User
this.locale = locale;
}
public char getAutheticationCode() {
return this.authenticationSchema != null ? this.authenticationSchema.getCode() : null;
public char getAutheticationTypeCode() {
return this.authenticationType != null ? this.authenticationType.getCode() : null;
}
public void setAutheticationCode(char code) {
this.authenticationSchema = AuthenticationSchema.valueOf(code);
public void setAutheticationTypeCode(char code) {
this.authenticationType = AuthenticationType.valueOf(code);
}
public AuthenticationSchema getAuthenticationSchema() {
return authenticationSchema;
public AuthenticationType getAuthenticationType() {
return authenticationType;
}
public void setAuthenticationSchema(@NotNull AuthenticationSchema authenticationSchema) {
this.authenticationSchema = authenticationSchema;
public void setAuthenticationType(@NotNull AuthenticationType authenticationType) {
this.authenticationType = authenticationType;
}
public boolean isDatabaseSchema(){
return this.authenticationSchema==AuthenticationSchema.DATABASE;
return this.authenticationType == AuthenticationType.DATABASE;
}
public String getAuthenticatorUri() {
return authenticatorUri;
}
public void setAuthenticatorUri(String authenticatorUri) {
this.authenticatorUri = authenticatorUri;
}

View File

@@ -19,7 +19,7 @@
package com.wisemapping.rest;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.AuthenticationSchema;
import com.wisemapping.model.AuthenticationType;
import com.wisemapping.model.User;
import com.wisemapping.rest.model.RestUser;
import com.wisemapping.service.UserService;
@@ -85,7 +85,7 @@ public class AdminController extends BaseController {
}
// Finally create the user ...
delegated.setAuthenticationSchema(AuthenticationSchema.DATABASE);
delegated.setAuthenticationType(AuthenticationType.DATABASE);
userService.createUser(delegated, false, true);
response.setHeader("Location", "/service/admin/users/" + user.getId());
}

View File

@@ -20,7 +20,7 @@ package com.wisemapping.security;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.AuthenticationSchema;
import com.wisemapping.model.AuthenticationType;
import com.wisemapping.model.User;
import com.wisemapping.service.UserService;
import org.jetbrains.annotations.NotNull;
@@ -60,10 +60,15 @@ public class UserDetailsService
final User result;
if (dbUser != null) {
if (!token.getIdentityUrl().equals(dbUser.getAuthenticatorUri())) {
throw new IllegalStateException("Identity url for this user can not change:" + token.getIdentityUrl());
}
result = dbUser;
} else {
try {
tUser.setAuthenticationSchema(AuthenticationSchema.OPENID);
tUser.setAuthenticationType(AuthenticationType.OPENID);
tUser.setAuthenticatorUri(token.getIdentityUrl());
result = userService.createUser(tUser, false, false);
} catch (WiseMappingException e) {
throw new IllegalStateException(e);

View File

@@ -2,7 +2,7 @@ package com.wisemapping.security.ldap;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.AuthenticationSchema;
import com.wisemapping.model.AuthenticationType;
import com.wisemapping.model.User;
import com.wisemapping.security.UserDetails;
import com.wisemapping.service.UserService;
@@ -65,7 +65,7 @@ public class LdapUserDetailsContextMapper implements UserDetailsContextMapper {
user.setActivationDate(now);
try {
user.setAuthenticationSchema(AuthenticationSchema.LDAP);
user.setAuthenticationType(AuthenticationType.LDAP);
user = userService.createUser(user, false, false);
} catch (WiseMappingException e) {
throw new IllegalStateException(e);

View File

@@ -19,7 +19,6 @@
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.*;
@@ -61,8 +60,8 @@ public class UserServiceImpl
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());
if (user.getAuthenticationType() != AuthenticationType.DATABASE) {
throw new InvalidAuthSchemaException("Could not change password for " + user.getAuthenticationType().getCode());
}
// Generate a random password ...

View File

@@ -45,14 +45,14 @@ public class LoginController {
return result;
}
@RequestMapping(value = "loginOpenId", method = RequestMethod.GET)
@RequestMapping(value = "loginopenid", method = RequestMethod.GET)
protected ModelAndView showLoginOpenIdPage() {
final User user = Utils.getUser(false);
ModelAndView result;
if (user != null) {
result = new ModelAndView("forward:/c/maps/");
} else {
result = new ModelAndView("loginOpenId");
result = new ModelAndView("loginopenid");
}
return result;
}

View File

@@ -19,7 +19,7 @@
package com.wisemapping.webmvc;
import com.wisemapping.model.AuthenticationSchema;
import com.wisemapping.model.AuthenticationType;
import com.wisemapping.service.InvalidAuthSchemaException;
import com.wisemapping.validator.Messages;
import com.wisemapping.exceptions.WiseMappingException;
@@ -111,7 +111,7 @@ public class UsersController {
user.setPassword(userBean.getPassword());
boolean confirmRegistrationByEmail = false;
user.setAuthenticationSchema(AuthenticationSchema.DATABASE);
user.setAuthenticationType(AuthenticationType.DATABASE);
userService.createUser(user, confirmRegistrationByEmail,true);
// Forward to the success view ...