Merge branch 'sonar-fix' into 'dev'
Sonarqube fixes See merge request sa4-2020/the-sanmarinoes/backend!128
This commit is contained in:
commit
1e99f5a501
7 changed files with 21 additions and 57 deletions
|
@ -31,10 +31,4 @@ public class CORSFilter implements Filter {
|
|||
|
||||
chain.doFilter(req, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) {}
|
||||
|
||||
@Override
|
||||
public void destroy() {}
|
||||
}
|
||||
|
|
|
@ -36,9 +36,9 @@ public class JWTRequestFilter extends OncePerRequestFilter {
|
|||
try {
|
||||
username = jwtTokenUtils.getUsernameFromToken(jwtToken);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("Unable to get JWT Token");
|
||||
logger.info("Unable to get JWT Token");
|
||||
} catch (ExpiredJwtException e) {
|
||||
System.out.println("JWT Token has expired");
|
||||
logger.info("JWT Token has expired");
|
||||
}
|
||||
} else {
|
||||
logger.warn("JWT Token does not begin with Bearer String");
|
||||
|
|
|
@ -68,7 +68,7 @@ public class JWTTokenUtils {
|
|||
* @param userDetails user details to validate against
|
||||
* @return true if valid, false if not
|
||||
*/
|
||||
public Boolean validateToken(String token, UserDetails userDetails) {
|
||||
public boolean validateToken(String token, UserDetails userDetails) {
|
||||
final String username = getUsernameFromToken(token);
|
||||
return (username.equals(userDetails.getUsername()) && !isTokenExpired(token));
|
||||
}
|
||||
|
|
|
@ -1,21 +1,5 @@
|
|||
package ch.usi.inf.sa4.sanmarinoes.smarthut.config;
|
||||
|
||||
/*
|
||||
* Copyright (C) 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
@ -158,8 +142,8 @@ import java.util.Map;
|
|||
public final class RuntimeTypeAdapterFactory<T> implements TypeAdapterFactory {
|
||||
private final Class<?> baseType;
|
||||
private final String typeFieldName;
|
||||
private final Map<String, Class<?>> labelToSubtype = new LinkedHashMap<String, Class<?>>();
|
||||
private final Map<Class<?>, String> subtypeToLabel = new LinkedHashMap<Class<?>, String>();
|
||||
private final Map<String, Class<?>> labelToSubtype = new LinkedHashMap<>();
|
||||
private final Map<Class<?>, String> subtypeToLabel = new LinkedHashMap<>();
|
||||
private final boolean maintainType;
|
||||
|
||||
private RuntimeTypeAdapterFactory(
|
||||
|
@ -179,7 +163,7 @@ public final class RuntimeTypeAdapterFactory<T> implements TypeAdapterFactory {
|
|||
*/
|
||||
public static <T> RuntimeTypeAdapterFactory<T> of(
|
||||
Class<T> baseType, String typeFieldName, boolean maintainType) {
|
||||
return new RuntimeTypeAdapterFactory<T>(baseType, typeFieldName, maintainType);
|
||||
return new RuntimeTypeAdapterFactory<>(baseType, typeFieldName, maintainType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,7 +171,7 @@ public final class RuntimeTypeAdapterFactory<T> implements TypeAdapterFactory {
|
|||
* the type field name. Type field names are case sensitive.
|
||||
*/
|
||||
public static <T> RuntimeTypeAdapterFactory<T> of(Class<T> baseType, String typeFieldName) {
|
||||
return new RuntimeTypeAdapterFactory<T>(baseType, typeFieldName, false);
|
||||
return new RuntimeTypeAdapterFactory<>(baseType, typeFieldName, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,7 +179,7 @@ public final class RuntimeTypeAdapterFactory<T> implements TypeAdapterFactory {
|
|||
* field name.
|
||||
*/
|
||||
public static <T> RuntimeTypeAdapterFactory<T> of(Class<T> baseType) {
|
||||
return new RuntimeTypeAdapterFactory<T>(baseType, "type", false);
|
||||
return new RuntimeTypeAdapterFactory<>(baseType, "type", false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,26 +200,15 @@ public final class RuntimeTypeAdapterFactory<T> implements TypeAdapterFactory {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers {@code type} identified by its {@link Class#getSimpleName simple name}. Labels are
|
||||
* case sensitive.
|
||||
*
|
||||
* @throws IllegalArgumentException if either {@code type} or its simple name have already been
|
||||
* registered on this type adapter.
|
||||
*/
|
||||
public RuntimeTypeAdapterFactory<T> registerSubtype(Class<? extends T> type) {
|
||||
return registerSubtype(type, type.getSimpleName());
|
||||
}
|
||||
|
||||
public <R> TypeAdapter<R> create(Gson gson, TypeToken<R> type) {
|
||||
if (type.getRawType() != baseType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Map<String, TypeAdapter<?>> labelToDelegate =
|
||||
new LinkedHashMap<String, TypeAdapter<?>>(labelToSubtype.size());
|
||||
new LinkedHashMap<>(labelToSubtype.size());
|
||||
final Map<Class<?>, TypeAdapter<?>> subtypeToDelegate =
|
||||
new LinkedHashMap<Class<?>, TypeAdapter<?>>(labelToSubtype.size());
|
||||
new LinkedHashMap<>(labelToSubtype.size());
|
||||
for (Map.Entry<String, Class<?>> entry : labelToSubtype.entrySet()) {
|
||||
TypeAdapter<?> delegate =
|
||||
gson.getDelegateAdapter(this, TypeToken.get(entry.getValue()));
|
||||
|
|
|
@ -33,8 +33,7 @@ public class AutomationController {
|
|||
@GetMapping
|
||||
public List<Automation> getAll(
|
||||
@RequestParam(value = "hostId", required = false) Long hostId,
|
||||
final Principal principal)
|
||||
throws NotFoundException {
|
||||
final Principal principal) {
|
||||
final Long userId = userService.findByUsername(principal.getName()).getId();
|
||||
return automationRepository.findAllByUserId(userId);
|
||||
}
|
||||
|
|
|
@ -49,10 +49,10 @@ public class DimmableLightController extends GuestEnabledController<DimmableLigh
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Assume that only the host can create a device
|
||||
Here save always as host, but remember to propagate change to guests (DeviceService.saveAsOwner())
|
||||
*/
|
||||
/**
|
||||
* Assume that only the host can create a device Here save always as host, but remember to
|
||||
* propagate change to guests (DeviceService.saveAsOwner())
|
||||
*/
|
||||
@PostMapping
|
||||
public DimmableLight create(
|
||||
@Valid @RequestBody DimmableSaveRequest dl, final Principal principal)
|
||||
|
@ -61,9 +61,7 @@ public class DimmableLightController extends GuestEnabledController<DimmableLigh
|
|||
return save(new DimmableLight(), dl, principal.getName(), null);
|
||||
}
|
||||
|
||||
/*
|
||||
Logic for saving either as owner or guest is handled in method save of this controller
|
||||
*/
|
||||
/** Logic for saving either as owner or guest is handled in method save of this controller */
|
||||
@PutMapping
|
||||
public DimmableLight update(
|
||||
@Valid @RequestBody DimmableSaveRequest sp,
|
||||
|
@ -84,8 +82,10 @@ public class DimmableLightController extends GuestEnabledController<DimmableLigh
|
|||
deviceService.deleteByIdAsOwner(id, principal.getName());
|
||||
}
|
||||
|
||||
// the full url should be: "/dimmableLight/{id}/state?sceneId={sceneId}
|
||||
// however it is not necessary to specify the query in the mapping
|
||||
/**
|
||||
* the full url should be: "/dimmableLight/{id}/state?sceneId={sceneId} however it is not
|
||||
* necessary to specify the query in the mapping
|
||||
*/
|
||||
@PostMapping("/{id}/state")
|
||||
public State<? extends Dimmable> sceneBinding(
|
||||
@PathVariable("id") long deviceId,
|
||||
|
|
|
@ -5,7 +5,6 @@ import static ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils.toList;
|
|||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.GuestPermissionsRequest;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.GuestsUpdateRequest;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.UserResponse;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.error.NotFoundException;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.EagerUserRepository;
|
||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.User;
|
||||
import java.security.Principal;
|
||||
|
@ -46,8 +45,7 @@ public class GuestController {
|
|||
|
||||
@PutMapping("/guests")
|
||||
public List<User> setGuests(
|
||||
@RequestBody @Valid GuestsUpdateRequest g, final Principal principal)
|
||||
throws NotFoundException {
|
||||
@RequestBody @Valid GuestsUpdateRequest g, final Principal principal) {
|
||||
Iterable<User> guests = userRepository.findAllById(g.ids);
|
||||
User host = userRepository.findByUsername(principal.getName());
|
||||
|
||||
|
|
Loading…
Reference in a new issue