查找

问题
· 22 hr 前

VsCode error to create a new class definition.

Anyone else is passing through this issue?

Since last week when I create a new class definition, It is created without the full name into the signature class and I have to put it by myself.

I thougth that should be any configuration about the language patterns, but I didn`t found it.



Thank you all

2 条新评论
讨论 (2)2
登录或注册以继续
文章
· 23 hr 前 阅读大约需 3 分钟

Generando JWT sin acceso a los certificados/keys x509 del sistema

Si queréis generar JWT a partir de un certificado/clave x509, cualquier operación (incluida la lectura) sobre %SYS.X509Credentials requiere el permiso U en el recurso %Admin_Secure. Esto se debe a que %SYS.X509Credentials es persistente y está implementado así para evitar que todos los usuarios tengan acceso a las claves privadas.

Si el recurso %Admin_Secure no está disponible en tiempo de ejecución, podéis usar la siguiente solución alternativa.

Revisándo el código de generación de JWT, descubrí que sólo utiliza %SYS.X509Credentials como fuente de datos en tiempo de ejecución para PrivateKey, PrivateKeyPasswordy Certificate. Como alternativa, podéis usar una implementación no persistente en tiempo de ejecución de la interfaz X.509, exponiendo únicamente estas propiedades.

Si estáis usando interoperabilidad, el certificado/clave privada se puede almacenar en credenciales para un acceso seguro.

Class User.X509 Extends %RegisteredObject
{

Property PrivateKey As %VarString;
Property PrivateKeyPassword As %String;
Property Certificate As %VarString;
Property HasPrivateKey As %Boolean [ InitialExpression = {$$$YES} ];
ClassMethod GetX509() As User.X509
{
    set x509 = ..%New()
    set x509.PrivateKey = ..Key()
    set x509.Certificate = ..Cert()
    quit x509
}

/// Get X509 object from credential.
/// Username is a Cert, Password is a Private Key
ClassMethod GetX509FromCredential(credential) As User.X509
{
    set credentialObj = ##class(Ens.Config.Credentials).%OpenId(credential,,.sc)
    throw:$$$ISERR(sc) ##class(%Exception.StatusException).ThrowIfInterrupt(sc)
    
    set x509 = ..%New()
    set x509.PrivateKey = credentialObj.Password
    set x509.Certificate = credentialObj.Username
    quit x509
}

ClassMethod Key()
{
    q "-----BEGIN RSA PRIVATE KEY-----"_$C(13,10)
    _"YOUR_TEST_KEY"_$C(13,10)
    _"-----END RSA PRIVATE KEY-----"
}

ClassMethod Cert() As %VarString
{
    q "-----BEGIN CERTIFICATE-----"_$C(13,10)
    _"YOUR_TEST_CERT"_$C(13,10)
    _"-----END CERTIFICATE-----"
}

}

Y podéis generar JWT de la siguiente manera:

ClassMethod JWT() As %Status
{
    Set sc = $$$OK
    //Set x509 = ##class(%SYS.X509Credentials).GetByAlias("TempKeyPair")
    Set x509 = ##class(User.X509).GetX509()
    
    Set algorithm ="RS256"
    Set header = {"alg": (algorithm), "typ": "JWT"}
    Set claims= {"Key": "Value" }
    
    #; create JWK
    Set sc = ##class(%Net.JSON.JWK).CreateX509(algorithm,x509,.privateJWK)
    
    If $$$ISERR(sc) {
        Write $SYSTEM.OBJ.DisplayError(sc)
    }

    #; Create JWKS
    Set sc = ##class(%Net.JSON.JWKS).PutJWK(privateJWK,.privateJWKS)
    
    If $$$ISERR(sc) {
        Write $SYSTEM.OBJ.DisplayError(sc)
    }

    Set sc = ##Class(%Net.JSON.JWT).Create(header,,claims,privateJWKS,,.pJWT)
    
    If $$$ISERR(sc) {
        Write $SYSTEM.OBJ.DisplayError(sc)
    }
    
    Write pJWT
	Return sc
}

Alternativamente, podéis usar un objeto dinámico para evitar crear la clase; en ese caso, se vería así:

ClassMethod JWT(credential) As %Status
{
    Set sc = $$$OK
    //Set x509 = ##class(%SYS.X509Credentials).GetByAlias("TempKeyPair")
    Set credentialObj = ##class(Ens.Config.Credentials).%OpenId(credential,,.sc)
    throw:$$$ISERR(sc) ##class(%Exception.StatusException).ThrowIfInterrupt(sc)
    
    Set x509 = {
        "HasPrivateKey": true,
        "PrivateKey": (credentialObj.Password),
        "PrivateKeyPassword":"",
        "Certificate":(credentialObj.Username)
    }

    Set algorithm ="RS256"
    Set header = {"alg": (algorithm), "typ": "JWT"}
    Set claims= {"Key": "Value" }
    
    #; create JWK
    Set sc = ##class(%Net.JSON.JWK).CreateX509(algorithm,x509,.privateJWK)
    
    If $$$ISERR(sc) {
        Write $SYSTEM.OBJ.DisplayError(sc)
    }

    #; Create JWKS
    Set sc = ##class(%Net.JSON.JWKS).PutJWK(privateJWK,.privateJWKS)
    
    If $$$ISERR(sc) {
        Write $SYSTEM.OBJ.DisplayError(sc)
    }

    Set sc = ##Class(%Net.JSON.JWT).Create(header,,claims,privateJWKS,,.pJWT)
    
    If $$$ISERR(sc) {
        Write $SYSTEM.OBJ.DisplayError(sc)
    }
    
    Write pJWT
    Return sc
}
讨论 (0)1
登录或注册以继续
公告
· 一月 15

[Video] ¿Qué es el InterSystems Secure Wallet?

Hola Comunidad!

¿Necesitas un modo de almacenar de forma segura tus passwords, API keys y otras credenciales? Mira como el Secure Wallet en InterSystems IRIS® data platform te puede ayudar:

¿Qué es el InterSystems Secure Wallet?

En este video, verás como utilizar Secure Wallet para almacenar y gestionar, de forma segura, credenciales utilizadas por aplicaciones que se conectan a sistemas o fuentes de datos externas.

讨论 (0)1
登录或注册以继续
公告
· 一月 15

[Video] What Is the InterSystems Secure Wallet?

Hi, Community!

Do you need a way to securely manage your passwords, API keys, and other credentials? See how the Secure Wallet in InterSystems IRIS® data platform can help:

What Is the InterSystems Secure Wallet?

In this video, you will see how to use the Secure Wallet to securely store and manage sensitive credentials used by applications that connect to external systems or data sources.

讨论 (0)1
登录或注册以继续
公告
· 一月 15

InterSystems Community Q&A Annual Recap 2025

Hello and welcome to the 2025 Q&A Recap.
General Stats
755 questions published in 2025
9,819 questions published all time
Most Popular
Most Discussed
2025 Q&A fromInterSystems Developers
讨论 (0)1
登录或注册以继续