use of io.milton.resource.Resource in project lobcder by skoulouzis.
the class ResourceList method _exclude.
public ResourceList _exclude(String... s) {
ResourceList newList = new ResourceList(this);
Iterator<CommonResource> it = newList.iterator();
while (it.hasNext()) {
Resource ct = it.next();
if (contains(s, ct.getName())) {
it.remove();
}
}
return newList;
}
use of io.milton.resource.Resource in project lobcder by skoulouzis.
the class ResourceList method remove.
@Override
public boolean remove(Object o) {
if (o instanceof Resource) {
Resource e = (Resource) o;
map.remove(e.getName());
}
return super.remove(o);
}
use of io.milton.resource.Resource in project lobcder by skoulouzis.
the class UsersAnnotationHandler method findUser.
public AnnoPrincipalResource findUser(AnnoCollectionResource root, String name) {
try {
// a @Authenticate annotation on their ChildOf or ChildrenOf methods
for (CommonResource col : root.getChildren()) {
if (col instanceof AnnoCollectionResource) {
AnnoCollectionResource acr = (AnnoCollectionResource) col;
List<ControllerMethod> availMethods = getMethods(acr.getSource().getClass());
if (!availMethods.isEmpty()) {
Resource r = acr.child(name);
if (r instanceof AnnoPrincipalResource) {
AnnoPrincipalResource apr = (AnnoPrincipalResource) r;
return apr;
}
}
}
}
} catch (NotAuthorizedException e) {
throw new RuntimeException(e);
} catch (BadRequestException e) {
throw new RuntimeException(e);
}
return null;
}
use of io.milton.resource.Resource in project lobcder by skoulouzis.
the class FckQuickUploaderResource method processFileUpload.
private void processFileUpload(FileItem f, Map<String, String> params) throws BadRequestException, NotAuthorizedException {
CollectionResource target = null;
if (wrappedResource == null) {
throw new BadRequestException(this, "collection not found");
}
target = (CollectionResource) wrappedResource.child("uploads");
if (target == null) {
try {
if (wrappedResource instanceof MakeCollectionableResource) {
MakeCollectionableResource mk = (MakeCollectionableResource) wrappedResource;
target = mk.createCollection("uploads");
} else {
throw new BadRequestException(target, "Cant create subfolder");
}
} catch (ConflictException ex) {
throw new RuntimeException(ex);
} catch (NotAuthorizedException ex) {
throw new RuntimeException(ex);
} catch (BadRequestException ex) {
throw new RuntimeException(ex);
}
}
String name = FileUtils.sanitiseName(f.getName());
log.debug("processFileUpload: " + name);
boolean isFirst = true;
String newName = null;
while (target.child(name) != null) {
name = FileUtils.incrementFileName(name, isFirst);
newName = name;
isFirst = false;
}
long size = f.getSize();
try {
if (target instanceof PutableResource) {
PutableResource putable = (PutableResource) target;
Resource newRes = putable.createNew(name, f.getInputStream(), size, null);
if (newRes != null) {
log.trace("created: " + newRes.getName() + " of type: " + newRes.getClass());
} else {
log.trace("createNew returned null");
}
} else {
throw new BadRequestException(target, "Does not implement PutableResource");
}
} catch (ConflictException ex) {
throw new RuntimeException(ex);
} catch (NotAuthorizedException ex) {
throw new RuntimeException(ex);
} catch (BadRequestException ex) {
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
try {
if (newName != null) {
// we renamed the file
uploadResponseOk(name);
} else {
uploadResponseOk();
}
} catch (Throwable ex) {
log.error("Exception saving new file", ex);
uploadResponseFailed(ex.getMessage());
}
}
use of io.milton.resource.Resource in project lobcder by skoulouzis.
the class UserManagerAdapter method authenticate.
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
if (authentication instanceof UsernamePasswordAuthentication) {
UsernamePasswordAuthentication upa = (UsernamePasswordAuthentication) authentication;
String user = upa.getUsername();
String password = upa.getPassword();
log.debug("authenticate: " + user);
NameAndAuthority naa = NameAndAuthority.parse(user);
if (naa.domain == null) {
log.warn("invalid login. no domain specified. use form: user#domain");
return null;
}
Resource hostRoot;
try {
hostRoot = resourceFactory.getResource(naa.domain, "/");
} catch (NotAuthorizedException ex) {
throw new RuntimeException(ex);
} catch (BadRequestException ex) {
throw new RuntimeException(ex);
}
if (hostRoot == null) {
log.warn("failed to find root for domain: " + naa.domain);
return null;
}
Object oUser = hostRoot.authenticate(naa.toMilton(), password);
if (oUser != null) {
return new MiltonUser(oUser, naa.toMilton(), naa.domain);
} else {
log.debug("authentication failed: " + user);
return null;
}
} else if (authentication instanceof AnonymousAuthentication) {
log.debug("anonymous login not supported");
return null;
} else {
log.warn("unknown authentication type: " + authentication.getClass());
return null;
}
}
Aggregations