Subversion Repositories SmartDukaan

Rev

Rev 35272 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35272 Rev 36465
Line 74... Line 74...
74
        } catch (JWTCreationException jwtCreationException) {
74
        } catch (JWTCreationException jwtCreationException) {
75
            throw new RuntimeException(ResponseCodeHolder.getMessage("USR_1011"));
75
            throw new RuntimeException(ResponseCodeHolder.getMessage("USR_1011"));
76
        }
76
        }
77
    }
77
    }
78
 
78
 
-
 
79
    public String createImpersonationToken(String targetEmail, int targetUserId, int targetRetailerId,
-
 
80
                                            String[] targetRoleIds, int authUserId, String authUserEmail) {
-
 
81
        try {
-
 
82
            return createBuilder()
-
 
83
                    .withClaim(ProfitMandiConstants.EMAIL_ID, targetEmail)
-
 
84
                    .withClaim(ProfitMandiConstants.USER_ID, targetUserId)
-
 
85
                    .withClaim(ProfitMandiConstants.RETAILER_ID, targetRetailerId)
-
 
86
                    .withArrayClaim(ProfitMandiConstants.ROLE_IDS, targetRoleIds)
-
 
87
                    .withClaim(ProfitMandiConstants.AUTH_USER_ID, authUserId)
-
 
88
                    .withClaim(ProfitMandiConstants.AUTH_USER_EMAIL, authUserEmail)
-
 
89
                    .withClaim(ProfitMandiConstants.IS_IMPERSONATION, true)
-
 
90
                    .sign(ALGORITHM);
-
 
91
        } catch (JWTCreationException jwtCreationException) {
-
 
92
            throw new RuntimeException(ResponseCodeHolder.getMessage("USR_1011"));
-
 
93
        }
-
 
94
    }
-
 
95
 
79
    public String create(String email) {
96
    public String create(String email) {
80
        try {
97
        try {
81
            return createBuilder().withClaim(EMAIL, email).sign(ALGORITHM);
98
            return createBuilder().withClaim(EMAIL, email).sign(ALGORITHM);
82
        } catch (JWTCreationException jwtCreationException) {
99
        } catch (JWTCreationException jwtCreationException) {
83
            throw new RuntimeException(ResponseCodeHolder.getMessage("USR_1011"));
100
            throw new RuntimeException(ResponseCodeHolder.getMessage("USR_1011"));
Line 141... Line 158...
141
            String emailId = null;
158
            String emailId = null;
142
            if (claims.containsKey(ProfitMandiConstants.EMAIL_ID)) {
159
            if (claims.containsKey(ProfitMandiConstants.EMAIL_ID)) {
143
                emailId = claims.get(ProfitMandiConstants.EMAIL_ID).asString();
160
                emailId = claims.get(ProfitMandiConstants.EMAIL_ID).asString();
144
            }
161
            }
145
            final UserInfo userInfo = new UserInfo(userId, retailerId, new HashSet<>(Arrays.asList(roleIdsClaim.asArray(Integer.class))), emailId);
162
            final UserInfo userInfo = new UserInfo(userId, retailerId, new HashSet<>(Arrays.asList(roleIdsClaim.asArray(Integer.class))), emailId);
-
 
163
            if (claims.containsKey(ProfitMandiConstants.IS_IMPERSONATION)
-
 
164
                    && !claims.get(ProfitMandiConstants.IS_IMPERSONATION).isNull()
-
 
165
                    && claims.get(ProfitMandiConstants.IS_IMPERSONATION).asBoolean()) {
-
 
166
                userInfo.setImpersonation(true);
-
 
167
                userInfo.setAuthUserId(claims.get(ProfitMandiConstants.AUTH_USER_ID).asInt());
-
 
168
                userInfo.setAuthUserEmail(claims.get(ProfitMandiConstants.AUTH_USER_EMAIL).asString());
-
 
169
            }
146
            return userInfo;
170
            return userInfo;
147
        } else if (claims.containsKey(EMAIL)) {
171
        } else if (claims.containsKey(EMAIL)) {
148
            final Claim emailClaim = claims.get("email");
172
            final Claim emailClaim = claims.get("email");
149
            String email = emailClaim.asString();
173
            String email = emailClaim.asString();
150
            int retailerId = -1;
174
            int retailerId = -1;