Skip to content

Commit

Permalink
[ALS-4793] Add user email and fix return
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcolon021 committed Aug 4, 2023
1 parent 20c4ecb commit babe1f2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,22 @@ public User findByUUID(UUID uuid) {
return null;
}

/**
* Creates a user with a subject of "open_access|{uuid}"
* and an email of "{uuid}@open_access.com"
*
* @return the created user
*/
public User createOpenAccessUser() {
// I can either use the user subject combined with a random string, or I can use the uuid of the user
// after I create the user. I think I will use the uuid of the user after I create the user.

// create a new user
User user = new User();
em().persist(user);

// We should have a user now, so get the user by uuid
User result = getById(user.getUuid());
result.setSubject("open_access|" + result.getUuid().toString());
result.setRoles(new HashSet<>());
result.setEmail(user.getUuid() + "@open_access.com");
em().merge(result);

return null;
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public class AuthService {

private Logger logger = LoggerFactory.getLogger(this.getClass());

@Inject
AuthorizationService authorizationService;

@Inject
AuthenticationService authenticationService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public class OpenAuthService {
@ApiOperation(value = "The authentication endpoint for retrieving a valid user token")
@POST
@Path("/authentication")
public Response authentication(@Context UriInfo uriInfo, @ApiParam(required = true, value = "A json object that includes all Oauth authentication needs, for example, access_token and redirectURI") Map<String, String> authRequest) {
public Response authentication(@ApiParam(required = true, value = "A json object that includes all Oauth authentication needs, for example, access_token and redirectURI") Map<String, String> authRequest) {
logger.debug("authentication() starting...");

return openAuthenticationService.authenticate(uriInfo, authRequest);
return openAuthenticationService.authenticate(authRequest);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ public class OpenAuthenticationService {
@Inject
AuthUtils authUtil;

public Response authenticate(UriInfo uriInfo, Map<String, String> authRequest) {
public Response authenticate(Map<String, String> authRequest) {
String userUUID = authRequest.get("UUID");
User current_user = null;

// Try to get the user by UUID
if (StringUtils.isNotBlank(userUUID)) {
UUID uuid = UUID.fromString(userUUID);

// Get the user from the database
current_user = userRepository.findByUUID(uuid);
}


// If we can't find the user by UUID, create a new one
if (current_user == null) {
current_user = userRepository.createOpenAccessUser();

Expand Down

0 comments on commit babe1f2

Please sign in to comment.