本文整理匯總了Java中com.auth0.jwt.JWTSigner.Options類的典型用法代碼示例。如果您正苦於以下問題:Java Options類的具體用法?Java Options怎麽用?Java Options使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Options類屬於com.auth0.jwt.JWTSigner包,在下文中一共展示了Options類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sign
import com.auth0.jwt.JWTSigner.Options; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public OAuth2IdToken sign(Map<String, ?> claims, Options options) {
final String token = signer.sign((Map<String,Object>) claims, options);
return new OAuth2IdToken(token);
}
示例2: login
import com.auth0.jwt.JWTSigner.Options; //導入依賴的package包/類
@RequestMapping(value = "", method = RequestMethod.POST)
public Map<String, Object> login(@RequestBody User u) {
String username = u.getUsername();
String password = u.getPassword();
if (username == null) {
throw new NullPointerException("用戶名或密碼錯誤!");
}
User user = userService.findByName(username);
if (user == null) {
throw new UnknownAccountException("該用戶不存在!");// 沒找到帳號
}
if (Boolean.TRUE.equals(user.getLocked())) {
throw new LockedAccountException("賬號已被鎖定!"); // 帳號鎖定
}
if (!userService.passwordsMatch(user, password)) {
throw new IncorrectCredentialsException("用戶名或密碼錯誤!");
}
JWTSigner signer = new JWTSigner(secret);
Options options = new Options();
// 7 * 24 * 60 * 60 = 604800
options.setExpirySeconds(604800);
Map<String, Object> claims = new HashMap<String, Object>();
RolePermission rolePermission = user.new RolePermission();
claims.put("perms", rolePermission.getPermissionSet());
claims.put("iss", user.getUsername());
String token = signer.sign(claims, options);
Map<String, Object> map = new HashMap<String, Object>();
map.put("access_token", token);
Map<String, Object> userMap = new HashMap<String, Object>();
userMap.put("id", user.getId());
userMap.put("username", user.getUsername());
userMap.put("perms", rolePermission.getPermissionSet());
userMap.put("roles", rolePermission.getRoleSet());
map.put("user", userMap);
return map;
}