Search in sources :

Example 1 with ChallengeRequest

use of org.restlet.data.ChallengeRequest 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);
}
Also used : User(org.qi4j.samples.forum.data.entity.User) ResourceException(org.restlet.resource.ResourceException) ChallengeRequest(org.restlet.data.ChallengeRequest) ChallengeResponse(org.restlet.data.ChallengeResponse) SubResource(org.qi4j.library.rest.server.api.SubResource)

Aggregations

SubResource (org.qi4j.library.rest.server.api.SubResource)1 User (org.qi4j.samples.forum.data.entity.User)1 ChallengeRequest (org.restlet.data.ChallengeRequest)1 ChallengeResponse (org.restlet.data.ChallengeResponse)1 ResourceException (org.restlet.resource.ResourceException)1