Search in sources :

Example 31 with ServletContext

use of javax.servlet.ServletContext in project OpenAM by OpenRock.

the class CreateFedlet method execute.

public String execute(Locale locale, Map params) throws WorkflowException {
    validateParameters(params);
    String entityId = getString(params, ParameterKeys.P_ENTITY_ID);
    Pattern patern = Pattern.compile("[/:\\.?|*]");
    Matcher match = patern.matcher(entityId);
    String folderName = match.replaceAll("");
    String workDir = SystemProperties.get(SystemProperties.CONFIG_PATH) + "/myfedlets/" + folderName;
    File dir = new File(workDir);
    if (dir.exists()) {
        throw new WorkflowException("directory.already.exist", workDir);
    }
    if (!dir.getParentFile().exists()) {
        dir.getParentFile().mkdir();
    }
    dir.mkdir();
    String warDir = workDir + "/war";
    dir = new File(warDir);
    dir.mkdir();
    String confDir = warDir + "/conf";
    dir = new File(confDir);
    dir.mkdir();
    loadMetaData(params, confDir);
    exportIDPMetaData(params, confDir);
    createCOTProperties(params, confDir);
    ServletContext servletCtx = (ServletContext) params.get(ParameterKeys.P_SERVLET_CONTEXT);
    copyBits(servletCtx, workDir);
    extractJars(servletCtx, warDir);
    createFederationConfigProperties(servletCtx, confDir);
    createWar(workDir);
    String zipFileName = createZip(workDir);
    return MessageFormat.format(getMessage("Fedlet.created", locale), zipFileName);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ServletContext(javax.servlet.ServletContext) File(java.io.File)

Example 32 with ServletContext

use of javax.servlet.ServletContext in project OpenAM by OpenRock.

the class AMSetupFilterTest method initShouldNotSetEncryptionPasswordIfConfigured.

@Test
public void initShouldNotSetEncryptionPasswordIfConfigured() throws Exception {
    //Given
    FilterConfig config = mock(FilterConfig.class);
    ServletContext context = mock(ServletContext.class);
    given(config.getServletContext()).willReturn(context);
    systemIsConfigured();
    //When
    setupFilter.init(config);
    //Then
    verifyZeroInteractions(context);
}
Also used : ServletContext(javax.servlet.ServletContext) FilterConfig(javax.servlet.FilterConfig) Test(org.testng.annotations.Test)

Example 33 with ServletContext

use of javax.servlet.ServletContext in project OpenAM by OpenRock.

the class AMSetupUtilsTest method readFileShouldThrowIOExceptionIfFileNotFound.

@Test(expectedExceptions = IOException.class)
public void readFileShouldThrowIOExceptionIfFileNotFound() throws IOException {
    //Given
    ServletContext context = mock(ServletContext.class);
    String file = "INVALID_FILE_NAME";
    //When
    readFile(context, file);
    //Then
    failBecauseExceptionWasNotThrown(IOException.class);
}
Also used : ServletContext(javax.servlet.ServletContext) Test(org.testng.annotations.Test)

Example 34 with ServletContext

use of javax.servlet.ServletContext in project OpenAM by OpenRock.

the class IDRepoAddViewBean method handleButton2Request.

/**
     * Handles create realm request.
     *
     * @param event Request invocation event
     */
public void handleButton2Request(RequestInvocationEvent event) throws ModelControlException {
    submitCycle = true;
    IDRepoModel model = (IDRepoModel) getModel();
    AMPropertySheet prop = (AMPropertySheet) getChild(PROPERTY_ATTRIBUTE);
    String idRepoType = (String) propertySheetModel.getValue(IDREPO_TYPE);
    String idRepoName = (String) propertySheetModel.getValue(IDREPO_NAME);
    Map defaultValues = model.getDefaultAttributeValues(idRepoType);
    if (idRepoName.trim().length() > 0) {
        try {
            boolean LoadSchema = false;
            Map values = prop.getAttributeValues(defaultValues.keySet());
            String realmName = (String) getPageSessionAttribute(AMAdminConstants.CURRENT_REALM);
            Set set = (HashSet) values.get("idRepoLoadSchema");
            if (set != null) {
                Iterator i = set.iterator();
                if (i.hasNext()) {
                    String loadingSchemaFlag = (String) i.next();
                    if (loadingSchemaFlag.equals("true") && IdRepoUtils.hasIdRepoSchema(idRepoType)) {
                        LoadSchema = true;
                    }
                }
            }
            model.createIDRepo(realmName, idRepoName, idRepoType, values);
            if (LoadSchema == true) {
                ServletContext servletCtx = event.getRequestContext().getServletContext();
                model.loadIdRepoSchema(idRepoName, realmName, servletCtx);
            }
            forwardToIDRepoViewBean();
        } catch (AMConsoleException e) {
            setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
            forwardTo();
        }
    } else {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", "idrepo.missing.idRepoName");
        forwardTo();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AMPropertySheet(com.sun.identity.console.base.AMPropertySheet) Iterator(java.util.Iterator) ServletContext(javax.servlet.ServletContext) IDRepoModel(com.sun.identity.console.realm.model.IDRepoModel) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Map(java.util.Map) HashSet(java.util.HashSet)

Example 35 with ServletContext

use of javax.servlet.ServletContext in project OpenAM by OpenRock.

the class IDRepoEditViewBean method handleButton1Request.

/**
     * Handles save request when editing the properties of a data store 
     * entry for a realm.
     *
     * @param event Request invocation event
     */
public void handleButton1Request(RequestInvocationEvent event) throws ModelControlException {
    submitCycle = true;
    IDRepoModel model = (IDRepoModel) getModel();
    AMPropertySheet prop = (AMPropertySheet) getChild(PROPERTY_ATTRIBUTE);
    String idRepoType = (String) propertySheetModel.getValue(IDREPO_TYPE);
    String idRepoName = (String) propertySheetModel.getValue(IDREPO_NAME);
    Map defaultValues = model.getDefaultAttributeValues(idRepoType);
    if (idRepoName.trim().length() > 0) {
        try {
            boolean LoadSchema = false;
            Map values = prop.getAttributeValues(defaultValues.keySet());
            String realmName = (String) getPageSessionAttribute(AMAdminConstants.CURRENT_REALM);
            values.remove(IdConstants.SERVICE_ATTRS);
            Set set = (HashSet) values.get("idRepoLoadSchema");
            if (set != null) {
                Iterator i = set.iterator();
                if (i.hasNext()) {
                    String loadingSchemaFlag = (String) i.next();
                    if (loadingSchemaFlag.equals("true") && IdRepoUtils.hasIdRepoSchema(idRepoType)) {
                        LoadSchema = true;
                    }
                }
            }
            model.editIDRepo(realmName, idRepoName, values);
            if (LoadSchema == true) {
                ServletContext servletCtx = event.getRequestContext().getServletContext();
                model.loadIdRepoSchema(idRepoName, realmName, servletCtx);
            }
            setInlineAlertMessage(CCAlert.TYPE_INFO, "message.information", "message.updated");
        } catch (AMConsoleException e) {
            setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
        }
    } else {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", "idrepo.missing.idRepoName");
    }
    forwardTo();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AMPropertySheet(com.sun.identity.console.base.AMPropertySheet) Iterator(java.util.Iterator) ServletContext(javax.servlet.ServletContext) IDRepoModel(com.sun.identity.console.realm.model.IDRepoModel) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

ServletContext (javax.servlet.ServletContext)1111 Test (org.junit.Test)259 HttpServletRequest (javax.servlet.http.HttpServletRequest)186 HttpServletResponse (javax.servlet.http.HttpServletResponse)143 IOException (java.io.IOException)136 ServletException (javax.servlet.ServletException)101 ServletConfig (javax.servlet.ServletConfig)79 File (java.io.File)78 FilterConfig (javax.servlet.FilterConfig)66 HashMap (java.util.HashMap)64 Enumeration (java.util.Enumeration)52 InputStream (java.io.InputStream)51 ArrayList (java.util.ArrayList)50 URL (java.net.URL)48 HttpSession (javax.servlet.http.HttpSession)43 Map (java.util.Map)39 Locale (java.util.Locale)38 List (java.util.List)33 PrintWriter (java.io.PrintWriter)32 LinkedHashMap (java.util.LinkedHashMap)30