Skip to content

Commit

Permalink
Merge branch 'SecureAuthCorp:develop' into RAD-672
Browse files Browse the repository at this point in the history
  • Loading branch information
glacuesta-sa authored Jan 12, 2024
2 parents e48792c + 2f2a248 commit 5c41a80
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 61 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: GitHub Actions
run-name: ${{ github.ref_name }} GitHub Actions 🚀
on: [push, pull_request]
jobs:
Build-Publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository code ⬇️
uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
- name: Setup Gradle 🐘
uses: gradle/gradle-build-action@v2
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Run build with Gradle Wrapper 🏃
run: ./gradlew build -x test
- name: Run tests 🧑‍⚕️
run: ./gradlew test
# Might want to remove this step
- name: Archive production artifacts ⬆️
uses: actions/upload-artifact@v3
with:
name: Artifacts
path: ./build/libs/saRestApi-*.jar
- uses: jfrog/setup-jfrog-cli@v3
env:
JF_URL: ${{ secrets.ARTIFACTORY_URL }}
JF_USER: ${{ secrets.JFROG_USERNAME }}
JF_PASSWORD: ${{ secrets.JFROG_PASSWORD }}
- run: |
# This command adds a new server configuration to the JFrog CLI
- name: Create version for Artifactory
run: |
export BUILD_NAME="saidp-sdk-java"
export BUILD_MODULE="sdk-java"
export BUILD_NUMBER="1"
export VERSION="1.0.3.5"
jf rt upload "./build/libs/saRestApi-*.jar" radius-release-local/saRestApi/$PATH_TO_DIRECTORY --build-name $BUILD_NAME --build-number $BUILD_NUMBER --module $BUILD_MODULE
# This action publishes the build information to Artifactory and deletes older builds
- name: Publish to Artifactory
run: |
jf rt build-publish $BUILD_NAME $BUILD_NUMBER
- run: echo "🍏 This job's status is ${{ job.status }}."
152 changes: 152 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env groovy

// load helpers
library 'jenkins-pipeline-libs'

node('radius-win-java11') {

def gh_cid = scm.getUserRemoteConfigs()[0].getCredentialsId()
def scmUrl = scm.getUserRemoteConfigs()[0].getUrl()
boolean is_master = isMaster()

properties([

// dont keep builds in Jenkins.
buildDiscarder( logRotator(artifactDaysToKeepStr: '',
artifactNumToKeepStr: '3',
daysToKeepStr: '',
numToKeepStr: '30') ),

// set url for diff links to gh
[ $class: 'GithubProjectProperty',
displayName: '',
projectUrlStr: "${getGitHubURL(scmUrl)}" ]
])

try {
stage('Checkout') {
deleteDir()
checkout scm
}

stage('Build') {
def build_cmd = "call gradlew.bat --info --refresh-dependencies clean build"
if (is_master) {
currentBuild.displayName = "#${env.BUILD_NUMBER} - v${getVersion()}"
}
bat build_cmd
}

// invoke any steps specific to the master(release) branch
stage('Tag & Push to Artifactory') {
if (is_master) {
// depends on GIT_USERNAME & GIT_PASSWORD env vars
applyTag(gh_cid, "v${getVersion()}", scmUrl)
}

deployToArtifactory()
}
}
catch (e) {
// set status to failed
currentBuild.result = "FAILED"

// still need to throw so Jenkins will log error
throw e
}
finally {
stage('Archive, Clean & Notify') {
def artifacts = 'build/libs/*.jar'
def recipients = '#radius_notify'
def status = currentBuild.result ?: 'SUCCESS'
def msg = "${env.JOB_NAME} - <${env.BUILD_URL}|#${env.BUILD_NUMBER}" +
(is_master ? " - v${getVersion()}" : "") +
"> - ${status}\n\n${getChangeString()}"

// save artifacts in Jenkins
archiveArtifacts artifacts

//send via library
notifySlack {
buildStatus = status
channel = recipients
message = msg
}

deleteDir()
}
}
}

// fetches version from file
def getVersion(){
def matches = readFile('gradle.properties') =~ /currentVersion *= *["']?([0-9\.\-a-zA-Z]*)/
matches ? matches[0][1] : null
}

// fetch global gradle identifier for Jenkins
// TODO move to global lib
def getGradleId() {
'gradle33'
}

boolean isMaster(){
("${env.BRANCH_NAME}" =~ /^(master|hotfix-.+)$/)
}

boolean isDevelop(){
("${env.BRANCH_NAME}" == "develop")
}

boolean isPR(){
("${env.BRANCH_NAME}" =~ /^(PR-[0-9]+)$/)
}

// deploys artifacts & build info to Artifactory
//TODO - this and archive step should ref same files
//TODO - use build retention to auto-delete old builds on develop only
void deployToArtifactory(){
def server = Artifactory.server 'on-prem-artifactory'
def gradle = Artifactory.newGradleBuild()

def repo = ""
if ( isMaster() ) {
repo = "radius-release-local"
} else if ( (isDevelop() || isPR()) && ( "${getVersion()}" =~ /^(.+SNAPSHOT)$/ ) ) {
repo = "radius-snapshot-local"
} else {
// only deploy for master/hotfix/develop
bat "echo Not a PR or Master, skipping deployment."
return
}

// define where it will be deployed
gradle.deployer server: server, repo: repo

// if com.jfrog.artifactory plugin is already used in script
//gradle.usesPlugin = true

// use the wrapper and not the 'master' jenkins gradle.
gradle.useWrapper = true

//deploy maven descriptors
gradle.deployer.deployMavenDescriptors = true

//use gradle defined in main config
gradle.tool = getGradleId()

def build_info = gradle.run buildFile: 'build.gradle', tasks: 'clean artifactoryPublish'
build_info.number = getVersion()

def uploadSpec = """{
"files": [
{
"pattern": "build/libs/*.jar",
"target": "${repo}/org/secureauth/sarestapi/saRestApi/${getVersion()}/"
}
]
}"""

server.publishBuildInfo(build_info)
server.upload spec: uploadSpec, failNoOp: true
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SAAccess
===========
![Build](https://github.com/SecureAuthCorp/saidp-sdk-java/actions/workflows/github-actions.yml/badge.svg)

SAAccess is a solution that allows access to SecureAuth's REST api. The intention
is to provide a easy and a standard method to to access the SecureAuth Appliance REST
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
currentVersion=1.1.0.8
currentVersion=1.1.0.11
61 changes: 59 additions & 2 deletions src/main/java/org/secureauth/sarestapi/SAAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public IPEval iPEvaluation(String userId, String ipAddress) {
/**
* <p>
* Returns the list of Factors available for the specified user
* Used for both /v1/users/factors and /v2/users/factors
* </p>
*
* @param userId the userid of the identity you wish to have a list of possible
Expand All @@ -263,11 +264,38 @@ public FactorsResponse factorsByUser(String userId) {
}
return null;
}

/**
* <p>
* Returns the list of Factors available for the specified user.
* Used for /v3/users/factors
* Includes Preferred MFA configured/set by the admin/user.
* </p>
*
* @param userId the userid of the identity you wish to have a list of possible
* second factors
* @return {@link FactorsResponse}
*/
public FactorsResponse factorsByUserV3(String userId) {
String ts = getServerTime();
String header = RestApiHeader.getAuthorizationHeader(saAuth, Resource.METHOD_GET,
FactorsQuery.queryFactorsV3(saAuth.getRealm(), userId), ts);

try {
return saExecuter.executeGetRequest(header,
saBaseURL.getApplianceURL() + FactorsQuery.queryFactorsV3(saAuth.getRealm(), userId), ts,
FactorsResponse.class);
} catch (Exception e) {
logger.error(new StringBuilder().append("Exception occurred executing REST query::\n")
.append(e.getMessage()).append("\n").toString(), e);
}
return null;
}

/**
* <p>
* Returns the list of Factors available for the specified user supporting
* special characters
* Returns the list of Factors available for the specified user supporting special characters
* Used for both /v1/users/factors and /v2/users/factors
* </p>
*
* @param userId the userid of the identity you wish to have a list of possible
Expand All @@ -292,6 +320,35 @@ public FactorsResponse factorsByUserQP(String userId) {
}
return null;
}

/**
* <p>
* Returns the list of Factors available for the specified user supporting special characters
* Used for /v3/users/factors
* Includes Preferred MFA configured/set by the admin/user.
* </p>
*
* @param userId the userid of the identity you wish to have a list of possible
* second factors. This method supports special characters for
* userId since it uses QP (Query Params) in order to create the
* request.
* @return {@link FactorsResponse}
*/
public FactorsResponse factorsByUserQPV3(String userId) {
String ts = getServerTime();
String header = RestApiHeader.getAuthorizationHeader(saAuth, Resource.METHOD_GET,
FactorsQuery.queryFactorsQPV3(saAuth.getRealm()), ts);

try {
return saExecuter.executeGetRequest(header,
saBaseURL.getApplianceURL() + FactorsQuery.queryFactorsQPV3(saAuth.getRealm()), userId, ts,
FactorsResponse.class);
} catch (Exception e) {
logger.error(new StringBuilder().append("Exception occurred executing REST query::\n")
.append(e.getMessage()).append("\n").toString(), e);
}
return null;
}

/**
* <p>
Expand Down
82 changes: 39 additions & 43 deletions src/main/java/org/secureauth/sarestapi/data/PreferredMFA.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,48 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class PreferredMFA {

private String factorId;
private String capability;
private String type;
private String mode;
private String available_choosen_mode;

public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getMode() {
return mode;
}
public void setMode(String mode) {
this.mode = mode;
}
public String getAvailable_choosen_mode() {
return available_choosen_mode;
}
public void setAvailable_choosen_mode(String available_choosen_mode) {
this.available_choosen_mode = available_choosen_mode;
}

public String getFactorId() {
return factorId;
}
public void setFactorId(String factorId) {
this.factorId = factorId;
}
public String getCapability() {
return capability;
}
public void setCapability(String capability) {
this.capability = capability;
}

@Override
public String toString(){
return JSONUtil.convertObjectToJSON(this);
}

@JsonProperty("factor_id")
private String factorId;

@JsonProperty("type")
private String type;

@JsonProperty("biometric_type")
private String biometricType;

public String getFactorId() {
return factorId;
}

public void setFactorId(String factorId) {
this.factorId = factorId;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getBiometricType() {
return biometricType;
}

public void setBiometricType(String biometricType) {
this.biometricType = biometricType;
}

@Override
public String toString() {
return JSONUtil.convertObjectToJSON(this);
}

}
Loading

0 comments on commit 5c41a80

Please sign in to comment.