//check if the authN data type matches is a good idea, and necessary if there are other fields
//to open/inspect
public static AuthorizationHandler getAuthZHandler() {
        return (AuthenticationData authN) -> {
            try {
                //framework checks for null authN so this shouldn't happen
                if (authN == null) {
                    throw new RuntimeException("Null AuthN data passed in!");
                }
                //check if the authN data type matches is a good idea, and necessary if there are other fields
                //to open/inspect
                if (authN instanceof ClientNameAuthenicationData) {
                    final ClientNameAuthenicationData data = (ClientNameAuthenicationData) authN;
                    //WARNING!!! this logic is for demonstration purposes
                    final String identityLabel = data.getIdentityLabel();
                    return identityLabel.startsWith("accepted.") ?
                            Authorization.ACCEPT : Authorization.REJECT;
                }
                //good idea to log reasons for rejection with the authentication label so testers/users can understand
                System.err.println("AuthN data type is not expected object type!");
                return Authorization.REJECT;
            } catch (Exception e) {
                return Authorization.REJECT;
            }
        };
    }
throw new RuntimeException("Null AuthN data passed in!");
}
//check if the authN data type matches is a good idea, and necessary if there are other fields
//to open/inspect
if (authN instanceof ClientNameAuthenicationData) {
final ClientNameAuthenicationData data = (ClientNameAuthenicationData) authN;
public static AuthorizationHandler getAuthZHandler() {
return (AuthenticationData authN) -> {
try {
//framework checks for null authN so this shouldn't happen
if (authN == null) {
throw new RuntimeException("Null AuthN data passed in!");
}
//check if the authN data type matches is a good idea, and necessary if there are other fields
//to open/inspect
if (authN instanceof ClientNameAuthenicationData) {
final ClientNameAuthenicationData data = (ClientNameAuthenicationData) authN;
//WARNING!!! this logic is for demonstration purposes
final String identityLabel = data.getIdentityLabel();
return identityLabel.startsWith("accepted.") ?
Authorization.ACCEPT : Authorization.REJECT;
}
//good idea to log reasons for rejection with the authentication label so testers/users can understand
System.err.println("AuthN data type is not expected object type!");
return Authorization.REJECT;
public static AuthorizationHandler getAuthZHandler() {
return (AuthenticationData authN) -> {
try {
//framework checks for null authN so this shouldn't happen
if (authN == null) {
throw new RuntimeException("Null AuthN data passed in!");
}
//check if the authN data type matches is a good idea, and necessary if there are other fields
//to open/inspect
if (authN instanceof ClientNameAuthenicationData) {
final ClientNameAuthenicationData data = (ClientNameAuthenicationData) authN;
//WARNING!!! this logic is for demonstration purposes
final String identityLabel = data.getIdentityLabel();
return identityLabel.startsWith("accepted.") ?
Authorization.ACCEPT : Authorization.REJECT;
}
//good idea to log reasons for rejection with the authentication label so testers/users can understand
System.err.println("AuthN data type is not expected object type!");
return Authorization.REJECT;
} catch (Exception e) {
return Authorization.REJECT;
}
};
}