• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MacProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.jsonwebtoken.impl.crypto.MacProvider的典型用法代码示例。如果您正苦于以下问题:Java MacProvider类的具体用法?Java MacProvider怎么用?Java MacProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MacProvider类属于io.jsonwebtoken.impl.crypto包,在下文中一共展示了MacProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testExpiredToken

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test
public void testExpiredToken() {

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.SECOND, 1);

    Key key = MacProvider.generateKey();

    // new KeyPair("publickey","privatekey")
    String token = TokenUtil.getJWTString("Phil", new String[]{"user"}, 11, calendar.getTime(), key);
    assertNotNull(token);
    try {
        Thread.sleep(1000L * 3L);                 //1000 milliseconds is one second.
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }

    assertEquals("Token should have expired", false, TokenUtil.isValid(token, key));
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:21,代码来源:TokenUtilTest.java


示例2: testNonExpiredToken

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test
public void testNonExpiredToken() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);

    Key key = MacProvider.generateKey();

    // new KeyPair("publickey","privatekey")
    String token = TokenUtil.getJWTString("Phil", new String[]{"user"}, 12, calendar.getTime(), key);
    assertNotNull(token);
    try {
        Thread.sleep(1000L * 2L);                 //1000 milliseconds is one second.
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }

    assertEquals("Token should have been valid", true, TokenUtil.isValid(token, key));
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:20,代码来源:TokenUtilTest.java


示例3: builder

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
public static JwtBuilder builder(KeyEncrypt keyEncrypt) throws KeyOperationException {
    SecretKey secretKey = MacProvider.generateKey(SignatureAlgorithm.HS256);
    byte[] encryptedKey = keyEncrypt.encrypt(secretKey.getEncoded());

    return Jwts.builder()
            .setHeaderParam("kid", DatatypeConverter.printBase64Binary(encryptedKey))
            .signWith(SignatureAlgorithm.HS256, secretKey);
}
 
开发者ID:julianghionoiu,项目名称:kms-jwt,代码行数:9,代码来源:JWTEncoder.java


示例4: testSigninService

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test
	public void testSigninService() {

		UserSigninReq reqObj = new UserSigninReq();
		// reqObj.setAppName("samyh");
		// reqObj.setDeviceType("android");
		// reqObj.setVersion("0.0.1");
//		reqObj.setUserPhone("13900000014");
		reqObj.setPassword("123456789");
		reqObj.setDeviceInfo("XXXXXXXXXXX");

		String jsonReq = JSON.toJSONString(reqObj);

		logger.info("Reuqest json String:" + jsonReq);

		String url = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/user/signin.json").build().toUriString();

		logger.info("Request URL:" + url);

		Key key = MacProvider.generateKey();
		String s = createJWT(key, jsonReq);
		logger.info("jwt:" + s);

		String str = decodeJWT(key, s);
		logger.info("jwt:" + str);

		MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
		params.add("jsonReq", jsonReq);
		String resp = restTemplate.postForObject(url, params, String.class);

		logger.info("ResponseBody:" + resp);

		assertEquals(jsonReq, str);
	}
 
开发者ID:booleguo,项目名称:sam-elle,代码行数:35,代码来源:UserSigninTest.java


示例5: Application

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
public Application() {
        this(new BookDao(), new UserDao(), MacProvider.generateKey());

        User user = new User();
        user.setUsername("ironman");
        user.setEmail("[email protected]");
        user.setRoles(new String[]{"user", "admin"});
        user.setHashedPassword("password");
        this.getUserDao().addUser(user);

        Book book1 = new Book();
//        book1.setId("1");
        book1.setTitle("The Sharp Sliver");
        book1.setAuthor("Clementine Green");
        book1.setIsbn("1234");
        book1.setPublished(new Date());

        Book book2 = new Book();
//        book2.setId("2");
        book2.setTitle("Edge of Darkness");
        book2.setAuthor("Francisco Fry");
        book2.setIsbn("1234");
        book2.setPublished(new Date());

        this.getBookDao().addBook(book1);
        // books.put(book1.getId(), book1);
        this.getBookDao().addBook(book2);
        // books.put(book2.getId(), book2);
    }
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:30,代码来源:Application.java


示例6: configure

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
protected javax.ws.rs.core.Application configure() {
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    final BookDao bookDao = new BookDao();
    final UserDao userDao = new UserDao();
    userDao.addUser(AdminUser);
    userDao.addUser(NormalUser);
    book1Id = bookDao.addBook(book1).getId();
    book2Id = bookDao.addBook(book2).getId();
    final Key key = MacProvider.generateKey();
    return new com.sample.Application(bookDao, userDao, key);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:13,代码来源:BookResourceTest.java


示例7: configure

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
protected javax.ws.rs.core.Application configure() {
    userDao = new UserDao();
    bookDao = new BookDao();
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    final Key key = MacProvider.generateKey();
    User user = userDao.addUser(buildUser(2L, "bob", "[email protected]", new String[]{"user"}, "aPassW0rd"));
    return new Application(bookDao, userDao, key);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:10,代码来源:AuthenticationResourceTest.java


示例8: testGetJWTString_invalidUserName

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void testGetJWTString_invalidUserName() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = null;
    String[] roles = new String[]{"user"};
    int version = 0;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    TokenUtil.getJWTString(username, roles, version, expires, key);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:13,代码来源:TokenUtilTest.java


示例9: testGetJWTString_invalidRoles

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void testGetJWTString_invalidRoles() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = null;
    int version = 0;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    TokenUtil.getJWTString(username, roles, version, expires, key);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:13,代码来源:TokenUtilTest.java


示例10: testGetJWTString_invalidExpires

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test(expected = NullPointerException.class)
public void testGetJWTString_invalidExpires() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 0;
    Date expires = null;
    Key key = MacProvider.generateKey();
    TokenUtil.getJWTString(username, roles, version, expires, key);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:13,代码来源:TokenUtilTest.java


示例11: testGetVersionGood

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test
public void testGetVersionGood() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    int version1 = TokenUtil.getVersion(jwtString, key);
    assertEquals(version, version1);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java


示例12: testGetVersionBad

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test
public void testGetVersionBad() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    int version1 = TokenUtil.getVersion(jwtString, MacProvider.generateKey());
    assertEquals(-1, version1);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java


示例13: testGetRolesGood

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test
public void testGetRolesGood() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    String[] roles1 = TokenUtil.getRoles(jwtString, key);
    assertEquals(Arrays.toString(roles), Arrays.toString(roles1));
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java


示例14: testGetRolesBad

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test
public void testGetRolesBad() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    String[] roles1 = TokenUtil.getRoles(jwtString, MacProvider.generateKey());
    assertEquals(Arrays.toString(new String[]{}), Arrays.toString(roles1));
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java


示例15: testGetNamesGood

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test
public void testGetNamesGood() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    String username1 = TokenUtil.getName(jwtString, key);
    assertEquals(username, username1);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java


示例16: testGetNamesBad

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Test
public void testGetNamesBad() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.MINUTE, 15);
    String username = "Bob";
    String[] roles = new String[]{"user"};
    int version = 3;
    Date expires = calendar.getTime();
    Key key = MacProvider.generateKey();
    String jwtString = TokenUtil.getJWTString(username, roles, version, expires, key);
    String username1 = TokenUtil.getName(jwtString, MacProvider.generateKey());
    assertNull(username1);
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:15,代码来源:TokenUtilTest.java


示例17: createJsonWebToken

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
public static String createJsonWebToken(String subject, Date expiration, Collection<String> permissions) {
  Key key = MacProvider.generateKey();
  userToKeyMap.put(subject, key);

  String permissionsString = StringUtils.join(permissions, "|");
  Map<String, Object> claims = new HashMap<>();
  claims.put("permissions", permissionsString);
  return Jwts.builder()
          .setClaims(claims)
          .setSubject(subject)
          .setExpiration(expiration)
          .signWith(SignatureAlgorithm.HS512, key)
          .compact();
}
 
开发者ID:OHDSI,项目名称:WebAPI,代码行数:15,代码来源:TokenManager.java


示例18: JwtTokenService

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
public JwtTokenService() {
    key = MacProvider.generateKey();
}
 
开发者ID:enocom,项目名称:json-api-java,代码行数:4,代码来源:JwtTokenService.java


示例19: getKey

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
@Override
public Key getKey() {

    return MacProvider.generateKey();
}
 
开发者ID:previousdeveloper,项目名称:spark-jwt-auth,代码行数:6,代码来源:IKeyGeneratorImpl.java


示例20: startServer

import io.jsonwebtoken.impl.crypto.MacProvider; //导入依赖的package包/类
public static HttpServer startServer() {

        Key key = MacProvider.generateKey();

        final ResourceConfig rc = new Application(new BookDao(), new UserDao(), key);
        return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
    }
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:8,代码来源:Main.java



注:本文中的io.jsonwebtoken.impl.crypto.MacProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BasePostprocessor类代码示例发布时间:2022-05-21
下一篇:
Java Index类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap