Search in sources :

Example 6 with PhotoInfo

use of org.springframework.security.oauth.examples.sparklr.PhotoInfo in project spring-security-oauth by spring-projects.

the class PhotoController method getJsonPhotos.

@RequestMapping(value = "/photos", params = "format=json")
@ResponseBody
public ResponseEntity<String> getJsonPhotos(@RequestParam(required = false) String callback) throws Exception {
    Collection<PhotoInfo> photos = photoService.getPhotosForCurrentUser();
    StringBuilder out = new StringBuilder();
    if (callback != null) {
        out.append(callback);
        out.append("( ");
    }
    out.append("{ \"photos\" : [ ");
    Iterator<PhotoInfo> photosIt = photos.iterator();
    while (photosIt.hasNext()) {
        PhotoInfo photo = photosIt.next();
        out.append(String.format("{ \"id\" : \"%s\" , \"name\" : \"%s\" }", photo.getId(), photo.getName()));
        if (photosIt.hasNext()) {
            out.append(" , ");
        }
    }
    out.append("] }");
    if (callback != null) {
        out.append(" )");
    }
    HttpHeaders headers = new HttpHeaders();
    headers.set("Content-Type", "application/json");
    return new ResponseEntity<String>(out.toString(), headers, HttpStatus.OK);
}
Also used : PhotoInfo(org.springframework.security.oauth.examples.sparklr.PhotoInfo) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with PhotoInfo

use of org.springframework.security.oauth.examples.sparklr.PhotoInfo in project spring-security-oauth by spring-projects.

the class WebMvcConfig method createPhoto.

private PhotoInfo createPhoto(String id, String userId) {
    PhotoInfo photo = new PhotoInfo();
    photo.setId(id);
    photo.setName("photo" + id + ".jpg");
    photo.setUserId(userId);
    photo.setResourceURL("/org/springframework/security/oauth/examples/sparklr/impl/resources/" + photo.getName());
    return photo;
}
Also used : PhotoInfo(org.springframework.security.oauth.examples.sparklr.PhotoInfo)

Example 8 with PhotoInfo

use of org.springframework.security.oauth.examples.sparklr.PhotoInfo in project spring-security-oauth by spring-projects.

the class WebMvcConfig method photoServices.

@Bean
public PhotoServiceImpl photoServices() {
    List<PhotoInfo> photos = new ArrayList<PhotoInfo>();
    photos.add(createPhoto("1", "marissa"));
    photos.add(createPhoto("2", "paul"));
    photos.add(createPhoto("3", "marissa"));
    photos.add(createPhoto("4", "paul"));
    photos.add(createPhoto("5", "marissa"));
    photos.add(createPhoto("6", "paul"));
    PhotoServiceImpl photoServices = new PhotoServiceImpl();
    photoServices.setPhotos(photos);
    return photoServices;
}
Also used : PhotoInfo(org.springframework.security.oauth.examples.sparklr.PhotoInfo) ArrayList(java.util.ArrayList) PhotoServiceImpl(org.springframework.security.oauth.examples.sparklr.impl.PhotoServiceImpl) ContentNegotiationManagerFactoryBean(org.springframework.web.accept.ContentNegotiationManagerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

PhotoInfo (org.springframework.security.oauth.examples.sparklr.PhotoInfo)8 HttpHeaders (org.springframework.http.HttpHeaders)4 ResponseEntity (org.springframework.http.ResponseEntity)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ArrayList (java.util.ArrayList)2 Authentication (org.springframework.security.core.Authentication)2 UserDetails (org.springframework.security.core.userdetails.UserDetails)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 IOException (java.io.IOException)1 URL (java.net.URL)1 Bean (org.springframework.context.annotation.Bean)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 PhotoServiceImpl (org.springframework.security.oauth.examples.sparklr.impl.PhotoServiceImpl)1 ContentNegotiationManagerFactoryBean (org.springframework.web.accept.ContentNegotiationManagerFactoryBean)1