Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(fido2): merge from jans #274

Merged
merged 3 commits into from
Jun 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public abstract class BaseCacheService implements CacheInterface {

private static int DEFAULT_EXPIRATION = 60;
public static int DEFAULT_EXPIRATION = 60;

@Inject
private Logger log;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.gluu.model.custom.script.type.ciba.EndUserNotificationType;
import org.gluu.model.custom.script.type.client.ClientRegistrationType;
import org.gluu.model.custom.script.type.client.DummyClientRegistrationType;
import org.gluu.model.custom.script.type.fido2.DummyFido2ExtensionType;
import org.gluu.model.custom.script.type.fido2.Fido2ExtensionType;
import org.gluu.model.custom.script.type.id.DummyIdGeneratorType;
import org.gluu.model.custom.script.type.id.IdGeneratorType;
import org.gluu.model.custom.script.type.idp.DummyIdpType;
Expand Down Expand Up @@ -89,7 +91,8 @@ public enum CustomScriptType implements AttributeEnum {
REVOKE_TOKEN("revoke_token", "Revoke Token", RevokeTokenType.class, CustomScript.class, "RevokeToken", new DummyRevokeTokenType()),
PERSISTENCE_EXTENSION("persistence_extension", "Persistence Extension", PersistenceType.class, CustomScript.class, "PersistenceExtension", new DummyPeristenceType()),
IDP("idp", "Idp Extension", IdpType.class, CustomScript.class, "IdpExtension", new DummyIdpType()),
UPDATE_TOKEN("update_token", "Update Token", UpdateTokenType.class, CustomScript.class, "UpdateToken", new DummyUpdateTokenType());
UPDATE_TOKEN("update_token", "Update Token", UpdateTokenType.class, CustomScript.class, "UpdateToken", new DummyUpdateTokenType()),
FIDO2_EXTENSION("fido2_extension", "Fido2 Extension", Fido2ExtensionType.class, CustomScript.class, "Fido2Extension", new DummyFido2ExtensionType());

private String value;
private String displayName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* oxCore is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
*
* Copyright (c) 2020, Gluu
*/

package org.gluu.model.custom.script.type.fido2;

import java.util.Map;

import org.gluu.model.SimpleCustomProperty;
import org.gluu.model.custom.script.model.CustomScript;

public class DummyFido2ExtensionType implements Fido2ExtensionType {

@Override
public boolean init(Map<String, SimpleCustomProperty> configurationAttributes) {
return true;
}

@Override
public boolean init(CustomScript customScript, Map<String, SimpleCustomProperty> configurationAttributes) {
return true;
}

@Override
public boolean destroy(Map<String, SimpleCustomProperty> configurationAttributes) {
return true;
}

@Override
public int getApiVersion() {
return 1;
}

@Override
public boolean registerAttestationStart(Object paramAsJsonNode, Object context) {
return false;
}

@Override
public boolean registerAttestationFinish(Object paramAsJsonNode, Object context) {
return false;
}

@Override
public boolean verifyAttestationStart(Object paramAsJsonNode, Object context) {
return false;
}

@Override
public boolean verifyAttestationFinish(Object paramAsJsonNode, Object context) {
return false;
}

@Override
public boolean authenticateAssertionStart(Object paramAsJsonNode, Object context) {
return false;
}

@Override
public boolean authenticateAssertionFinish(Object paramAsJsonNode, Object context) {
return false;
}

@Override
public boolean verifyAssertionStart(Object paramAsJsonNode, Object context) {
return false;
}

@Override
public boolean verifyAssertionFinish(Object paramAsJsonNode, Object context) {
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* oxCore is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
*
* Copyright (c) 2020, Gluu
*/

package org.gluu.model.custom.script.type.fido2;

import org.gluu.model.custom.script.type.BaseExternalType;

public interface Fido2ExtensionType extends BaseExternalType {

boolean registerAttestationStart(Object paramAsJsonNode, Object context);
boolean registerAttestationFinish(Object paramAsJsonNode, Object context);

boolean verifyAttestationStart(Object paramAsJsonNode, Object context);
boolean verifyAttestationFinish(Object paramAsJsonNode, Object context);

boolean authenticateAssertionStart(Object paramAsJsonNode, Object context);
boolean authenticateAssertionFinish(Object paramAsJsonNode, Object context);

boolean verifyAssertionStart(Object paramAsJsonNode, Object context);
boolean verifyAssertionFinish(Object paramAsJsonNode, Object context);
}
15 changes: 15 additions & 0 deletions doc/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.gluu</groupId>
<artifactId>oxcore</artifactId>
<version>4.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>gluu-doc</artifactId>
<packaging>jar</packaging>
<name>gluu-doc</name>


</project>
16 changes: 16 additions & 0 deletions doc/src/main/java/org/gluu/doc/annotation/DocFeatureFlag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.gluu.doc.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface DocFeatureFlag {
String description();

boolean isRequired() default false;

String defaultValue();
}
112 changes: 112 additions & 0 deletions doc/src/main/java/org/gluu/doc/annotation/DocFeatureFlagProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.gluu.doc.annotation;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedOptions;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@SupportedAnnotationTypes("org.gluu.doc.annotation.DocFeatureFlag")
@SupportedOptions({"module"})
public class DocFeatureFlagProcessor extends AbstractProcessor {

String moduleName;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) {

moduleName = processingEnv.getOptions().get("module");

for (TypeElement annotation : annotations) {
Set<? extends Element> annotatedElements = env.getElementsAnnotatedWith(annotation);

// sort alphabetically
List<? extends Element> sortedElements = annotatedElements.stream()
.sorted((prop1, prop2)->prop1.getSimpleName().toString().toLowerCase().compareTo(prop2.getSimpleName().toString().toLowerCase()))
.collect(Collectors.toList());

StringBuilder docContents = new StringBuilder();
StringBuilder tableContents = new StringBuilder();
StringBuilder detailsContent = new StringBuilder();

// prepare document header
prepareDocTagsAndTableHeader(docContents, tableContents);

// for each feature flag add a row in table and add content for the details section
for (Element element : sortedElements)
{
DocFeatureFlag elementAnnotation = element.getAnnotation(DocFeatureFlag.class);
addToTable(tableContents, element, elementAnnotation);
addToDetails(detailsContent, element, elementAnnotation);
}
tableContents.append("\n\n");
createAndWriteDoc(docContents.append((tableContents.append(detailsContent.toString()))));

}
return false;
}

private void prepareDocTagsAndTableHeader(StringBuilder docContents, StringBuilder tableContents) {
// add tags
docContents.append("---\n")
.append("tags:\n")
.append("- administration\n")
.append("- reference\n")
.append("- json\n")
.append("- feature-flags\n")
.append("---\n")
.append("\n")
.append("# "+moduleName+" Feature Flags") // add doc header
.append("\n")
.append("\n");

tableContents.append("| Feature Flag Name ") // prepare table header
.append("| Description ")
.append("| | ")
.append("\n")
.append("|-----|-----|-----|")
.append("\n");
}

private void createAndWriteDoc(StringBuilder docContent) {

FileObject docFile = null;
try{
docFile = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", moduleName.toLowerCase().replaceAll("\\s", "")+"-feature-flags.md");
}
catch (IOException ioe){
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, this.getClass().getName()+": Error occurred while creating annotation documentation file");
}
if(docFile!=null){
try(PrintWriter docWriter = new PrintWriter(docFile.openWriter());) {
docWriter.write(docContent.toString());
docWriter.flush();
} catch (IOException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, this.getClass().getName()+": Error occurred while writing annotation documentation file");
}
}
}

private static void addToDetails(StringBuilder propDetails, Element jansElement, DocFeatureFlag featureFlagAnnotation) {
propDetails.append("### "+ jansElement.getSimpleName()+"\n\n");
propDetails.append("- Description: "+ featureFlagAnnotation.description()+"\n\n");
propDetails.append("- Required: "+ (featureFlagAnnotation.isRequired()?"Yes":"No")+"\n\n");
propDetails.append("- Default value: "+ featureFlagAnnotation.defaultValue()+"\n\n");
propDetails.append("\n");
}

private static void addToTable(StringBuilder propTable, Element jansElement, DocFeatureFlag featureFlagAnnotation) {
propTable.append("| "+ jansElement.getSimpleName()+" ");
propTable.append("| "+ featureFlagAnnotation.description()+" ");
propTable.append("| [Details](#"+jansElement.getSimpleName().toString().toLowerCase()+") |");
propTable.append("\n");
}
}
16 changes: 16 additions & 0 deletions doc/src/main/java/org/gluu/doc/annotation/DocProperty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.gluu.doc.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface DocProperty {
String description() default "None";

boolean isRequired() default false;

String defaultValue() default "None";
}
Loading