Search in sources :

Example 11 with AccessToken

use of org.craftercms.profile.api.AccessToken in project profile by craftercms.

the class AccessTokenController method getAccessToken.

@RequestMapping(value = URL_GET_ACCESS_TOKEN, method = RequestMethod.GET)
@ResponseBody
public AccessToken getAccessToken(@PathVariable(PATH_VAR_ID) String id) throws ProfileException {
    checkIfAllowed(id, Action.GET_PROFILE);
    AccessToken token = accessTokenService.getToken(id);
    if (token != null) {
        return token;
    } else {
        throw new ResourceNotFoundException("No access token found with ID '" + id + "'");
    }
}
Also used : AccessToken(org.craftercms.profile.api.AccessToken) ResourceNotFoundException(org.craftercms.profile.management.exceptions.ResourceNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with AccessToken

use of org.craftercms.profile.api.AccessToken in project profile by craftercms.

the class AccessTokenServiceImplTest method testGetToken.

@Test
public void testGetToken() throws Exception {
    AccessToken expected = getNormalToken();
    AccessToken actual = accessTokenService.getToken(TOKEN_ID);
    assertNotNull(actual);
    assertEquals(expected.getId(), actual.getId());
    assertEquals(expected.getApplication(), actual.getApplication());
    assertEquals(expected.isMaster(), actual.isMaster());
    assertEquals(expected.getTenantPermissions(), actual.getTenantPermissions());
    assertEquals(expected.getExpiresOn(), actual.getExpiresOn());
    verify(accessTokenRepository).findByStringId(TOKEN_ID);
}
Also used : AccessToken(org.craftercms.profile.api.AccessToken) Test(org.junit.Test)

Example 13 with AccessToken

use of org.craftercms.profile.api.AccessToken in project profile by craftercms.

the class AccessTokenServiceImplTest method getNormalToken.

private AccessToken getNormalToken() {
    TenantPermission permission = new TenantPermission();
    permission.allowAny();
    AccessToken token = new AccessToken();
    token.setId(TOKEN_ID);
    token.setApplication(APPLICATION);
    token.setMaster(true);
    token.setTenantPermissions(Arrays.asList(permission));
    token.setExpiresOn(EXPIRES_ON);
    return token;
}
Also used : TenantPermission(org.craftercms.profile.api.TenantPermission) AccessToken(org.craftercms.profile.api.AccessToken)

Aggregations

AccessToken (org.craftercms.profile.api.AccessToken)13 Test (org.junit.Test)6 TenantPermission (org.craftercms.profile.api.TenantPermission)5 Date (java.util.Date)4 SimpleDateFormat (java.text.SimpleDateFormat)1 ResourceNotFoundException (org.craftercms.profile.management.exceptions.ResourceNotFoundException)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1