Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SOA & JWT

HaniYSNov 26 2018 — edited Dec 10 2018

Hi

I use SOA 12.2.1, in my scenario i need to generate many rest json web service throw oracle soa (i am not using osb), in my case i need to pass jwt token (http_jwt_token_service_policy) with any web service that i call, i add this policy to my rest web service as display in screen below. I generate java class to generate (code below) and then i use the out put token to test the web service, but every time return Unauthorized.

What i need to know is that correct to generate my own java class to generate jwt token? if not how can i create the token, and if yes how i fix Unauthorized call web service (in other way how soa know if token valid or not).

Many thanks

Sketch.png

public static String jwtCreate(String username, int systemId, String userRole,

                                 String secretKey) throws Exception {

    try {

        String result = null;

        JwtToken jwtToken = new JwtToken();

        //Fill in all the parameters- algorithm, issuer, expiry time, other claims etc

        jwtToken.setAlgorithm(JwtToken.SIGN\_ALGORITHM.HS512.toString());

        jwtToken.setType(JwtToken.JWT);

        jwtToken.setClaimParameter("username", username);

        jwtToken.setClaimParameter("systemId", systemId);

        jwtToken.setClaimParameter("userRole", userRole);

        long nowMillis = System.currentTimeMillis();

        Date now = new Date(nowMillis);

        jwtToken.setIssueTime(now);

        // expiry = 8 \* 60 minutes

        jwtToken.setExpiryTime(new Date(nowMillis + (8 \* 60) \* 60 \* 1000));

        // Get the private key and sign the token with a secret key or a private key

        result = jwtToken.signAndSerialize(secretKey.getBytes());

        return result;

    } catch (Exception e) {

        return "";

    }

}
This post has been answered by HaniYS on Dec 10 2018
Jump to Answer
Comments
Post Details
Added on Nov 26 2018
25 comments
1,593 views