use of org.qi4j.library.rest.server.api.SubResource in project qi4j-sdk by Qi4j.
the class RootResource method administration.
@SubResource
public void administration() {
ChallengeResponse challenge = Request.getCurrent().getChallengeResponse();
if (challenge == null) {
Response.getCurrent().setChallengeRequests(Collections.singletonList(new ChallengeRequest(ChallengeScheme.HTTP_BASIC, "Forum")));
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED);
}
User user = module.currentUnitOfWork().newQuery(module.newQueryBuilder(User.class).where(QueryExpressions.eq(QueryExpressions.templateFor(User.class).name(), challenge.getIdentifier()))).find();
if (user == null || !user.isCorrectPassword(new String(challenge.getSecret()))) {
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED);
}
current().select(user);
subResource(AdministrationResource.class);
}
Aggregations