Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2009-2012 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.admingui.common.handlers;
import com.sun.jsftemplating.annotation.Handler;
import com.sun.jsftemplating.annotation.HandlerInput;
import com.sun.jsftemplating.annotation.HandlerOutput;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.glassfish.admingui.common.util.GuiUtil;
import org.glassfish.admingui.common.util.RestResponse;
import org.glassfish.admingui.common.util.RestUtil;
/**
*
* @author anilam
*/
public class SecurityHandler {
/**
*
This handler returns the a Map for storing the attributes for realm creation.
* @param handlerCtx The HandlerContext.
*/
@Handler(id="getRealmAttrForCreate",
output={
@HandlerOutput(name="attrMap", type=Map.class),
@HandlerOutput(name="classnameOption", type=String.class),
@HandlerOutput(name="realmClasses", type=List.class),
@HandlerOutput(name="properties", type=List.class)})
public static void getRealmAttrForCreate(HandlerContext handlerCtx) {
handlerCtx.setOutputValue("realmClasses", realmClassList);
handlerCtx.setOutputValue("classnameOption", "predefine");
Map attrMap = new HashMap();
attrMap.put("predefinedClassname", Boolean.TRUE);
handlerCtx.setOutputValue("attrMap", attrMap);
handlerCtx.setOutputValue("properties", new ArrayList());
}
/**
*
This handler returns the a Map for storing the attributes for editing a realm.
* This can be used by either the node agent realm or the realm in configuration-Security-realm
* @param handlerCtx The HandlerContext.
*/
@Handler(id="getRealmAttrForEdit",
input={
@HandlerInput(name="endpoint", type=String.class)},
output={
@HandlerOutput(name="attrMap", type=Map.class),
@HandlerOutput(name="classnameOption", type=String.class),
@HandlerOutput(name="realmClasses", type=List.class),
@HandlerOutput(name="properties", type=List.class)})
public static void getRealmAttrForEdit(HandlerContext handlerCtx) {
String endpoint = (String) handlerCtx.getInputValue("endpoint");
HashMap realmMap = (HashMap) RestUtil.getEntityAttrs(endpoint, "entity");
HashMap responseMap = (HashMap) RestUtil.restRequest(endpoint + "/property.json", null, "GET", null, false);
HashMap propsMap = (HashMap) ((Map) responseMap.get("data")).get("extraProperties");
ArrayList propList = (ArrayList) propsMap.get("properties");
HashMap origProps = new HashMap();
for (HashMap prop : propList) {
origProps.put(prop.get("name"), prop.get("value"));
}
Map attrMap = new HashMap();
attrMap.put("Name", (String) realmMap.get("name"));
attrMap.put("fileJaax", "fileRealm");
attrMap.put("ldapJaax", "ldapRealm" );
attrMap.put("solarisJaax", "solarisRealm");
attrMap.put("jdbcJaax", "jdbcRealm");
String classname = (String) realmMap.get("classname");
if (realmClassList.contains(classname)){
handlerCtx.setOutputValue("classnameOption", "predefine");
attrMap.put("predefinedClassname", Boolean.TRUE);
attrMap.put("classname", classname);
List props = getChildrenMapForTableList(propList, "property", skipRealmPropsList);
handlerCtx.setOutputValue("properties", props);
if(classname.indexOf("FileRealm")!= -1){
attrMap.put("file", origProps.get("file"));
attrMap.put("fileJaax", origProps.get("jaas-context"));
attrMap.put("fileAsGroups", origProps.get("assign-groups"));
}else
if(classname.indexOf("LDAPRealm")!= -1){
attrMap.put("ldapJaax", origProps.get("jaas-context"));
attrMap.put("ldapAsGroups", origProps.get("assign-groups"));
attrMap.put("directory", origProps.get("directory"));
attrMap.put("baseDn", origProps.get("base-dn"));
}else
if(classname.indexOf("SolarisRealm")!= -1){
attrMap.put("solarisJaax", origProps.get("jaas-context"));
attrMap.put("solarisAsGroups", origProps.get("assign-groups"));
}else
if(classname.indexOf("PamRealm")!= -1){
attrMap.put("pamJaax", origProps.get("jaas-context"));
}else
if(classname.indexOf("JDBCRealm")!= -1){
attrMap.put("jdbcJaax", origProps.get("jaas-context"));
attrMap.put("jdbcAsGroups", origProps.get("assign-groups"));
attrMap.put("datasourceJndi", origProps.get("datasource-jndi"));
attrMap.put("userTable", origProps.get("user-table"));
attrMap.put("userNameColumn", origProps.get("user-name-column"));
attrMap.put("passwordColumn", origProps.get("password-column"));
attrMap.put("groupTable", origProps.get("group-table"));
attrMap.put("groupTableUserName", origProps.get("group-table-user-name-column"));
attrMap.put("groupNameColumn", origProps.get("group-name-column"));
attrMap.put("dbUser", origProps.get("db-user"));
attrMap.put("dbPassword", origProps.get("db-password"));
attrMap.put("digestAlgorithm", origProps.get("digest-algorithm"));
attrMap.put("pswdEncAlgorithm", origProps.get("digestrealm-password-enc-algorithm"));
attrMap.put("encoding", origProps.get("encoding"));
attrMap.put("charset", origProps.get("charset"));
}else
if(classname.indexOf("CertificateRealm")!= -1){
attrMap.put("certAsGroups", origProps.get("assign-groups"));
}
}else{
//Custom realm class
handlerCtx.setOutputValue("classnameOption", "input");
attrMap.put("predefinedClassname", Boolean.FALSE);
attrMap.put("classnameInput", classname);
attrMap.put("classname", classname);
List props = getChildrenMapForTableList(propList, "property", null);
handlerCtx.setOutputValue("properties", props);
}
handlerCtx.setOutputValue("attrMap", attrMap);
handlerCtx.setOutputValue("realmClasses", realmClassList);
}
public static List getChildrenMapForTableList(List propList, String childType, List skipList){
boolean hasSkip = true;
if (skipList == null ){
hasSkip = false;
}
List result = new ArrayList();
if (propList != null) {
for(HashMap oneMap: propList){
HashMap oneRow = new HashMap();
String name = (String) oneMap.get("name");
if (hasSkip && skipList.contains(name)){
continue;
}
oneRow.put("selected", false);
oneRow.put("name", name);
oneRow.put("value", oneMap.get("value"));
oneRow.put("description", oneMap.get("description"));
result.add(oneRow);
}
}
return result;
}
public static List getListfromMap(HashMap props) {
List result = new ArrayList();
Iterator it = props.entrySet().iterator();
while(it.hasNext()) {
Map.Entry m =(Map.Entry)it.next();
HashMap oneRow = new HashMap();
oneRow.put("selected", false);
oneRow.put("Name", m.getKey());
oneRow.put("Value", m.getValue());
oneRow.put("Description", "");
result.add(oneRow);
}
return result;
}
@Handler(id="saveRealm",
input={
@HandlerInput(name="endpoint", type=String.class),
@HandlerInput(name="classnameOption", type=String.class),
@HandlerInput(name="attrMap", type=Map.class),
@HandlerInput(name="edit", type=Boolean.class, required=true),
@HandlerInput(name="contentType", type=String.class, required=false),
@HandlerInput(name="propList", type=List.class)
},
output={
@HandlerOutput(name="newPropList", type=List.class)
})
public static void saveRealm(HandlerContext handlerCtx) {
String option = (String) handlerCtx.getInputValue("classnameOption");
List