Example usage for java.security AccessControlException AccessControlException

List of usage examples for java.security AccessControlException AccessControlException

Introduction

In this page you can find the example usage for java.security AccessControlException AccessControlException.

Prototype

public AccessControlException(String s) 

Source Link

Document

Constructs an AccessControlException with the specified, detailed message.

Usage

From source file:com.sshtools.common.ui.SshToolsApplication.java

/**
 * Creates a new SshToolsApplication object.
 *
 * @param panelClass/*w  w w  .j a va2s . c  o m*/
 * @param defaultContainerClass
 */
public SshToolsApplication(Class panelClass, Class defaultContainerClass) {
    this.panelClass = panelClass;
    this.defaultContainerClass = defaultContainerClass;
    additionalOptionsTabs = new java.util.ArrayList();

    try {
        if (System.getSecurityManager() != null) {
            AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write"));
        }

        File a = getApplicationPreferencesDirectory();

        if (a == null) {
            throw new AccessControlException("Application preferences directory not specified.");
        }

        InputStream in = null;
        MRUList mru = new MRUList();

        try {
            File f = new File(a, getApplicationName() + ".mru");

            if (f.exists()) {
                if (log.isDebugEnabled()) {
                    log.debug("Loading MRU from " + f.getAbsolutePath());
                }

                in = new FileInputStream(f);
                mru.reload(in);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("MRU file " + f.getAbsolutePath() + " doesn't exist, creating empty list");
                }
            }
        } catch (Exception e) {
            log.error("Could not load MRU list.", e);
        } finally {
            IOUtil.closeStream(in);
        }

        mruModel = new MRUListModel();
        mruModel.setMRUList(mru);
    } catch (AccessControlException ace) {
        log.error("Could not load MRU.", ace);
    }
}

From source file:org.apache.syncope.client.console.pages.Login.java

public Login(final PageParameters parameters) {
    super(parameters);
    setStatelessHint(true);/* www  . ja va 2 s . co m*/

    feedbackPanel = new NotificationPanel(Constants.FEEDBACK);
    add(feedbackPanel);

    form = new StatelessForm<Void>("login");

    userIdField = new TextField<String>("userId", new Model<String>());
    userIdField.setMarkupId("userId");
    form.add(userIdField);

    passwordField = new PasswordTextField("password", new Model<String>());
    passwordField.setMarkupId("password");
    form.add(passwordField);

    languageSelect = new LocaleDropDown("language");

    form.add(languageSelect);

    AjaxButton submitButton = new AjaxButton("submit", new Model<String>(getString("submit"))) {

        private static final long serialVersionUID = 429178684321093953L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            try {
                if (anonymousUser.equals(userIdField.getRawInput())) {
                    throw new AccessControlException("Illegal username");
                }

                authenticate(userIdField.getRawInput(), passwordField.getRawInput());

                setResponsePage(WelcomePage.class, parameters);
            } catch (AccessControlException e) {
                error(getString("login-error"));
                feedbackPanel.refresh(target);
                SyncopeSession.get().resetClients();
            }
        }
    };

    submitButton.setDefaultFormProcessing(false);
    form.add(submitButton);

    add(form);

    // Modal window for self registration
    final ModalWindow selfRegModalWin = new ModalWindow("selfRegModal");
    selfRegModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    selfRegModalWin.setInitialHeight(SELF_REG_WIN_HEIGHT);
    selfRegModalWin.setInitialWidth(SELF_REG_WIN_WIDTH);
    selfRegModalWin.setCookieName("self-reg-modal");
    add(selfRegModalWin);

    Fragment selfRegFrag;
    if (userSelfRestClient.isSelfRegistrationAllowed()) {
        selfRegFrag = new Fragment("selfRegistration", "selfRegAllowed", this);

        final AjaxLink<Void> selfRegLink = new ClearIndicatingAjaxLink<Void>("link", getPageReference()) {

            private static final long serialVersionUID = -7978723352517770644L;

            @Override
            protected void onClickInternal(final AjaxRequestTarget target) {
                selfRegModalWin.setPageCreator(new ModalWindow.PageCreator() {

                    private static final long serialVersionUID = -7834632442532690940L;

                    @Override
                    public Page createPage() {
                        // anonymous authentication needed for self-registration
                        authenticate(anonymousUser, anonymousKey);

                        return new UserSelfModalPage(Login.this.getPageReference(), selfRegModalWin,
                                new UserTO());
                    }
                });

                selfRegModalWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

                    private static final long serialVersionUID = 251794406325329768L;

                    @Override
                    public void onClose(final AjaxRequestTarget target) {
                        SyncopeSession.get().invalidate();
                    }
                });

                selfRegModalWin.show(target);
            }
        };
        selfRegLink.add(new Label("linkTitle", getString("selfRegistration")));

        Panel panel = new LinkPanel("selfRegistration", new ResourceModel("selfRegistration"));
        panel.add(selfRegLink);
        selfRegFrag.add(panel);
    } else {
        selfRegFrag = new Fragment("selfRegistration", "selfRegNotAllowed", this);
    }
    add(selfRegFrag);

    // Modal window for password reset request
    final ModalWindow pwdResetReqModalWin = new ModalWindow("pwdResetReqModal");
    pwdResetReqModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    pwdResetReqModalWin.setInitialHeight(PWD_RESET_WIN_HEIGHT);
    pwdResetReqModalWin.setInitialWidth(PWD_RESET_WIN_WIDTH);
    pwdResetReqModalWin.setCookieName("pwd-reset-req-modal");
    add(pwdResetReqModalWin);

    Fragment pwdResetFrag;
    if (userSelfRestClient.isPasswordResetAllowed()) {
        pwdResetFrag = new Fragment("passwordReset", "pwdResetAllowed", this);

        final AjaxLink<Void> pwdResetLink = new ClearIndicatingAjaxLink<Void>("link", getPageReference()) {

            private static final long serialVersionUID = -6957616042924610290L;

            @Override
            protected void onClickInternal(final AjaxRequestTarget target) {
                pwdResetReqModalWin.setPageCreator(new ModalWindow.PageCreator() {

                    private static final long serialVersionUID = -7834632442532690940L;

                    @Override
                    public Page createPage() {
                        // anonymous authentication needed for password reset request
                        authenticate(anonymousUser, anonymousKey);

                        return new RequestPasswordResetModalPage(pwdResetReqModalWin);
                    }
                });

                pwdResetReqModalWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

                    private static final long serialVersionUID = 8804221891699487139L;

                    @Override
                    public void onClose(final AjaxRequestTarget target) {
                        SyncopeSession.get().invalidate();
                        setResponsePage(Login.class);
                    }
                });

                pwdResetReqModalWin.show(target);
            }
        };
        pwdResetLink.add(new Label("linkTitle", getString("passwordReset")));

        Panel panel = new LinkPanel("passwordReset", new ResourceModel("passwordReset"));
        panel.add(pwdResetLink);
        pwdResetFrag.add(panel);
    } else {
        pwdResetFrag = new Fragment("passwordReset", "pwdResetNotAllowed", this);
    }
    add(pwdResetFrag);

    // Modal window for password reset confirm - automatically shown when token is available as request parameter
    final String pwdResetToken = RequestCycle.get().getRequest().getRequestParameters()
            .getParameterValue(Constants.PARAM_PASSWORD_RESET_TOKEN).toOptionalString();
    final ModalWindow pwdResetConfModalWin = new ModalWindow("pwdResetConfModal");
    if (StringUtils.isNotBlank(pwdResetToken)) {
        pwdResetConfModalWin.add(new AbstractDefaultAjaxBehavior() {

            private static final long serialVersionUID = 3109256773218160485L;

            @Override
            protected void respond(final AjaxRequestTarget target) {
                ModalWindow window = (ModalWindow) getComponent();
                window.show(target);
            }

            @Override
            public void renderHead(final Component component, final IHeaderResponse response) {
                response.render(JavaScriptHeaderItem.forScript(getCallbackScript(), null));
            }
        });
    }
    pwdResetConfModalWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    pwdResetConfModalWin.setInitialHeight(PWD_RESET_WIN_HEIGHT);
    pwdResetConfModalWin.setInitialWidth(PWD_RESET_WIN_WIDTH);
    pwdResetConfModalWin.setCookieName("pwd-reset-conf-modal");
    pwdResetConfModalWin.setPageCreator(new ModalWindow.PageCreator() {

        private static final long serialVersionUID = -7834632442532690940L;

        @Override
        public Page createPage() {
            // anonymous authentication needed for password reset confirm
            authenticate(anonymousUser, anonymousKey);

            return new ConfirmPasswordResetModalPage(pwdResetConfModalWin, pwdResetToken);
        }
    });
    pwdResetConfModalWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        private static final long serialVersionUID = 8804221891699487139L;

        @Override
        public void onClose(final AjaxRequestTarget target) {
            SyncopeSession.get().invalidate();
            setResponsePage(Login.class);
        }
    });
    add(pwdResetConfModalWin);
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java

public static String getName(Node node) {
    try {//  ww  w  .  j  av a2  s  .c  om
        return node.getName();
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to access name property of node: " + node, e);
    }
}

From source file:servlets.Admin_servlets.java

private void backup_datadatabases(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String filename = "STATegraDB_content_backup_" + new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date())
            + ".sql";
    String backup_file_location = DATA_LOCATION + "/" + filename;

    try {/*from ww  w . j  a  va2 s.c o m*/
        /**
         * *******************************************************
         * STEP 1 CHECK IF THE USER IS LOGGED CORRECTLY IN THE APP. IF ERROR
         * --> throws exception if not valid session, GO TO STEP 4b ELSE -->
         * GO TO STEP 2
         * *******************************************************
         */
        Map<String, Cookie> cookies = this.getCookies(request);
        String loggedUser = cookies.get("loggedUser").getValue();
        String sessionToken = cookies.get("sessionToken").getValue();

        /**
         * *******************************************************
         * STEP 1 CHECK IF THE USER IS LOGGED CORRECTLY IN THE APP. IF
         * ERROR --> throws exception if not valid session, GO TO STEP
         * 3b ELSE --> GO TO STEP 2
         * *******************************************************
         */
        if (!checkAccessPermissions(loggedUser, sessionToken)) {
            throw new AccessControlException("Your session is invalid. User or session token not allowed.");
        }
        if (!isValidAdminUser(loggedUser)) {
            throw new AccessControlException("User not allowed for this action.");
        }

        /**
         * *******************************************************
         * STEP 2 EXECUTE THE DUMP SCRIPT. IF ERROR --> throws exception if
         * failed dump, GO TO STEP 3b ELSE --> GO TO STEP 3
         * *******************************************************
         */
        DBConnectionManager.getConnectionManager().doDatabaseDump(backup_file_location);

    } catch (Exception e) {
        ServerErrorManager.handleException(e, Admin_servlets.class.getName(), "backup_datadatabases",
                e.getMessage());
    } finally {
        /**
         * *******************************************************
         * STEP 3b CATCH ERROR. GO TO STEP 5
         * *******************************************************
         */
        if (ServerErrorManager.errorStatus()) {
            response.setStatus(400);
            response.getWriter().print(ServerErrorManager.getErrorResponse());

            File file = new File(backup_file_location);
            if (file.exists()) {
                file.delete();
            }
        } else {
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "filename=\"" + filename + "\"");
            File srcFile = new File(backup_file_location);
            FileUtils.copyFile(srcFile, response.getOutputStream());

            //                /**
            //                 * *******************************************************
            //                 * STEP 3A WRITE RESPONSE ERROR.
            //                 * *******************************************************
            //                 */
            //                JsonObject obj = new JsonObject();
            //                obj.add("success", new JsonPrimitive(true));
            //                response.getWriter().print(obj.toString());
        }
    }
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrUtil.java

public static Node getParent(Node node) {
    try {//from  w ww . j a v  a  2s  . c  om
        return node.getParent();
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to retrieve the parent of node: " + node, e);
    }
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java

public static String getName(Property prop) {
    try {// w ww  .  ja v  a 2 s .c o  m
        return prop.getName();
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to get the name of property: " + prop, e);
    }
}

From source file:com.silverpeas.blog.control.BlogSessionController.java

public void checkWriteAccessOnBlogPost() {
    if (!accessController.isUserAuthorized(getUserId(), getComponentId())) {
        String errorMsg = getMultilang().getString(FORBIDEN_ACCESS_MSG);
        throw new AccessControlException(errorMsg);
    }//from  w  w  w  . j  av  a 2s .  com
}

From source file:ca.nrc.cadc.web.ServerToServerFTPTransfer.java

/**
 *
 * @param ftpClient     The Connected client.
 * @return              The mutated client, now authenticated.
 * @throws AccessControlException    If login fails.
 */// w  w w.ja v  a 2 s. c o m
private FTPClient login(final FTPClient ftpClient) throws AccessControlException, IOException {
    if (!ftpClient.login(CREDENTIAL, CREDENTIAL)) {
        ftpClient.logout();
        throw new AccessControlException(String.format("Login failed for %s", CREDENTIAL));
    } else {
        return ftpClient;
    }
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java

public static String getString(Node node, String name) {
    try {//from w  w w.ja va 2s  . c om
        Property prop = node.getProperty(name);
        return prop.getString();
    } catch (PathNotFoundException e) {
        return null;
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to access property: " + name, e);
    }
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrUtil.java

public static Node getRootNode(Session session) {
    try {// w  w  w.  j  a  v  a 2 s.c  o  m
        return session.getRootNode();
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to retrieve the root node", e);
    }
}