Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Reshaped anubis interface to separate signature management from resou…
…rce initialization and to make key rotation possible.
- Loading branch information
1 parent
8d1fc8d
commit 6a0459692922de25cc280e2a0866faa8cb1734e8
Showing
34 changed files
with
684 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2017 The Mifos Initiative. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.mifos.anubis.api.v1.domain; | ||
|
||
import io.mifos.anubis.api.v1.validation.ValidKeyTimestamp; | ||
|
||
import javax.validation.Valid; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author Myrle Krantz | ||
*/ | ||
@SuppressWarnings({"unused", "WeakerAccess"}) | ||
public class ApplicationSignatureSet { | ||
@ValidKeyTimestamp | ||
private String timestamp; | ||
@Valid | ||
private Signature applicationSignature; | ||
@Valid | ||
private Signature identityManagerSignature; | ||
|
||
public ApplicationSignatureSet() { | ||
} | ||
|
||
public ApplicationSignatureSet(String timestamp, Signature applicationSignature, Signature identityManagerSignature) { | ||
this.timestamp = timestamp; | ||
this.applicationSignature = applicationSignature; | ||
this.identityManagerSignature = identityManagerSignature; | ||
} | ||
|
||
public String getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public void setTimestamp(String timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
|
||
public Signature getApplicationSignature() { | ||
return applicationSignature; | ||
} | ||
|
||
public void setApplicationSignature(Signature applicationSignature) { | ||
this.applicationSignature = applicationSignature; | ||
} | ||
|
||
public Signature getIdentityManagerSignature() { | ||
return identityManagerSignature; | ||
} | ||
|
||
public void setIdentityManagerSignature(Signature identityManagerSignature) { | ||
this.identityManagerSignature = identityManagerSignature; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ApplicationSignatureSet that = (ApplicationSignatureSet) o; | ||
return Objects.equals(timestamp, that.timestamp) && | ||
Objects.equals(applicationSignature, that.applicationSignature) && | ||
Objects.equals(identityManagerSignature, that.identityManagerSignature); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(timestamp, applicationSignature, identityManagerSignature); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ApplicationSignatureSet{" + | ||
"timestamp='" + timestamp + '\'' + | ||
", applicationSignature=" + applicationSignature + | ||
", identityManagerSignature=" + identityManagerSignature + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2017 The Mifos Initiative. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.mifos.anubis.api.v1.validation; | ||
|
||
import io.mifos.core.lang.DateConverter; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
import java.time.DateTimeException; | ||
|
||
/** | ||
* @author Myrle Krantz | ||
*/ | ||
@SuppressWarnings("WeakerAccess") | ||
public class CheckKeyTimestamp implements ConstraintValidator<ValidKeyTimestamp, String> { | ||
@Override | ||
public void initialize(ValidKeyTimestamp constraintAnnotation) { } | ||
|
||
@Override | ||
public boolean isValid(final String value, final ConstraintValidatorContext context) { | ||
if (value == null) | ||
return false; | ||
try { | ||
final String timeString = value.replace('_', ':'); | ||
DateConverter.fromIsoString(timeString); | ||
return true; | ||
} | ||
catch (final DateTimeException ignored) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2017 The Mifos Initiative. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.mifos.anubis.api.v1.validation; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
import java.lang.annotation.*; | ||
|
||
/** | ||
* @author Myrle Krantz | ||
*/ | ||
@SuppressWarnings("unused") | ||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Constraint( | ||
validatedBy = {CheckKeyTimestamp.class} | ||
) | ||
public @interface ValidKeyTimestamp { | ||
String message() default "Invalid key timestamp."; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2017 The Mifos Initiative. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.mifos.anubis.api.v1.validation; | ||
|
||
import io.mifos.core.lang.DateConverter; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.time.Clock; | ||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* @author Myrle Krantz | ||
*/ | ||
public class CheckKeyTimestampTest { | ||
@Test | ||
public void testValid() | ||
{ | ||
final CheckKeyTimestamp testSubject = new CheckKeyTimestamp(); | ||
|
||
String utcNowAsString = DateConverter.toIsoString(LocalDateTime.now(Clock.systemUTC())); | ||
Assert.assertTrue(testSubject.isValid(utcNowAsString, null)); | ||
} | ||
|
||
@Test | ||
public void testNull() | ||
{ | ||
final CheckKeyTimestamp testSubject = new CheckKeyTimestamp(); | ||
|
||
Assert.assertFalse(testSubject.isValid(null, null)); | ||
} | ||
|
||
|
||
@Test | ||
public void testGobbledyGook() | ||
{ | ||
final CheckKeyTimestamp testSubject = new CheckKeyTimestamp(); | ||
|
||
Assert.assertFalse(testSubject.isValid("gobbledygook", null)); | ||
} | ||
|
||
@Test | ||
public void testInitializeDoesntThrowException() | ||
{ | ||
final CheckKeyTimestamp testSubject = new CheckKeyTimestamp(); | ||
|
||
testSubject.initialize(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.