Skip to content

Commit

Permalink
Added Check Style
Browse files Browse the repository at this point in the history
  • Loading branch information
oblodgett committed May 28, 2024
1 parent d852e2d commit cb9d08b
Show file tree
Hide file tree
Showing 419 changed files with 4,272 additions and 3,922 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Checkstyle Action
on: pull_request

jobs:
checkstyle_job:
runs-on: ubuntu-latest
name: Checkstyle Job
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run check style
uses: nikitasavinov/checkstyle-action@master
with:
level: 'error'
fail_on_error: 'true'
github_token: ${{ secrets.GH_PAT }}
reporter: 'github-pr-check'
filter_mode: 'file'
checkstyle_config: checkstyle.xml
tool_name: 'reviewdog'
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ docker-run:
debug:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5045 -jar target/agr_curation_api-bootable.jar

checkstyle:
mvn checkstyle:check

test:
mvn test

Expand Down
90 changes: 90 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<property name="fileExtensions" value="java" />
<module name="LineLength">
<property name="max" value="400" />
</module>
<module name="TreeWalker">
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE.OFF\: ?([\w\|]+)" />
<property name="onCommentFormat" value="CHECKSTYLE.ON\: ?([\w\|]+)" />
<property name="checkFormat" value="$1" />
</module>
<module name="AnnotationUseStyle">
<property name="elementStyle" value="ignore" />
</module>
<module name="MissingOverride">
<property name="javaFiveCompatibility" value="true" />
</module>
<module name="EmptyBlock">
<property name="option" value="text" />
<property name="tokens" value="LITERAL_CATCH" />
</module>
<module name="EmptyBlock">
<property name="tokens" value="LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF, LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, STATIC_INIT" />
<property name="option" value="text" />
</module>
<module name="LeftCurly" />
<module name="NeedBraces" />
<module name="RightCurly" />
<module name="HideUtilityClassConstructor" />
<module name="EmptyStatement" />
<module name="EqualsHashCode" />
<module name="InnerAssignment" />
<module name="SimplifyBooleanExpression" />
<module name="SimplifyBooleanReturn" />
<module name="StringLiteralEquality" />
<module name="IllegalThrows">
<property name="illegalClassNames" value="java.lang.Error, java.lang.RuntimeException" />
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="^\t* "/>
<property name="message" value="Indent must use tab characters"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="ExplicitInitialization" />
<module name="DefaultComesLast" />
<module name="FallThrough" />
<module name="MultipleVariableDeclarations" />
<module name="UnnecessaryParentheses" />
<module name="RedundantImport" />
<module name="UnusedImports">
<property name="processJavadoc" value="true" />
</module>
<module name="UpperEll" />
<module name="ArrayTypeStyle" />
<module name="RedundantModifier">
<property name="tokens" value="METHOD_DEF,VARIABLE_DEF,ANNOTATION_FIELD_DEF,INTERFACE_DEF,CLASS_DEF,ENUM_DEF" />
</module>
<module name="ClassTypeParameterName" />
<module name="LocalFinalVariableName" />
<module name="LocalVariableName" />
<module name="MemberName" />
<module name="MethodName">
<property name="format" value="^(([A-Z][A-Z0-9]+)|([a-z][a-z0-9]*))([A-Z][a-z0-9]*)*" />
</module>
<module name="MethodTypeParameterName" />
<module name="PackageName" />
<module name="ParameterName" />
<module name="StaticVariableName" />
<module name="TypeName" />
<module name="GenericWhitespace" />
<module name="EmptyForInitializerPad" />
<module name="EmptyForIteratorPad" />
<module name="MethodParamPad" />
<module name="NoWhitespaceAfter">
<property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS" />
</module>
<module name="NoWhitespaceBefore">
<property name="allowLineBreaks" value="true" />
<property name="tokens" value="SEMI,POST_DEC,POST_INC" />
</module>
<module name="OperatorWrap" />
<module name="ParenPad" />
<module name="TypecastParenPad" />
<module name="WhitespaceAfter">
<property name="tokens" value="COMMA,SEMI,TYPECAST" />
</module>
<module name="WhitespaceAround" />
</module>
</module>
9 changes: 9 additions & 0 deletions checkstyle_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<property name="fileExtensions" value="java"/>

<module name="FileTabCharacter">
<property name="fileExtensions" value="java"/>
</module>
</module>
41 changes: 41 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<okta-jwt.version>0.5.1</okta-jwt.version>
<quarkus.platform.version>3.5.0</quarkus.platform.version>
<surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
<maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
<checkstyle.version>10.17.0</checkstyle.version>
</properties>

<scm>
Expand Down Expand Up @@ -486,7 +488,46 @@
<tagNameFormat>v@{project.version}</tagNameFormat>
</configuration>
</plugin>


</plugins>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<propertyExpansion>config_loc=${basedir}</propertyExpansion>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins>
</pluginManagement>

</build>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,27 @@
public class AuthenticationFilter implements ContainerRequestFilter {

@Inject
@AuthenticatedUser
Event<Person> userAuthenticatedEvent;
@AuthenticatedUser Event<Person> userAuthenticatedEvent;

@Inject
AuthenticationService authenticationService;
@Inject AuthenticationService authenticationService;

@Inject
PersonDAO personDAO;
@Inject PersonDAO personDAO;

@Inject
AllianceMemberDAO allianceMemberDAO;
@Inject AllianceMemberDAO allianceMemberDAO;

@Inject
PersonService personService;
@Inject PersonService personService;

@Inject
PersonUniqueIdHelper loggedInPersonUniqueId;
@Inject PersonUniqueIdHelper loggedInPersonUniqueId;

@ConfigProperty(name = "okta.authentication")
Instance<Boolean> okta_auth;
@ConfigProperty(name = "okta.authentication") Instance<Boolean> oktaAuth;

@ConfigProperty(name = "okta.url")
Instance<String> okta_url;
@ConfigProperty(name = "okta.url") Instance<String> oktaUrl;

@ConfigProperty(name = "okta.client.id")
Instance<String> client_id;
@ConfigProperty(name = "okta.client.id") Instance<String> clientId;

@ConfigProperty(name = "okta.client.secret")
Instance<String> client_secret;
@ConfigProperty(name = "okta.client.secret") Instance<String> clientSecret;

@ConfigProperty(name = "okta.api.token")
Instance<String> api_token;
@ConfigProperty(name = "okta.api.token") Instance<String> apiToken;

// private static final String REALM = "AGR";
private static final String AUTHENTICATION_SCHEME = "Bearer";
Expand All @@ -86,8 +75,8 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
// Testing)
// if okta_auth is on and we have okta_creds validate(token), else fail

if (okta_auth.get()) {
if (!okta_url.get().equals("\"\"") && !client_id.get().equals("\"\"") && !client_secret.get().equals("\"\"") && !api_token.get().equals("\"\"")) {
if (oktaAuth.get()) {
if (!oktaUrl.get().equals("\"\"") && !clientId.get().equals("\"\"") && !clientSecret.get().equals("\"\"") && !apiToken.get().equals("\"\"")) {

String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);

Expand All @@ -97,20 +86,20 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
String token = authorizationHeader.substring(AUTHENTICATION_SCHEME.length()).trim();

Person person = null;

try {
Jwt jsonWebToken = authenticationService.verifyToken(token);

if(person == null) {
if (person == null) {
person = validateUserToken(jsonWebToken);
}
if(person == null) {
if (person == null) {
person = validateAdminToken(jsonWebToken);
}
} catch (JwtVerificationException e) {
person = personService.findPersonByApiToken(token);
}

if (person != null) {
userAuthenticatedEvent.fire(person);
} else {
Expand Down Expand Up @@ -152,12 +141,12 @@ private void loginDevUser() {

// Check Okta(token), Check DB ApiToken(token), else return null
private Person validateUserToken(Jwt jsonWebToken) {

String oktaUserId = (String) jsonWebToken.getClaims().get("uid"); // User Id
if(oktaUserId != null && oktaUserId.length() > 0) {

if (oktaUserId != null && oktaUserId.length() > 0) {
String oktaEmail = (String) jsonWebToken.getClaims().get("sub"); // Subject Id

Person authenticatedUser = personService.findPersonByOktaEmail(oktaEmail);

if (authenticatedUser != null) {
Expand Down Expand Up @@ -186,27 +175,27 @@ private Person validateUserToken(Jwt jsonWebToken) {
return person;
}
}

return null;
}

private Person validateAdminToken(Jwt jsonWebToken) {

String oktaClientId = (String) jsonWebToken.getClaims().get("cid"); // Client Id
if(oktaClientId != null && oktaClientId.length() > 0) {

if (oktaClientId != null && oktaClientId.length() > 0) {

Person authenticatedUser = personService.findPersonByOktaId(oktaClientId);

if (authenticatedUser != null) {
return authenticatedUser;
}

Log.info("Making OKTA call to get app info: ");

Application app = getOktaClient(oktaClientId);
if(app != null) {

if (app != null) {
log.debug("OKTA Authentication for Admin user via token");
String adminEmail = "[email protected]";
Person person = new Person();
Expand All @@ -224,14 +213,13 @@ private Person validateAdminToken(Jwt jsonWebToken) {
return null;
}


private User getOktaUser(String oktaId) {
Client client = Clients.builder().setOrgUrl(okta_url.get()).setClientId(client_id.get()).setClientCredentials(new TokenClientCredentials(api_token.get())).build();
Client client = Clients.builder().setOrgUrl(oktaUrl.get()).setClientId(clientId.get()).setClientCredentials(new TokenClientCredentials(apiToken.get())).build();
return client.getUser(oktaId);
}

private Application getOktaClient(String applicationId) {
Client client = Clients.builder().setOrgUrl(okta_url.get()).setClientId(client_id.get()).setClientCredentials(new TokenClientCredentials(api_token.get())).build();
Client client = Clients.builder().setOrgUrl(oktaUrl.get()).setClientId(clientId.get()).setClientCredentials(new TokenClientCredentials(apiToken.get())).build();
return client.getApplication(applicationId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
public class AuthenticationService {

@ConfigProperty(name = "okta.url")
Instance<String> okta_url;
Instance<String> oktaUrl;

private AccessTokenVerifier jwtVerifier;

@PostConstruct
public void init() {
jwtVerifier = JwtVerifiers.accessTokenVerifierBuilder().setIssuer(okta_url.get() + "/oauth2/default").setAudience("api://default").setConnectionTimeout(Duration.ofSeconds(1))
jwtVerifier = JwtVerifiers.accessTokenVerifierBuilder().setIssuer(oktaUrl.get() + "/oauth2/default").setAudience("api://default").setConnectionTimeout(Duration.ofSeconds(1))
// .setReadTimeout(Duration.ofSeconds(1))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
@ApplicationPath("/api")
@OpenAPIDefinition(
info = @Info(
description = " <h3> This is the Alliance Curation Java API </h3>" + //
"<h1> !!! Please note: Some Swagger widgets may crash this page when expanded !!! </h1>" + //
"<h1>For flat file of API documentation click on the link below <a href=\"/openapi\"><h1>OpenAPI definition download</h1></a></h1>",
description = " <h3> This is the Alliance Curation Java API </h3>"
+ "<h1> !!! Please note: Some Swagger widgets may crash this page when expanded !!! </h1>"
+ "<h1>For flat file of API documentation click on the link below <a href=\"/openapi\"><h1>OpenAPI definition download</h1></a></h1>",
title = "Alliance of Genome Resources Curation API ",
version = "1.0 Alpha"
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.alliancegenome.curation_api.constants;

public final class EntityFieldConstants {

private EntityFieldConstants() {
// Hidden from view, as it is a utility class
}

public static final String TAXON = "taxon.curie";
public static final String DATA_PROVIDER = "dataProvider.sourceOrganization.abbreviation";
public static final String SECONDARY_DATA_PROVIDER = "secondaryDataProvider.sourceOrganization.abbreviation";
public static final String DA_SUBJECT = "diseaseAnnotationSubject";
public static final String DA_SUBJECT_TAXON = DA_SUBJECT+ "." + TAXON;
public static final String DA_SUBJECT_TAXON = DA_SUBJECT + "." + TAXON;
public static final String PA_SUBJECT = "phenotypeAnnotationSubject";
public static final String PA_SUBJECT_TAXON = PA_SUBJECT+ "." + TAXON;
public static final String PA_SUBJECT_TAXON = PA_SUBJECT + "." + TAXON;
public static final String ALLELE_ASSOCIATION_SUBJECT_DATA_PROVIDER = "alleleAssociationSubject." + DATA_PROVIDER;
public static final String CONSTRUCT_ASSOCIATION_SUBJECT_DATA_PROVIDER = "constructAssociationSubject." + DATA_PROVIDER;

Expand Down
Loading

0 comments on commit cb9d08b

Please sign in to comment.