mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
Fix login bug.
This commit is contained in:
parent
56c322fd3f
commit
885de4e1c1
@ -11,8 +11,10 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
@ -43,13 +45,13 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
|
|
||||||
if (email.isPresent() && jwtTokenUtil.validateJwtToken(token.get())) {
|
if (email.isPresent() && jwtTokenUtil.validateJwtToken(token.get())) {
|
||||||
// Is it an existing user ?
|
// Is it an existing user ?
|
||||||
|
try {
|
||||||
final UserDetails userDetails = userDetailsService.loadUserByUsername(email.get());
|
final UserDetails userDetails = userDetailsService.loadUserByUsername(email.get());
|
||||||
if (userDetails != null) {
|
|
||||||
final UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
|
final UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
|
||||||
userDetails, null, userDetails.getAuthorities());
|
userDetails, null, userDetails.getAuthorities());
|
||||||
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
||||||
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
||||||
} else {
|
} catch (UsernameNotFoundException e) {
|
||||||
logger.trace("User " + email.get() + " could not be found");
|
logger.trace("User " + email.get() + " could not be found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,16 @@ public class MindmapController extends BaseController {
|
|||||||
return new RestMindmap(mindMap, user);
|
return new RestMindmap(mindMap, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("isAuthenticated() and hasRole('ROLE_USER')")
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = "/{id}/metadata", produces = {"application/json"})
|
||||||
|
@ResponseBody
|
||||||
|
public RestMindmap retrieveMetadata(@PathVariable int id) throws WiseMappingException {
|
||||||
|
final User user = Utils.getUser();
|
||||||
|
|
||||||
|
final Mindmap mindMap = findMindmapById(id);
|
||||||
|
return new RestMindmap(mindMap, user);
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated() and hasRole('ROLE_USER')")
|
@PreAuthorize("isAuthenticated() and hasRole('ROLE_USER')")
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/", produces = {"application/json"})
|
@RequestMapping(method = RequestMethod.GET, value = "/", produces = {"application/json"})
|
||||||
public RestMindmapList retrieveList(@RequestParam(required = false) String q) {
|
public RestMindmapList retrieveList(@RequestParam(required = false) String q) {
|
||||||
|
@ -65,7 +65,7 @@ public class UserController extends BaseController {
|
|||||||
@Value("${google.recaptcha2.enabled:false}")
|
@Value("${google.recaptcha2.enabled:false}")
|
||||||
private Boolean recatchaEnabled;
|
private Boolean recatchaEnabled;
|
||||||
|
|
||||||
@Value("${accounts.exclusion.domain:''}")
|
@Value("${app.accounts.exclusion.domain:''}")
|
||||||
private String domainBanExclusion;
|
private String domainBanExclusion;
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
@ -99,6 +99,8 @@ public class UserController extends BaseController {
|
|||||||
user.setAuthenticationType(AuthenticationType.DATABASE);
|
user.setAuthenticationType(AuthenticationType.DATABASE);
|
||||||
userService.createUser(user, false, true);
|
userService.createUser(user, false, true);
|
||||||
response.setHeader("Location", "/api/restful/users/" + user.getId());
|
response.setHeader("Location", "/api/restful/users/" + user.getId());
|
||||||
|
response.setHeader("ResourceId", Integer.toString(user.getId()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.PUT, value = "/resetPassword", produces = {"application/json"})
|
@RequestMapping(method = RequestMethod.PUT, value = "/resetPassword", produces = {"application/json"})
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2022] [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.rest.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.wisemapping.exceptions.InvalidMindmapException;
|
||||||
|
import com.wisemapping.exceptions.WiseMappingException;
|
||||||
|
import com.wisemapping.model.*;
|
||||||
|
import com.wisemapping.util.TimeUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
@JsonAutoDetect(
|
||||||
|
fieldVisibility = JsonAutoDetect.Visibility.NONE,
|
||||||
|
setterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
|
||||||
|
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
|
||||||
|
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY
|
||||||
|
)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
public class RestMindmapMetadata {
|
||||||
|
|
||||||
|
public RestMindmapMetadata() throws WiseMappingException {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -58,6 +58,9 @@ app:
|
|||||||
mail:
|
mail:
|
||||||
serverSendEmail: root@localhost
|
serverSendEmail: root@localhost
|
||||||
supportEmail: root@localhost
|
supportEmail: root@localhost
|
||||||
|
# accounts:
|
||||||
|
# exclusion:
|
||||||
|
# domain:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user