<commit_before>/*******************************************************************************
 * Copyright (c) 2014 Whizzo Software, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package com.whizzosoftware.hobson.rest.v1.resource.config;

import com.whizzosoftware.hobson.api.hub.HubManager;
import com.whizzosoftware.hobson.rest.v1.HobsonRestContext;
import com.whizzosoftware.hobson.rest.v1.JSONMarshaller;
import org.restlet.data.Status;
import org.restlet.ext.guice.SelfInjectingServerResource;
import org.restlet.representation.EmptyRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.ResourceException;

import javax.inject.Inject;

/**
 * A REST resource that manages the Hub admin password.
 *
 * @author <NAME>
 */
public class HubPasswordResource extends SelfInjectingServerResource {
    public static final String PATH = "/users/{userId}/hubs/{hubId}/configuration/password";
    public static final String REL = "password";

    @Inject
    HubManager hubManager;

    /**
     * @api {post} /api/v1/users/:userId/hubs/:hubId/configuration/password Set Hub password
     * @apiVersion 0.1.6
     * @apiName SetPassword
     * @apiDescription Sets the Hub password.
     * @apiGroup Hub
     * @apiParamExample {json} Example Request:
     * {
     *   "currentPassword": "<PASSWORD>",
     *   "newPassword": "<PASSWORD>"
     * }
     * @apiSuccessExample {json} Success Response:
     * HTTP/1.1 202 Accepted
     * @apiErrorExample {json} Error Response:
     * HTTP/1.1 400 Bad Request
     * Content-Type: application/json; charset=UTF-8
     * 
     * {"message":"New password does not meet complexity requirements"}
     */
    @Override
    protected Representation post(Representation entity) throws ResourceException {
        HobsonRestContext ctx = HobsonRestContext.createContext(this, getRequest());
        hubManager.setHubPassword(ctx.getUserId(), ctx.getHubId(), JSONMarshaller.createPasswordChange(JSONMarshaller.createJSONFromRepresentation(entity)));
        getResponse().setStatus(Status.SUCCESS_ACCEPTED);
        return new EmptyRepresentation();
    }
}<commit_msg>Added password complexity API description.<commit_after>/*******************************************************************************
 * Copyright (c) 2014 Whizzo Software, LLC.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package com.whizzosoftware.hobson.rest.v1.resource.config;

import com.whizzosoftware.hobson.api.hub.HubManager;
import com.whizzosoftware.hobson.rest.v1.HobsonRestContext;
import com.whizzosoftware.hobson.rest.v1.JSONMarshaller;
import org.restlet.data.Status;
import org.restlet.ext.guice.SelfInjectingServerResource;
import org.restlet.representation.EmptyRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.ResourceException;

import javax.inject.Inject;

/**
 * A REST resource that manages the Hub admin password.
 *
 * @author <NAME>
 */
public class HubPasswordResource extends SelfInjectingServerResource {
    public static final String PATH = "/users/{userId}/hubs/{hubId}/configuration/password";
    public static final String REL = "password";

    @Inject
    HubManager hubManager;

    /**
     * @api {post} /api/v1/users/:userId/hubs/:hubId/configuration/password Set Hub password
     * @apiVersion 0.1.6
     * @apiName SetPassword
     * @apiDescription Sets the Hub password. The complexity requirements for the new password are: 1. Between 8 and 14 characters long, 2. At least one upper and lower case letter, 3. At least one number, 4. At least one special character.
     * @apiGroup Hub
     * @apiParamExample {json} Example Request:
     * {
     *   "currentPassword": "<PASSWORD>",
     *   "newPassword": "<PASSWORD>"
     * }
     * @apiSuccessExample {json} Success Response:
     * HTTP/1.1 202 Accepted
     * @apiErrorExample {json} Error Response:
     * HTTP/1.1 400 Bad Request
     * Content-Type: application/json; charset=UTF-8
     *
     * {"message":"New password does not meet complexity requirements"}
     */
    @Override
    protected Representation post(Representation entity) throws ResourceException {
        HobsonRestContext ctx = HobsonRestContext.createContext(this, getRequest());
        hubManager.setHubPassword(ctx.getUserId(), ctx.getHubId(), JSONMarshaller.createPasswordChange(JSONMarshaller.createJSONFromRepresentation(entity)));
        getResponse().setStatus(Status.SUCCESS_ACCEPTED);
        return new EmptyRepresentation();
    }
}
{'fraction_non_alphanumeric': 0.1574710386805419, 'fraction_numerical': 0.011584527783231886, 'mean_word_length': 4.311783107403546, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2502062', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1361, 'n_words': 351}