@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED})
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML,"text/html;qs=2"})
public Response create(HashMap<String, String> data) {
Response.ResponseBuilder responseBuilder = Response.status(UNAUTHORIZED);
RestActionReporter ar = new RestActionReporter();
GrizzlyRequest grizzlyRequest = request.get();
// If the call flow reached here, the request has been authenticated by logic in RestAdapater.
// We authenticate here once again with supplied remoteHostName to see if the authentication needs to happen
// as coming from it. This is to support admin gui to authenticate as if coming from remoteHostName that
// original request to it originated from.
String hostName = data.get("remoteHostName");
AdminAccessController.Access access = AdminAccessController.Access.NONE;
try {
access = (hostName == null ? AdminAccessController.Access.FULL : ResourceUtil.authenticateViaAdminRealm(habitat, grizzlyRequest, hostName) ) ;
} catch (Exception e) {
ar.setMessage("Error while authenticating " + e);
}
if (access == AdminAccessController.Access.FULL) {
responseBuilder.status(OK);
// Check to see if the username has been set (anonymous user case)
String username = (String) grizzlyRequest.getAttribute("restUser");
if (username != null) {
ar.getExtraProperties().put("username", username);
}
ar.getExtraProperties().put("token", sessionManager.createSession(grizzlyRequest));