Subversion Repositories SmartDukaan

Rev

Rev 23801 | Rev 24490 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23801 Rev 23846
Line 45... Line 45...
45
			// TODO Auto-generated catch block
45
			// TODO Auto-generated catch block
46
			e.printStackTrace();
46
			e.printStackTrace();
47
		}
47
		}
48
	}
48
	}
49
	
49
	
50
	public static String create(int userId, String[] roleIds){
50
	public static String create(int userId, int retailerId, String[] roleIds){
51
		try{
51
		try{
52
			return createBuilder()
52
			return createBuilder()
53
				.withClaim(USER_ID, userId)
53
				.withClaim(ProfitMandiConstants.USER_ID, userId)
-
 
54
				.withClaim(ProfitMandiConstants.RETAILER_ID, retailerId)
54
				.withArrayClaim(ProfitMandiConstants.ROLE_IDS, roleIds)
55
				.withArrayClaim(ProfitMandiConstants.ROLE_IDS, roleIds)
55
				.sign(ALGORITHM);
56
				.sign(ALGORITHM);
56
		}catch(JWTCreationException jwtCreationException){
57
		}catch(JWTCreationException jwtCreationException){
57
			throw new RuntimeException(ResponseCodeHolder.getMessage("USR_1011"));
58
			throw new RuntimeException(ResponseCodeHolder.getMessage("USR_1011"));
58
		}
59
		}
Line 105... Line 106...
105
		}*/
106
		}*/
106
		Map<String, Claim> claims = decodedJWT.getClaims();
107
		Map<String, Claim> claims = decodedJWT.getClaims();
107
		if(claims.containsKey(USER_ID)){
108
		if(claims.containsKey(USER_ID)){
108
			final Claim userIdclaim = claims.get(USER_ID);
109
			final Claim userIdclaim = claims.get(USER_ID);
109
			int userId = userIdclaim.asInt();
110
			int userId = userIdclaim.asInt();
-
 
111
			final Claim retailerIdclaim = claims.get(ProfitMandiConstants.RETAILER_ID);
-
 
112
			int retailerId = retailerIdclaim.asInt();
110
			final Claim roleIdsClaim = claims.get(ProfitMandiConstants.ROLE_IDS);
113
			final Claim roleIdsClaim = claims.get(ProfitMandiConstants.ROLE_IDS);
111
			if(roleIdsClaim==null || roleIdsClaim.isNull()) {
114
			if(roleIdsClaim==null || roleIdsClaim.isNull()) {
112
				throw new ProfitMandiBusinessException("Token", token, "Invalid Token");
115
				throw new ProfitMandiBusinessException("Token", token, "Invalid Token");
113
			}
116
			}
114
			final UserInfo userInfo = new UserInfo(userId, new HashSet<>(Arrays.asList(roleIdsClaim.asArray(Integer.class))), null);
117
			final UserInfo userInfo = new UserInfo(userId, retailerId, new HashSet<>(Arrays.asList(roleIdsClaim.asArray(Integer.class))), null);
115
			return userInfo;
118
			return userInfo;
116
		}else if(claims.containsKey(EMAIL)){
119
		}else if(claims.containsKey(EMAIL)){
117
			final Claim emailClaim = claims.get("email");
120
			final Claim emailClaim = claims.get("email");
118
			final UserInfo userInfo = new UserInfo(-1, null, emailClaim.asString());
121
			final UserInfo userInfo = new UserInfo(-1, -1, null, emailClaim.asString());
119
			return userInfo;
122
			return userInfo;
120
		} else {
123
		} else {
121
			throw new ProfitMandiBusinessException(ProfitMandiConstants.TOKEN, token, "USR_1008");
124
			throw new ProfitMandiBusinessException(ProfitMandiConstants.TOKEN, token, "USR_1008");
122
		}
125
		}
123
	}
126
	}