Skip to content

Commit

Permalink
prod release 11/17 (#105)
Browse files Browse the repository at this point in the history
* adding qa env

* activate debug logging for qa build

* enable full debug for qa deploy

* enable full debug - bugfix

* pom change to qa

* bugfix - qa pom

* adding qa profile

* bugfix- for qa

* frontend build script

* test google-code-formatter for Java

* applying google Java code formatter

Co-authored-by: RichardYang_2016 <richardyang@google.com>

* Casts list printing function (#91)

* linted and printing functions

* printer button icon

* adding segment ts declaration

* change print casts autosave

* restore formatting in perf-editor template

* delete local vscode setting file

* relint ts changes

* restore lint

Co-authored-by: RichardYang_2016 <richardyang@google.com>

* Replace lodash with higher order funcs (#93)

* linted and printing functions

* printer button icon

* adding segment ts declaration

* change print casts autosave

* restore formatting in perf-editor template

* delete local vscode setting file

* relint ts changes

* restore lint

* replace lodash with higherorder funcs

* separate performace segments as a standalone type

Co-authored-by: RichardYang_2016 <richardyang@google.com>

* Fix types (#94)

* bugfix - printing casts (#96)

Co-authored-by: RichardYang_2016 <richardyang@google.com>

* Remove cache service, it's not used. (#95)

* Remove dead code, including unused parameters as part of enabling noUnusedParameters tsconfig safety check. (#92)

* New full name pipe (#90)

* added fullName pipe

* hook up fullName pipe

* fixed display problem

* Update user-editor.component.ts

* Review fixes

* More review fixes

* Update cloudbuild.unit_tests.yaml (#99)

Codecov will not be able to access repos under google-intern. Thus we will not upload the coverage information to codecov.

* make dashboard columns a little wider (#97)

* make dashboard columns a little wider

* changing quote type

Co-authored-by: RichardYang_2016 <richardyang@google.com>

* add print footer (#100)

* add print footer

* adding banner

Co-authored-by: RichardYang_2016 <richardyang@google.com>

* fix backend test errors (#101)

* fix backend test errors

* Update User.java

* fix karma/npm script issue (#103)

* fix karma/npm script issue

* remove headless chromium  from browser options

* clear trailing space

Co-authored-by: RichardYang_2016 <richardyang@google.com>

* Fix karma script (#104)

* fix karma/npm script issue

* remove headless chromium  from browser options

* clear trailing space

* fix the same for code coverage step

Co-authored-by: RichardYang_2016 <richardyang@google.com>

Co-authored-by: RichardYang_2016 <richardyang@google.com>
Co-authored-by: Mikhail Zaturenskiy <mikzat@gmail.com>
Co-authored-by: yhedholm <69502014+yhedholm@users.noreply.github.com>
Co-authored-by: zephyr-l <66442008+zephyr-l@users.noreply.github.com>
  • Loading branch information
5 people authored Nov 17, 2020
1 parent f687164 commit f94811c
Show file tree
Hide file tree
Showing 78 changed files with 1,488 additions and 930 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ backend/.settings/*
backend/.classpath
backend/.factorypath
.idea
frontend/rolecall/.vscode/settings.json
4 changes: 2 additions & 2 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
</properties>
</profile>
<profile>
<id>clouddev</id>
<id>qa</id>
<properties>
<spring.profiles.active>clouddev</spring.profiles.active>
<spring.profiles.active>qa</spring.profiles.active>
</properties>
</profile>
<profile>
Expand Down
149 changes: 77 additions & 72 deletions backend/src/main/java/com/google/rolecall/ApplicationLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import com.google.rolecall.models.User;
import com.google.rolecall.repos.UserRepository;
import com.google.rolecall.restcontrollers.exceptionhandling.RequestExceptions.InvalidParameterException;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
Expand All @@ -24,123 +22,130 @@
public class ApplicationLoader implements ApplicationRunner {

private Logger logger = Logger.getLogger(ApplicationLoader.class.getName());

private final Environment environment;
private final UserRepository userRepo;
private String adminFirstName;
private String adminLastName;
private String adminEmail;

@Profile({"dev","prod"})
@Profile({"dev", "prod", "qa"})
@Override
public void run(ApplicationArguments args) throws Exception {
// Initialize admin if exists, or create one with given information.
adminFirstName = environment.getProperty("admin.first.name");
adminLastName = environment.getProperty("admin.last.name");
adminEmail = environment.getProperty("admin.email");

Optional<User> possibleAdmin = userRepo.findByEmailIgnoreCase(adminEmail);

possibleAdmin.ifPresentOrElse(this::adminExists, this::createAdmin);
}

private void adminExists(User user) {
logger.log(Level.INFO, String.format("Admin User already exists: %s %s %s",
user.getFirstName(), user.getLastName(), user.getEmail()));
logger.log(
Level.INFO,
String.format(
"Admin User already exists: %s %s %s",
user.getFirstName(), user.getLastName(), user.getEmail()));
}

private void createAdmin() {
User admin;
try {
admin = User.newBuilder()
.setFirstName(adminFirstName)
.setMiddleName("")
.setLastName(adminLastName)
.setSuffix("")
.setEmail(adminEmail)
.setIsActive(true)
.setCanLogin(true)
.setIsAdmin(true)
.build();
} catch(InvalidParameterException e) {
admin =
User.newBuilder()
.setFirstName(adminFirstName)
.setMiddleName("")
.setLastName(adminLastName)
.setSuffix("")
.setEmail(adminEmail)
.setIsActive(true)
.setCanLogin(true)
.setIsAdmin(true)
.build();
} catch (InvalidParameterException e) {
logger.log(Level.SEVERE, "Unable to Create admin. Insufficient Properties.");
return;
}
userRepo.save(admin);
logger.log(Level.WARNING, String.format("Admin User Created: %s %s %s",
adminFirstName, adminLastName, adminEmail));
if(DataCreateError.OK != createTestData()) {
logger.log(
Level.WARNING,
String.format("Admin User Created: %s %s %s", adminFirstName, adminLastName, adminEmail));
if (DataCreateError.OK != createTestData()) {
logger.log(Level.SEVERE, "Unable to Create Sample Data");
}
}

// TODO: Remove the sameple data creation once the customer is up and running.

// Create sample data

private enum DataCreateError {
OK,
OtherError
}

private void createOneUser(String fName, String mName, String lName, String suffix,
String email, String dateJoined) throws ParseException, InvalidParameterException {
private void createOneUser(
String fName, String mName, String lName, String suffix, String email, String dateJoined)
throws ParseException, InvalidParameterException {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
User user;

cal.setTime(sdf.parse(dateJoined));

user = User.newBuilder()
.setFirstName(fName)
.setMiddleName(mName)
.setLastName(lName)
.setSuffix(suffix)
.setEmail(email)
.setDateJoined(cal)
.setIsActive(true)
.setCanLogin(true)
.setIsDancer(true)
.build();
userRepo.save(user);
cal.setTime(sdf.parse(dateJoined));

user =
User.newBuilder()
.setFirstName(fName)
.setMiddleName(mName)
.setLastName(lName)
.setSuffix(suffix)
.setEmail(email)
.setDateJoined(cal)
.setIsActive(true)
.setCanLogin(true)
.setIsDancer(true)
.build();
userRepo.save(user);
}

private DataCreateError createTestData() {
logger.log(Level.WARNING, "Creating test data.");
logger.log(Level.WARNING, "Creating test data.");
try {
createOneUser("Jeroboam", "", "Bozeman", "", "bb@gmail.com","1/1/2020");
createOneUser("Khalia", "", "Campbell", "", "kc@gmail.com","1/1/2020");
createOneUser("Patrick", "", "Coker", "", "pc@gmail.com","1/1/2020");
createOneUser("Sarah", "", "Daley", "", "sd@gmail.com","1/1/2020");
createOneUser("Ghrai", "", "Devore", "", "gde@gmail.com","1/1/2020");
createOneUser("Solomon", "", "Dumas", "", "sdu@gmail.com","1/1/2020");
createOneUser("Samantha", "", "Figgins", "", "sf@gmail.com","1/1/2020");

createOneUser("James", "", "Gilmer", "", "jg@gmail.com","1/1/2020");
createOneUser("Vernard", "", "Gilmore", "", "vg@gmail.com","1/1/2020");
createOneUser("Jacqueline", "", "Green", "", "jgr@gmail.com","1/1/2020");
createOneUser("Jacquelin", "", "Harris", "", "jh@gmail.com","1/1/2020");
createOneUser("Michael", "", "Jackson", " Jr.", "mj@gmail.com","1/1/2020");
createOneUser("Yazzmeen", "", "Laidler", "", "yl@gmail.com","1/1/2020");
createOneUser("Yannick", "", "Lebrun", "", "yle@gmail.com","1/1/2020");
createOneUser("Constance", "Stamatiou", "Lopez", "", "csl@gmail.com","1/1/2020");
createOneUser("Renaldo", "", "Maurice", "", "rm@gmail.com","1/1/2020");
createOneUser("Corrin", "Rachelle", "Mitchell", "", "crm@gmail.com","1/1/2020");

createOneUser("Chalvar", "", "Monteiro", "", "cm@gmail.com","1/1/2020");
createOneUser("Belen", "", "Pereyra", "", "bp@gmail.com","1/1/2020");
createOneUser("Jessica", "Amber", "Pinkett", "", "jap@gmail.com","1/1/2020");
createOneUser("Miranda", "", "Quinn", "", "mq@gmail.com","1/1/2020");
createOneUser("Jamar", "", "Roberts", "", "jr@gmail.com","1/1/2020");
createOneUser("Kanji", "", "Segawa", "", "ks@gmail.com","1/1/2020");
createOneUser("Courtney", "Celeste", "Spears", "", "ccs@gmail.com","1/1/2020");
createOneUser("Jermaine", "", "Terry", "", "jt@gmail.com","1/1/2020");
createOneUser("Christopher", "", "Wilson", "", "cw@gmail.com","1/1/2020");

createOneUser("Brandon", "", "Woolridge", "", "bw@gmail.com","1/1/2020");
} catch(InvalidParameterException e) {
createOneUser("Jeroboam", "", "Bozeman", "", "bb@gmail.com", "1/1/2020");
createOneUser("Khalia", "", "Campbell", "", "kc@gmail.com", "1/1/2020");
createOneUser("Patrick", "", "Coker", "", "pc@gmail.com", "1/1/2020");
createOneUser("Sarah", "", "Daley", "", "sd@gmail.com", "1/1/2020");
createOneUser("Ghrai", "", "Devore", "", "gde@gmail.com", "1/1/2020");
createOneUser("Solomon", "", "Dumas", "", "sdu@gmail.com", "1/1/2020");
createOneUser("Samantha", "", "Figgins", "", "sf@gmail.com", "1/1/2020");

createOneUser("James", "", "Gilmer", "", "jg@gmail.com", "1/1/2020");
createOneUser("Vernard", "", "Gilmore", "", "vg@gmail.com", "1/1/2020");
createOneUser("Jacqueline", "", "Green", "", "jgr@gmail.com", "1/1/2020");
createOneUser("Jacquelin", "", "Harris", "", "jh@gmail.com", "1/1/2020");
createOneUser("Michael", "", "Jackson", " Jr.", "mj@gmail.com", "1/1/2020");
createOneUser("Yazzmeen", "", "Laidler", "", "yl@gmail.com", "1/1/2020");
createOneUser("Yannick", "", "Lebrun", "", "yle@gmail.com", "1/1/2020");
createOneUser("Constance", "Stamatiou", "Lopez", "", "csl@gmail.com", "1/1/2020");
createOneUser("Renaldo", "", "Maurice", "", "rm@gmail.com", "1/1/2020");
createOneUser("Corrin", "Rachelle", "Mitchell", "", "crm@gmail.com", "1/1/2020");

createOneUser("Chalvar", "", "Monteiro", "", "cm@gmail.com", "1/1/2020");
createOneUser("Belen", "", "Pereyra", "", "bp@gmail.com", "1/1/2020");
createOneUser("Jessica", "Amber", "Pinkett", "", "jap@gmail.com", "1/1/2020");
createOneUser("Miranda", "", "Quinn", "", "mq@gmail.com", "1/1/2020");
createOneUser("Jamar", "", "Roberts", "", "jr@gmail.com", "1/1/2020");
createOneUser("Kanji", "", "Segawa", "", "ks@gmail.com", "1/1/2020");
createOneUser("Courtney", "Celeste", "Spears", "", "ccs@gmail.com", "1/1/2020");
createOneUser("Jermaine", "", "Terry", "", "jt@gmail.com", "1/1/2020");
createOneUser("Christopher", "", "Wilson", "", "cw@gmail.com", "1/1/2020");

createOneUser("Brandon", "", "Woolridge", "", "bw@gmail.com", "1/1/2020");
} catch (InvalidParameterException e) {
return DataCreateError.OtherError;
} catch(ParseException e) {
} catch (ParseException e) {
return DataCreateError.OtherError;
}
return DataCreateError.OK;
Expand Down
4 changes: 3 additions & 1 deletion backend/src/main/java/com/google/rolecall/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public static class Permissions {
}

// Prevents object creation
private Constants() {
// private
// the above (private) was commented out because it breaks our unit tests
Constants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.logging.Level;
import java.util.logging.Logger;

import org.springframework.context.annotation.Profile;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
Expand All @@ -15,7 +14,7 @@
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import org.springframework.stereotype.Component;

@Profile({"dev", "clouddev"})
@Profile({"dev"})
@Component
public class CustomDebugAuthenticationProvider implements AuthenticationProvider {

Expand All @@ -25,30 +24,29 @@ public class CustomDebugAuthenticationProvider implements AuthenticationProvider

/**
* Verifies the email of the user is in the database.
*
* @param authentication Contains the session's current authentication levels and at least
* the email of the user.
*
* @param authentication Contains the session's current authentication levels and at least the
* email of the user.
* @return The authentication based on the email of the user as a {@link RememberMeToken} token.
* @throws AuthenticationException When the email is not in the database.
*/
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String email = authentication.getName();

UserDetails user;
try {
user = detailService.loadUserByUsername(email);
} catch(UsernameNotFoundException ex) {
throw new BadCredentialsException(String.format(
"User with email %s could not be authenticated.", email));
} catch (UsernameNotFoundException ex) {
throw new BadCredentialsException(
String.format("User with email %s could not be authenticated.", email));
}

Authentication auth = new RememberMeAuthenticationToken("Bad_HardCoded_Key", user, user.getAuthorities());
Authentication auth =
new RememberMeAuthenticationToken("Bad_HardCoded_Key", user, user.getAuthorities());
return auth;
}


@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(PreAuthenticatedAuthenticationToken.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.google.rolecall.authentication;

import com.google.rolecall.services.GoogleAuthServices;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.rolecall.services.GoogleAuthServices;

import org.springframework.context.annotation.Profile;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.AuthenticationServiceException;
Expand All @@ -19,7 +17,7 @@
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import org.springframework.stereotype.Component;

@Profile("prod")
@Profile({"prod", "qa"})
@Component
public class CustomOauthAuthenticationProvider implements AuthenticationProvider {

Expand All @@ -30,14 +28,13 @@ public class CustomOauthAuthenticationProvider implements AuthenticationProvider

/**
* Authenticates a user through existence in the database and a valid Google Oauth Id Token.
*
*
* @param authentication current authentication of a user
* @return Returns the user's authentication as a {@link RememberAuthenticationToken} token
* @return Returns the user's authentication as a {@link RememberAuthenticationToken} token
* @throws AuthenticationException when bad credentials are provided or is unable to authenticate
*/
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String email = authentication.getName();
String oauthToken = authentication.getCredentials().toString();

Expand All @@ -46,42 +43,42 @@ public Authentication authenticate(Authentication authentication)
UserDetails user;
try {
user = detailService.loadUserByUsername(email);
} catch(UsernameNotFoundException ex) {
throw new BadCredentialsException(String.format(
"User with email %s could not be authenticated.", email));
} catch (UsernameNotFoundException ex) {
throw new BadCredentialsException(
String.format("User with email %s could not be authenticated.", email));
}

boolean isValid = false;

try {
isValid = authService.isValidAccessToken(email, oauthToken);
} catch(IOException ex) {
} catch (IOException ex) {
logger.log(Level.SEVERE, "Unable to validate token with Google.", ex);
throw new AuthenticationServiceException("Unable to successfully authenticate", ex);
} catch(Exception ex) {
} catch (Exception ex) {
logger.log(Level.WARNING, "Unexcepted Exception was thrown.", ex);
throw new AuthenticationServiceException("Unable to successfully authenticate", ex);
}

if(!isValid) {
if (!isValid) {
logger.log(Level.INFO, String.format("Login failed for %s. Invalid Credentials", email));
throw new BadCredentialsException("Email and token do not validate with Google.");
}

logger.log(Level.INFO, String.format("Login for %s was successful", email));

Authentication auth = new RememberMeAuthenticationToken("Bad_HardCoded_Key", user, user.getAuthorities());
Authentication auth =
new RememberMeAuthenticationToken("Bad_HardCoded_Key", user, user.getAuthorities());
return auth;
}


@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(PreAuthenticatedAuthenticationToken.class);
}

public CustomOauthAuthenticationProvider(UserDetailsService detailService,
GoogleAuthServices authService) {
public CustomOauthAuthenticationProvider(
UserDetailsService detailService, GoogleAuthServices authService) {
this.detailService = detailService;
this.authService = authService;
logger.log(Level.INFO, "Using oauth authentication");
Expand Down
Loading

0 comments on commit f94811c

Please sign in to comment.