Search in sources :

Example 16 with InvalidJwtException

use of org.xdi.oxauth.model.exception.InvalidJwtException in project oxAuth by GluuFederation.

the class Jwt method parse.

public static Jwt parse(String encodedJwt) throws InvalidJwtException {
    if (StringUtils.isBlank(encodedJwt)) {
        return null;
    }
    String encodedHeader = null;
    String encodedClaims = null;
    String encodedSignature = null;
    String[] jwtParts = encodedJwt.split("\\.");
    if (jwtParts.length == 2) {
        // Signature Algorithm NONE
        encodedHeader = jwtParts[0];
        encodedClaims = jwtParts[1];
        encodedSignature = "";
    } else if (jwtParts.length == 3) {
        encodedHeader = jwtParts[0];
        encodedClaims = jwtParts[1];
        encodedSignature = jwtParts[2];
    } else {
        throw new InvalidJwtException("Invalid JWT format.");
    }
    Jwt jwt = new Jwt();
    jwt.setHeader(new JwtHeader(encodedHeader));
    jwt.setClaims(new JwtClaims(encodedClaims));
    jwt.setEncodedSignature(encodedSignature);
    jwt.encodedHeader = encodedHeader;
    jwt.encodedClaims = encodedClaims;
    jwt.loaded = true;
    return jwt;
}
Also used : InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException)

Example 17 with InvalidJwtException

use of org.xdi.oxauth.model.exception.InvalidJwtException in project oxAuth by GluuFederation.

the class JwtClaimSet method toJsonObject.

public JSONObject toJsonObject() throws InvalidJwtException {
    JSONObject jsonObject = new JSONObject();
    try {
        for (Map.Entry<String, Object> claim : claims.entrySet()) {
            if (claim.getValue() instanceof Date) {
                Date date = (Date) claim.getValue();
                jsonObject.put(claim.getKey(), date.getTime() / 1000);
            } else if (claim.getValue() instanceof JwtSubClaimObject) {
                JwtSubClaimObject subClaimObject = (JwtSubClaimObject) claim.getValue();
                jsonObject.put(subClaimObject.getName(), subClaimObject.toJsonObject());
            } else {
                jsonObject.put(claim.getKey(), claim.getValue());
            }
        }
    } catch (JSONException e) {
        throw new InvalidJwtException(e);
    } catch (Exception e) {
        throw new InvalidJwtException(e);
    }
    return jsonObject;
}
Also used : InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException) JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException) InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

InvalidJwtException (org.xdi.oxauth.model.exception.InvalidJwtException)17 JSONException (org.codehaus.jettison.json.JSONException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 URISyntaxException (java.net.URISyntaxException)5 Response (javax.ws.rs.core.Response)5 InvalidJweException (org.xdi.oxauth.model.exception.InvalidJweException)5 Jwt (org.xdi.oxauth.model.jwt.Jwt)5 SignatureException (java.security.SignatureException)4 Builder (javax.ws.rs.client.Invocation.Builder)4 JSONObject (org.codehaus.jettison.json.JSONObject)4 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)4 Parameters (org.testng.annotations.Parameters)4 Test (org.testng.annotations.Test)4 BaseTest (org.xdi.oxauth.BaseTest)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)3 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)3 UserInfoRequest (org.xdi.oxauth.client.UserInfoRequest)3 OAuth2AuditLog (org.xdi.oxauth.model.audit.OAuth2AuditLog)3 URI (java.net.URI)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2