Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env groovy

openshift.withCluster() {

podTemplate(
inheritFrom: 'maven',
cloud: 'openshift', //cloud must be openshift
envVars: [ //This fixes the error with en_US.utf8 not being found
envVar(key:"LC_ALL", value:"C.utf8")
],
volumes: [ //mount the settings.xml
secretVolume(mountPath: '/etc/m2', secretName: 'maven-settings')
]) {

try {
//GO to a node with maven and settings.xml
node(POD_LABEL) {
//Do not use concurrent builds
properties([disableConcurrentBuilds()])

def mvnCmd = "mvn -s /etc/m2/settings.xml --batch-mode"

stage('checkout') {
checkout scm
}

stage('Mvn clean package') {
sh "${mvnCmd} -PallTests clean package"
}

stage('Analyze build results') {
recordIssues aggregatingResults: true,
tools: [java(),
javaDoc(),
mavenConsole(),
taskScanner(highTags:'FIXME', normalTags:'TODO', includePattern: '**/*.java', excludePattern: 'target/**/*')]
}

stage('Push to Nexus (if Master)') {
echo "Branch name ${env.BRANCH_NAME}"
if (env.BRANCH_NAME == 'master') {
sh "${mvnCmd} clean deploy -DskipTests=true"
} else {
echo "Branch ${env.BRANCH_NAME} is not master, so no mvn deploy"
}
}
}
} catch (e) {
currentBuild.result = 'FAILURE'
throw e
} finally {
configFileProvider([configFile(fileId: "notifier", variable: 'notifier')]) {
def notifier = load notifier
notifier.notifyInCaseOfFailureOrImprovement(true, "#playground")
}
}
}
}

1 change: 1 addition & 0 deletions bitrepository-alarm-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<tarLongFileMode>posix</tarLongFileMode>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void alarmExceptionTest() throws Exception {
Assert.assertEquals(model.getFileID(), defaultFileID);

addStep("Test the MaxCount", "Should be able to put a new one in and extract it again.");
Integer defaultMaxCount = new Integer(192837456);
Integer defaultMaxCount = 192837456;
model.setMaxCount(defaultMaxCount);
Assert.assertEquals(model.getMaxCount(), defaultMaxCount);

Expand Down
1 change: 1 addition & 0 deletions bitrepository-audit-trail-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<tarLongFileMode>posix</tarLongFileMode>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
Expand Down
6 changes: 3 additions & 3 deletions bitrepository-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ import org.bitrepository.protocol.messagebus.MessageBus;
import org.bitrepository.protocol.messagebus.MessageBusManager;
import org.bitrepository.protocol.security.BasicMessageAuthenticator;
import org.bitrepository.protocol.security.BasicMessageSigner;
import org.bitrepository.protocol.security.BasicOperationAuthorizor;
import org.bitrepository.protocol.security.BasicOperationAuthorizer;
import org.bitrepository.protocol.security.SecurityManager;
import org.bitrepository.protocol.security.BasicSecurityManager;
import org.bitrepository.protocol.security.MessageAuthenticator;
import org.bitrepository.protocol.security.MessageSigner;
import org.bitrepository.protocol.security.OperationAuthorizor;
import org.bitrepository.protocol.security.OperationAuthorizer;
import org.bitrepository.protocol.security.PermissionStore;

public class BitrepositoryClientExample {
Expand Down Expand Up @@ -226,7 +226,7 @@ public class BitrepositoryClientExample {
PermissionStore permissionStore = new PermissionStore();
MessageAuthenticator authenticator = new BasicMessageAuthenticator(permissionStore);
MessageSigner signer = new BasicMessageSigner();
OperationAuthorizor authorizer = new BasicOperationAuthorizor(permissionStore);
OperationAuthorizer authorizer = new BasicOperationAuthorizer(permissionStore);
SecurityManager securityManager = new BasicSecurityManager(
settings.getRepositorySettings(), certificateFile, authenticator,
signer, authorizer, permissionStore, settings.getComponentID());
Expand Down
1 change: 1 addition & 0 deletions bitrepository-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<tarLongFileMode>posix</tarLongFileMode>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private ComponentIDFactory createClientIDFactory(String clientIDFactoryClass) {
return new DefaultCommandlineComponentID();
} else {
try {
return (ComponentIDFactory)Class.forName(clientIDFactoryClass).newInstance();
return (ComponentIDFactory)Class.forName(clientIDFactoryClass).getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException("Unable to instantiate ClientIDFactory " +
clientIDFactoryClass +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public IdentifyPillarsForPutFile(PutFileConversationContext context) {
}

/**
* Extends the default behaviour with a idempotent aspects. This assumes that the put to a pillar is successful if
* Extends the default behaviour with an idempotent aspect. This assumes that the put to a pillar is successful if
* the same file already exists.
*
* The existence of a different file on the other hand is a fatal problem.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ public void testPaging() throws Exception {
Date timestamp3 = new Date();
Date timestamp2 = new Date(timestamp3.getTime() - 100);
Date timestamp1 = new Date(timestamp3.getTime() - 1000);
ContributorQuery query1 = new ContributorQuery(PILLAR1_ID, timestamp1, timestamp2, new Integer(1));
ContributorQuery query2 = new ContributorQuery(PILLAR2_ID, timestamp2, timestamp3, new Integer(2));
ContributorQuery query1 = new ContributorQuery(PILLAR1_ID, timestamp1, timestamp2, 1);
ContributorQuery query2 = new ContributorQuery(PILLAR2_ID, timestamp2, timestamp3, 2);
getChecksumsClient.getChecksums(collectionID, new ContributorQuery[]{query1, query2}, null, null, null,
testEventHandler, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ public void testPaging() throws Exception {
Date timestamp3 = new Date();
Date timestamp2 = new Date(timestamp3.getTime() - 100);
Date timestamp1 = new Date(timestamp3.getTime() - 1000);
ContributorQuery query1 = new ContributorQuery(PILLAR1_ID, timestamp1, timestamp2, new Integer(1));
ContributorQuery query2 = new ContributorQuery(PILLAR2_ID, timestamp2, timestamp3, new Integer(2));
ContributorQuery query1 = new ContributorQuery(PILLAR1_ID, timestamp1, timestamp2, 1);
ContributorQuery query2 = new ContributorQuery(PILLAR2_ID, timestamp2, timestamp3, 2);
client.getFileIDs(collectionID, new ContributorQuery[]{query1, query2}, null, null, testEventHandler);

IdentifyPillarsForGetFileIDsRequest receivedIdentifyRequestMessage = collectionReceiver.waitForMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public XMLFileSettingsLoader(String pathToSettingsFiles) {
public <T> T loadSettings(Class<T> settingsClass) {
StringBuilder fileLocationBuilder = new StringBuilder();
if (pathToSettingsFiles != null && !pathToSettingsFiles.equals("")) {
fileLocationBuilder.append(pathToSettingsFiles + DIRECTORY_SEPERATOR);
fileLocationBuilder.append(pathToSettingsFiles).append(DIRECTORY_SEPERATOR);
}
fileLocationBuilder.append(settingsClass.getSimpleName() + XML_FILE_EXTENSION);
fileLocationBuilder.append(settingsClass.getSimpleName()).append(XML_FILE_EXTENSION);
String fileLocation = fileLocationBuilder.toString();
String schemaLocation = settingsClass.getSimpleName() + XSD_FILE_EXTENSION;
JaxbHelper jaxbHelper = new JaxbHelper(XSD_SCHEMA_DIR, schemaLocation);
Expand All @@ -94,7 +94,7 @@ public <T> T loadSettings(Class<T> settingsClass) {
log.debug("Loading the settings file '" + fileLocation + "'.");
try {
jaxbHelper.validate(configStreamValidate);
return (T) jaxbHelper.loadXml(settingsClass, configStreamLoad);
return jaxbHelper.loadXml(settingsClass, configStreamLoad);
} catch (SAXException e) {
throw new RuntimeException("Unable to validate settings from " +
Thread.currentThread().getContextClassLoader().getResource(fileLocation), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ private ReceiverDestinationIDFactory createReceiverDestinationIDFactory(
return new DefaultReceiverDestinationIDFactory();
} else {
try {
return (ReceiverDestinationIDFactory)Class.forName(receiverDestinationIDFactoryClass).newInstance();
return (ReceiverDestinationIDFactory) Class.forName(receiverDestinationIDFactoryClass)
.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException("Unable to instantiate ReceiverDestinationIDFactory " +
receiverDestinationIDFactoryClass +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public BasicMessageAuthenticator(PermissionStore permissionStore) {
public SignerId authenticateMessage(byte[] messageData, byte[] signatureData) throws MessageAuthenticationException {
try {
CMSSignedData s = new CMSSignedData(new CMSProcessableByteArray(messageData), signatureData);
SignerInformation signer = (SignerInformation) s.getSignerInfos().getSigners().iterator().next();
SignerInformation signer = s.getSignerInfos().getSigners().iterator().next();
X509Certificate signingCert = permissionStore.getCertificate(signer.getSID());
SignerInformationVerifier verifier = new JcaSimpleSignerInfoVerifierBuilder().setProvider(
SecurityModuleConstants.BC).build(signingCert);
Expand All @@ -70,9 +70,7 @@ public SignerId authenticateMessage(byte[] messageData, byte[] signatureData) th
return signer.getSID();
} catch (PermissionStoreException e) {
throw new MessageAuthenticationException(e.getMessage(), e);
} catch (CMSException e) {
throw new SecurityException(e.getMessage(), e);
} catch (OperatorCreationException e) {
} catch (CMSException | OperatorCreationException e) {
throw new SecurityException(e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Class to check permissions based on the signer of a MessageRequest and the type of request.
*/
public class BasicOperationAuthorizor implements OperationAuthorizor {
public class BasicOperationAuthorizer implements OperationAuthorizer {

/** Mapper from operation type to needed permission */
private RequestToOperationPermissionMapper requestToPermissionMapper;
Expand All @@ -42,7 +42,7 @@ public class BasicOperationAuthorizor implements OperationAuthorizor {
/**
* @param permissionStore permissionStore which holds the permissions to check against.
*/
public BasicOperationAuthorizor(PermissionStore permissionStore) {
public BasicOperationAuthorizer(PermissionStore permissionStore) {
requestToPermissionMapper = new RequestToOperationPermissionMapper();
this.permissionStore = permissionStore;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class BasicSecurityManager implements SecurityManager {
/** Object to sign messages */
private final MessageSigner signer;
/** Object to authorize operations */
private final OperationAuthorizor authorizer;
private final OperationAuthorizer authorizer;
/** Object storing permissions and certificates */
private final PermissionStore permissionStore;
/** int value to keep track of the next keystore alias */
Expand All @@ -122,7 +122,7 @@ public class BasicSecurityManager implements SecurityManager {
* @param componentID the component ID
*/
public BasicSecurityManager(RepositorySettings repositorySettings, String privateKeyFile, MessageAuthenticator authenticator,
MessageSigner signer, OperationAuthorizor authorizer, PermissionStore permissionStore, String componentID) {
MessageSigner signer, OperationAuthorizer authorizer, PermissionStore permissionStore, String componentID) {
ArgumentValidator.checkNotNull(repositorySettings, "repositorySettings");
ArgumentValidator.checkNotNull(authenticator, "authenticator");
ArgumentValidator.checkNotNull(signer, "signer");
Expand Down Expand Up @@ -185,51 +185,56 @@ public String signMessage(String message) throws MessageSigningException {
public void authorizeCertificateUse(String certificateUser, String messageData, String signature)
throws CertificateUseException {
if(repositorySettings.getProtocolSettings().isRequireOperationAuthorization()) {
byte[] decodeSig = Base64.decode(signature.getBytes(StandardCharsets.UTF_8));
CMSSignedData s;
try {
s = new CMSSignedData(new CMSProcessableByteArray(messageData.getBytes(StandardCharsets.UTF_8)), decodeSig);
} catch (CMSException e) {
throw new SecurityException(e.getMessage(), e);
}

SignerInformation signer = (SignerInformation) s.getSignerInfos().getSigners().iterator().next();
CMSSignedData s = makeSignedData(messageData, signature);

SignerInformation signer = s.getSignerInfos().getSigners().iterator().next();
authorizer.authorizeCertificateUse(certificateUser, signer.getSID());
}
}

@Override
public String getCertificateFingerprint(SignerId signer) throws UnregisteredPermissionException {
return permissionStore.getCertificateFingerprint(signer);
}

/**
* Method to authorize an operation
* Method to authorize an operation
* @param operationType the type of operation that is to be authorized.
* @param messageData the data of the message request.
* @param signature the signature belonging to the message request.
* @throws OperationAuthorizationException in case of failure.
* @throws OperationAuthorizationException in case of failure.
*/
public void authorizeOperation(String operationType, String messageData, String signature, String collectionID)
public void authorizeOperation(String operationType, String messageData, String signature, String collectionID)
throws OperationAuthorizationException {
if(repositorySettings.getProtocolSettings().isRequireOperationAuthorization()) {
byte[] decodeSig = Base64.decode(signature.getBytes(StandardCharsets.UTF_8));
CMSSignedData s;
try {
s = new CMSSignedData(new CMSProcessableByteArray(messageData.getBytes(StandardCharsets.UTF_8)), decodeSig);
} catch (CMSException e) {
throw new SecurityException(e.getMessage(), e);
}

SignerInformation signer = (SignerInformation) s.getSignerInfos().getSigners().iterator().next();
CMSSignedData s = makeSignedData(messageData, signature);

SignerInformation signer = s.getSignerInfos().getSigners().iterator().next();
try {
authorizer.authorizeOperation(operationType, signer.getSID(), collectionID);
authorizer.authorizeOperation(operationType, signer.getSID(), collectionID);
} catch (UnregisteredPermissionException e) {
log.info(e.getMessage());
}
}
}


/**
* Encapsulates the data of a message request and a signature into a CMSSignedData object.
* @param messageData the data of a message request.
* @param signature the signature belonging to the message request.
* @return the signed data.
*/
private CMSSignedData makeSignedData(String messageData, String signature) {
byte[] decodeSig = Base64.decode(signature.getBytes(StandardCharsets.UTF_8));
CMSSignedData signedData;
try {
signedData = new CMSSignedData(new CMSProcessableByteArray(messageData.getBytes(StandardCharsets.UTF_8)), decodeSig);
} catch (CMSException e) {
throw new SecurityException(e.getMessage(), e);
}
return signedData;
}

@Override
public String getCertificateFingerprint(SignerId signer) throws UnregisteredPermissionException {
return permissionStore.getCertificateFingerprint(signer);
}

/**
* Do initialization work
* - Creates keystore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* Class to authorize an operation based on the certificate which has signed the operation request.
*/
public interface OperationAuthorizor {
public interface OperationAuthorizer {

/**
* Authorize an operation based on its signature
Expand All @@ -39,7 +39,7 @@ public interface OperationAuthorizor {
* @throws OperationAuthorizationException if the authorization fails.
* @throws UnregisteredPermissionException if no permissions could be found for the signer
*/
abstract void authorizeOperation(String operationType, SignerId signer, String collectionID)
void authorizeOperation(String operationType, SignerId signer, String collectionID)
throws OperationAuthorizationException, UnregisteredPermissionException;

/**
Expand All @@ -49,6 +49,6 @@ abstract void authorizeOperation(String operationType, SignerId signer, String c
* @throws CertificateUseException in case the message has been signed by the wrong user.
*
*/
abstract void authorizeCertificateUse(String certificateUser, SignerId signer) throws CertificateUseException;
void authorizeCertificateUse(String certificateUser, SignerId signer) throws CertificateUseException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static SecurityManager getSecurityManager(Settings settings, Path compone
PermissionStore permissionStore = new PermissionStore();
MessageAuthenticator authenticator = new BasicMessageAuthenticator(permissionStore);
MessageSigner signer = new BasicMessageSigner();
OperationAuthorizor authorizer = new BasicOperationAuthorizor(permissionStore);
OperationAuthorizer authorizer = new BasicOperationAuthorizer(permissionStore);
return new BasicSecurityManager(settings.getRepositorySettings(), componentCertificate.toString(),
authenticator, signer, authorizer, permissionStore, componentID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public void testUncaughtExceptionHandler() throws Exception {
ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);

//We mock an appender so we can catch the log messages
@SuppressWarnings("unchecked")
final Appender<ILoggingEvent> mockAppender = mock(Appender.class);

//Nessesary for the logback framework, all appenders must have a name
//Necessary for the logback framework, all appenders must have a name
when(mockAppender.getName()).thenReturn("MOCK");
//Add the appender to the root logger
rootLogger.addAppender(mockAppender);
Expand Down
Loading