Search in sources :

Example 1 with FileSystemResource

use of org.apache.wicket.resource.FileSystemResource in project openmeetings by apache.

the class GroupLogoResourceReference method getResource.

@Override
public IResource getResource() {
    return new FileSystemResource() {

        private static final long serialVersionUID = 1L;

        @Override
        protected String getMimeType() throws IOException {
            return PNG_MIME_TYPE;
        }

        @Override
        protected ResourceResponse newResourceResponse(Attributes attrs) {
            Long id = null;
            boolean allowed = false;
            WebSession ws = WebSession.get();
            if (ws.isSignedIn()) {
                PageParameters params = attrs.getParameters();
                StringValue _id = params.get("id");
                try {
                    id = _id.toOptionalLong();
                } catch (Exception e) {
                // no-op expected
                }
                allowed = id == null || hasAdminLevel(getRights()) || null != groupUserDao.getByGroupAndUser(id, getUserId());
                if (!allowed && ws.getInvitation() != null) {
                    Room r = ws.getInvitation().getRoom() == null ? null : roomDao.get(ws.getInvitation().getRoom().getId());
                    if (r != null && r.getGroups() != null) {
                        for (RoomGroup rg : r.getGroups()) {
                            if (id.equals(rg.getGroup().getId())) {
                                allowed = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (allowed) {
                return createResourceResponse(attrs, getGroupLogo(id, true).toPath());
            } else {
                log.debug("Not authorized");
                ResourceResponse rr = new ResourceResponse();
                rr.setError(HttpServletResponse.SC_FORBIDDEN);
                return rr;
            }
        }
    };
}
Also used : WebSession(org.apache.openmeetings.web.app.WebSession) FileSystemResource(org.apache.wicket.resource.FileSystemResource) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) RoomGroup(org.apache.openmeetings.db.entity.room.RoomGroup) StringValue(org.apache.wicket.util.string.StringValue) Room(org.apache.openmeetings.db.entity.room.Room) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Room (org.apache.openmeetings.db.entity.room.Room)1 RoomGroup (org.apache.openmeetings.db.entity.room.RoomGroup)1 WebSession (org.apache.openmeetings.web.app.WebSession)1 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)1 FileSystemResource (org.apache.wicket.resource.FileSystemResource)1 StringValue (org.apache.wicket.util.string.StringValue)1