-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
320 changed files
with
10,643 additions
and
18,407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
import eu.europeana.metis.authentication.dao.PsqlMetisUserDao; | ||
import eu.europeana.metis.authentication.user.AccountRole; | ||
import eu.europeana.metis.authentication.user.Credentials; | ||
import eu.europeana.metis.authentication.user.MetisUserView; | ||
import eu.europeana.metis.authentication.user.MetisUserAccessToken; | ||
import eu.europeana.metis.authentication.user.MetisUser; | ||
import eu.europeana.metis.authentication.user.MetisUserAccessToken; | ||
import eu.europeana.metis.authentication.user.MetisUserView; | ||
import eu.europeana.metis.authentication.utils.ZohoMetisUserUtils; | ||
import eu.europeana.metis.exception.BadContentException; | ||
import eu.europeana.metis.exception.GenericMetisException; | ||
|
@@ -36,8 +36,7 @@ | |
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Service that handles all related operations to authentication including communication between a | ||
* psql database and Zoho. | ||
* Service that handles all related operations to authentication including communication between a psql database and Zoho. | ||
* | ||
* @author Simon Tzanakis ([email protected]) | ||
* @since 2018-12-05 | ||
|
@@ -47,10 +46,10 @@ public class AuthenticationService { | |
|
||
private static final int LOG_ROUNDS = 13; | ||
private static final int CREDENTIAL_FIELDS_NUMBER = 2; | ||
@SuppressWarnings("java:S6418") // It is not an actual token | ||
private static final String ACCESS_TOKEN_CHARACTER_BASKET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
private static final int ACCESS_TOKEN_LENGTH = 32; | ||
private static final Pattern TOKEN_MATCHING_PATTERN = Pattern | ||
.compile("^[" + ACCESS_TOKEN_CHARACTER_BASKET + "]*$"); | ||
private static final Pattern TOKEN_MATCHING_PATTERN = Pattern.compile("^[" + ACCESS_TOKEN_CHARACTER_BASKET + "]*$"); | ||
public static final Supplier<BadContentException> COULD_NOT_CONVERT_EXCEPTION_SUPPLIER = () -> new BadContentException( | ||
"Could not convert internal user"); | ||
private final PsqlMetisUserDao psqlMetisUserDao; | ||
|
@@ -243,7 +242,7 @@ public String validateAuthorizationHeaderWithAccessToken(String authorization) | |
} | ||
//Check that the token is of valid structure | ||
if (accessToken.length() != ACCESS_TOKEN_LENGTH || !TOKEN_MATCHING_PATTERN.matcher(accessToken) | ||
.matches()) { | ||
.matches()) { | ||
throw new UserUnauthorizedException("Access token invalid"); | ||
} | ||
return accessToken; | ||
|
@@ -368,7 +367,8 @@ public boolean hasPermissionToRequestUserUpdate(String accessToken, String userE | |
} | ||
MetisUser storedMetisUser = authenticateUserInternal(accessToken); | ||
return storedMetisUser.getAccountRole() == AccountRole.METIS_ADMIN || storedMetisUser.getEmail() | ||
.equals(storedMetisUserToUpdate.getEmail()); | ||
.equals( | ||
storedMetisUserToUpdate.getEmail()); | ||
} | ||
|
||
String generateAccessToken() { | ||
|
@@ -480,14 +480,14 @@ public List<MetisUserView> getAllUsers() { | |
return convert(psqlMetisUserDao.getAllMetisUsers()); | ||
} | ||
|
||
private static MetisUserView convert(MetisUser record) throws BadContentException { | ||
return Optional.ofNullable(record).map(MetisUserView::new) | ||
.orElseThrow(COULD_NOT_CONVERT_EXCEPTION_SUPPLIER); | ||
private static MetisUserView convert(MetisUser metisUser) throws BadContentException { | ||
return Optional.ofNullable(metisUser).map(MetisUserView::new) | ||
.orElseThrow(COULD_NOT_CONVERT_EXCEPTION_SUPPLIER); | ||
} | ||
|
||
private static List<MetisUserView> convert(List<MetisUser> records) { | ||
return Optional.ofNullable(records).stream().flatMap(Collection::stream).map(MetisUserView::new) | ||
.collect(Collectors.toList()); | ||
.collect(Collectors.toList()); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.