Java Code Examples for org.keycloak.util.JsonSerialization#writeValueAsBytes()

The following examples show how to use org.keycloak.util.JsonSerialization#writeValueAsBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RSAVerifierTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void testSpeed() throws Exception
{
    // Took 44 seconds with 50000 iterations
   byte[] tokenBytes = JsonSerialization.writeValueAsBytes(token);

   long start = System.currentTimeMillis();
   int count = 50000;
   for (int i = 0; i < count; i++)
   {
       String encoded = new JWSBuilder()
               .content(tokenBytes)
               .rsa256(idpPair.getPrivate());

       verifySkeletonKeyToken(encoded);

   }
   long end = System.currentTimeMillis() - start;
   System.out.println("took: " + end);
}
 
Example 2
Source File: DefaultDataMarshaller.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public String serialize(Object value) {
    if (value instanceof String) {
        return (String) value;
    } else {
        try {
            byte[] bytes = JsonSerialization.writeValueAsBytes(value);
            return Base64Url.encode(bytes);
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
}
 
Example 3
Source File: SerializedBrokeredIdentityContext.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@JsonIgnore
@Override
public void setAttribute(String key, List<String> value) {
    try {
        byte[] listBytes = JsonSerialization.writeValueAsBytes(value);
        String listStr = Base64Url.encode(listBytes);
        ContextDataEntry ctxEntry = ContextDataEntry.create(List.class.getName(), listStr);
        this.contextData.put(Constants.USER_ATTRIBUTES_PREFIX + key, ctxEntry);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
Example 4
Source File: JWSBuilder.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public EncodingBuilder jsonContent(Object object) {
    try {
        this.contentBytes = JsonSerialization.writeValueAsBytes(object);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return new EncodingBuilder();
}
 
Example 5
Source File: JWE.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public String getBase64Header() throws IOException {
    if (base64Header == null && header != null) {
        byte[] contentBytes = JsonSerialization.writeValueAsBytes(header);
        base64Header = Base64Url.encode(contentBytes);
    }
    return base64Header;
}