use of org.glassfish.admingui.common.util.RestResponse in project Payara by payara.
the class RestApiHandlers method checkIfEndPointExist.
@Handler(id = "gf.checkIfEndPointExist", input = { @HandlerInput(name = "endpoint", type = String.class, required = true) }, output = { @HandlerOutput(name = "exists", type = Boolean.class) })
public static void checkIfEndPointExist(HandlerContext handlerCtx) {
boolean result = false;
RestResponse response = null;
try {
response = get((String) handlerCtx.getInputValue("endpoint"));
result = response.isSuccess();
} catch (Exception ex) {
GuiUtil.getLogger().info("checkIfEnpointExist failed.");
if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
ex.printStackTrace();
}
} finally {
if (response != null) {
response.close();
}
}
handlerCtx.setOutputValue("exists", result);
}
use of org.glassfish.admingui.common.util.RestResponse in project Payara by payara.
the class SecurityHandler method removeUser.
/**
* <p> This handler removes users for specified realm.
* @param handlerCtx The HandlerContext.
*/
@Handler(id = "removeUser", input = { @HandlerInput(name = "Realm", type = String.class, required = true), @HandlerInput(name = "configName", type = String.class, required = true), @HandlerInput(name = "selectedRows", type = List.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void removeUser(HandlerContext handlerCtx) {
String error = null;
String realmName = (String) handlerCtx.getInputValue("Realm");
String configName = (String) handlerCtx.getInputValue("configName");
try {
List obj = (List) handlerCtx.getInputValue("selectedRows");
List<Map> selectedRows = (List) obj;
for (Map oneRow : selectedRows) {
String user = (String) oneRow.get("name");
String endpoint = GuiUtil.getSessionValue("REST_URL") + "/configs/config/" + configName + "/admin-service/jmx-connector/system.json";
Map<String, Object> responseMap = RestUtil.restRequest(endpoint, null, "get", handlerCtx, false);
Map<String, Object> valueMap = (Map<String, Object>) responseMap.get("data");
valueMap = (Map<String, Object>) ((Map<String, Object>) valueMap.get("extraProperties")).get("entity");
String authRealm = (String) valueMap.get("authRealmName");
if (realmName.equals(authRealm) && user.equals(GuiUtil.getSessionValue("userName"))) {
error = GuiUtil.getMessage(COMMON_BUNDLE, "msg.error.cannotDeleteCurrent");
continue;
} else {
HashMap attrs = new HashMap<String, Object>();
endpoint = GuiUtil.getSessionValue("REST_URL") + "/configs/config/" + configName + "/security-service/auth-realm/" + realmName + "/delete-user?target=" + configName;
attrs.put("name", user);
RestResponse response = RestUtil.delete(endpoint, attrs);
if (!response.isSuccess()) {
GuiUtil.getLogger().severe("Remove user failed. parent=" + endpoint + "; attrs =" + attrs);
error = GuiUtil.getMessage("msg.error.checkLog");
}
}
}
if (error != null) {
GuiUtil.prepareAlert("error", error, null);
}
} catch (Exception ex) {
GuiUtil.handleException(handlerCtx, ex);
}
}
use of org.glassfish.admingui.common.util.RestResponse in project Payara by payara.
the class AdminConsoleAuthModule method validateRequest.
/**
* <p>
* This is where the validation happens...
* </p>
*/
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {
HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();
if (!isMandatory(messageInfo) && !request.getRequestURI().endsWith("/j_security_check")) {
return doNothing(clientSubject);
}
HttpSession session = request.getSession(true);
Subject savedClientSubject = (Subject) session.getAttribute(SAVED_SUBJECT);
String savedUsername = (String) session.getAttribute(USER_NAME);
if (savedClientSubject != null && savedUsername != null) {
// Caller authenticated before, re-apply authentication for this request
return notifyContainerAboutLogin(clientSubject, savedUsername);
}
// See if we've already calculated the serverName / serverPort
if (session.getAttribute(REST_SERVER_NAME) == null) {
saveServerHostPort(session);
}
// See if the username / password has been passed in...
String username = request.getParameter("j_username");
char[] password = request.getParameter("j_password") != null ? request.getParameter("j_password").toCharArray() : null;
if (username == null || password == null || !request.getMethod().equalsIgnoreCase("post")) {
// Credentials not passed in, show the login page
return saveRequestAndForwardToLogin(session, request, response);
}
// Credentials provided, validte them via a REST based identity store
RestResponse validationResult = validateCredentials(request, username, password);
// Check to see if successful
if (validationResult.isSuccess()) {
notifyContainerAboutLogin(clientSubject, username);
request.changeSessionId();
// Get the "extraProperties" section from the validation result
@SuppressWarnings("rawtypes") Map extraProperties = getExtraProperties(validationResult);
// Save the Rest Token...
if (extraProperties != null) {
session.setAttribute(REST_TOKEN, extraProperties.get("token"));
}
// Save the Subject...
session.setAttribute(SAVED_SUBJECT, clientSubject);
// Save the userName
session.setAttribute(USER_NAME, username);
return redirectBack(session, request, response);
}
// If we reach this location an error has occurred
return forwardToErrorPage(validationResult, request, response);
}
Aggregations