use of org.craftercms.profile.api.AccessToken in project profile by craftercms.
the class AccessTokenServiceIT method testCreateAccessToken.
@Test
public void testCreateAccessToken() throws Exception {
AccessToken token = accessTokenService.createToken(getCrafterStudioAccessToken());
try {
assertNotNull(token);
assertNotNull(token.getId());
assertEquals(CRAFTER_STUDIO_APPLICATION, token.getApplication());
assertEquals(true, token.isMaster());
assertEquals(EXPIRES_ON, token.getExpiresOn());
assertEquals(1, token.getTenantPermissions().size());
assertEquals("*", token.getTenantPermissions().get(0).getTenant());
assertEquals(SetUtils.asSet("*"), token.getTenantPermissions().get(0).getAllowedActions());
} finally {
accessTokenService.deleteToken(token.getId());
}
}
use of org.craftercms.profile.api.AccessToken in project profile by craftercms.
the class AccessTokenServiceIT method testDeleteToken.
@Test
public void testDeleteToken() throws Exception {
AccessToken token = accessTokenService.createToken(getCrafterStudioAccessToken());
assertNotNull(token);
accessTokenService.deleteToken(token.getId());
token = accessTokenService.getToken(token.getId());
assertNull(token);
}
use of org.craftercms.profile.api.AccessToken in project profile by craftercms.
the class AccessTokenCheckingInterceptorTest method testPreHandle.
@Test
public void testPreHandle() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter(ProfileConstants.PARAM_ACCESS_TOKEN_ID, NORMAL_TOKEN_ID);
interceptor.preHandle(request, null, null);
AccessToken token = AccessTokenUtils.getAccessToken(request);
TenantPermission permission = new TenantPermission();
permission.allow("*");
assertNotNull(token);
assertEquals(APPLICATION, token.getApplication());
assertTrue(token.isMaster());
assertEquals(Arrays.asList(permission), token.getTenantPermissions());
verify(tokenRepository).findByStringId(NORMAL_TOKEN_ID);
}
use of org.craftercms.profile.api.AccessToken in project profile by craftercms.
the class AccessTokenServiceIT method testGetToken.
@Test
public void testGetToken() throws Exception {
AccessToken token = accessTokenService.getToken(ADMIN_CONSOLE_TOKEN_ID);
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yy");
Date expiresOn = format.parse("01/01/24");
assertNotNull(token);
assertNotNull(token.getId());
assertEquals(ADMIN_CONSOLE_APPLICATION, token.getApplication());
assertEquals(true, token.isMaster());
assertEquals(expiresOn, token.getExpiresOn());
assertEquals(1, token.getTenantPermissions().size());
assertEquals("*", token.getTenantPermissions().get(0).getTenant());
assertEquals(SetUtils.asSet("*"), token.getTenantPermissions().get(0).getAllowedActions());
}
use of org.craftercms.profile.api.AccessToken in project profile by craftercms.
the class AccessTokenCheckingInterceptor method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (includeRequest(request)) {
AccessToken token = getAccessToken(request);
Date now = new Date();
if (token.getExpiresOn() == null || now.before(token.getExpiresOn())) {
AccessTokenUtils.setAccessToken(request, token);
} else {
throw new AccessDeniedException.ExpiredAccessToken(token.getId(), token.getApplication(), token.getExpiresOn());
}
}
return true;
}
Aggregations