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.thinkbiganalytics.metadata.modeshape.common.JcrPropertiesEntity.java

public void clearAdditionalProperties() {
    getPropertiesObject().ifPresent(propsObj -> {
        try {/*from   ww  w  .  j  ava  2  s.  co  m*/
            Node propsNode = propsObj.getNode();
            Map<String, Object> props = propsObj.getProperties();
            for (Map.Entry<String, Object> prop : props.entrySet()) {
                if (!JcrPropertyUtil.hasProperty(propsNode.getPrimaryNodeType(), prop.getKey())) {
                    try {
                        Property property = propsNode.getProperty(prop.getKey());
                        property.remove();
                    } catch (AccessDeniedException e) {
                        // Failed remove the extra property
                        log.debug("Access denied", e);
                        throw new AccessControlException(
                                "You do not have the permission to remove property \"" + prop.getKey() + "\"");
                    }
                }
            }
        } catch (RepositoryException e) {
            throw new MetadataRepositoryException("Unable to clear the Properties for this entity. ", e);
        }
    });
}

From source file:org.webcurator.auth.dbms.WCTForcePasswordChange.java

/** @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) */
public void doFilter(ServletRequest aRequest, ServletResponse aResponse, FilterChain aChain)
        throws IOException, ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Checking forced password change action.");
    }//from w w  w . j a  v a2s.  co  m

    if (!(aRequest instanceof HttpServletRequest)) {
        throw new ServletException("Can only process HttpServletRequest");
    }

    if (!(aResponse instanceof HttpServletResponse)) {
        throw new ServletException("Can only process HttpServletResponse");
    }

    HttpServletRequest httpRequest = (HttpServletRequest) aRequest;

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth != null) {
        if (auth.isAuthenticated()) {
            User authUser = (User) auth.getDetails();

            if (authUser != null) {
                if (authUser.isForcePasswordChange() == true && authUser.isExternalAuth() == false) {

                    RequestDispatcher reqDisp = httpRequest
                            .getRequestDispatcher("/" + Constants.CNTRL_RESET_PWD);
                    reqDisp.forward(aRequest, aResponse);
                    auditor.audit(User.class.getName(), authUser.getOid(), Auditor.ACTION_FORCE_PWD_CHANGE,
                            "User has been forced to change password");
                }
            }
        } else {
            throw new AccessControlException("The user is not authenticated correctly.");
        }
    }

    aChain.doFilter(aRequest, aResponse);
}

From source file:com.jpeterson.littles3.bo.Resource.java

/**
 * Determines if the <code>principal</code> can "write" the resource. The
 * meaning of "write" depends on the particular implementation of the
 * resource./*www  .  j  a v  a  2 s  . co  m*/
 * 
 * @param grantee
 *            The entity to check and see if they can "write" the resource.
 *            This is typically the authenticated principal requesting to
 *            write the resource.
 * @throws AccessControlException
 *             Thrown if the <code>principal</code> can not "write" the
 *             resource.
 */
public void canWrite(Grantee grantee) throws AccessControlException {
    if (acp == null) {
        throw new AccessControlException("Access Control Policy is null, therefore, no grants");
    }

    Permission permission = new ResourcePermission(grantee, ResourcePermission.ACTION_WRITE);
    acp.checkPermission(permission);
}

From source file:org.infoglue.igide.helper.http.HTTPTextDocumentListenerEngine.java

private void listen() {
    String errorMessage;//from w  w w. j a va 2s  .  c  o  m
    boolean error;
    errorMessage = "";
    error = false;
    try {
        Logger.logConsole("Starting listen thread");
        URLConnection urlConn = url.openConnection();
        urlConn.setConnectTimeout(3000);
        urlConn.setRequestProperty("Connection", "Keep-Alive");
        urlConn.setReadTimeout(0);
        urlConn.setDoInput(true);
        urlConn.setDoOutput(true);
        urlConn.setUseCaches(false);
        urlConn.setAllowUserInteraction(false);
        if (urlConn.getHeaderFields().toString().indexOf("401 Unauthorized") > -1) {
            Logger.logConsole("User has no access to the CMS - closing connection");
            throw new AccessControlException("User has no access to the CMS - closing connection");
        }
        String boundary = urlConn.getHeaderField("boundary");
        DataInputStream input = new DataInputStream(urlConn.getInputStream());
        StringBuffer buf = new StringBuffer();
        if (listener != null)
            listener.onConnection(url);
        String str = null;
        while ((str = input.readLine()) != null) {
            if (str.indexOf("XMLNotificationWriter.ping") == -1) {
                if (str.equals(boundary)) {
                    String message = buf.toString();

                    // By checking there is more in the String than the XML declaration we assume the message is valid
                    if (message != null
                            && !message.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").equals("")) {
                        if (listener != null)
                            listener.recieveDocument(buf.toString());
                        else
                            Logger.logConsole((new StringBuilder("NEW DOCUMENT!!\r\n")).append(buf.toString())
                                    .append("\r\n").toString());
                    }
                    buf = new StringBuffer();
                } else {
                    buf.append(str);
                }
            }
        }
        input.close();
    } catch (MalformedURLException me) {
        error = true;
        errorMessage = (new StringBuilder("Faulty CMS-url:")).append(url).toString();
        if (listener != null)
            listener.onException(me);
        else
            System.err.println((new StringBuilder("MalformedURLException: ")).append(me).toString());
        final String errorMessageFinal = errorMessage;
        Logger.logConsole(
                (new StringBuilder("The connection was shut. Was it an error:")).append(error).toString());
        if (!error) {
            if (System.currentTimeMillis() - lastRetry > 20000L) {
                Logger.logConsole("Trying to restart the listener as it was a while since last...");
                lastRetry = System.currentTimeMillis();
                listen();
            }
        } else {
            try {
                if (listener != null)
                    listener.onEndConnection(url);
            } catch (Exception e) {
                Logger.logConsole(
                        (new StringBuilder("Error ending connection:")).append(e.getMessage()).toString());
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openError(viewer.getControl().getShell(), "Error",
                            (new StringBuilder()).append(errorMessageFinal).toString());
                }
            });
        }
    } catch (IOException ioe) {
        error = true;
        errorMessage = "Got an I/O-Exception talking to the CMS. Check that it is started and in valid state.";
        Logger.logConsole((new StringBuilder("ioe: ")).append(ioe.getMessage()).toString());
        if (listener != null)
            listener.onException(ioe);
        else
            Logger.logConsole((new StringBuilder("TextDocumentListener cannot connect to: "))
                    .append(url.toExternalForm()).toString());
        final String errorMessageFinal = errorMessage;
        Logger.logConsole(
                (new StringBuilder("The connection was shut. Was it an error:")).append(error).toString());
        if (!error) {
            if (System.currentTimeMillis() - lastRetry > 20000L) {
                Logger.logConsole("Trying to restart the listener as it was a while since last...");
                lastRetry = System.currentTimeMillis();
                listen();
            }
        } else {
            try {
                if (listener != null)
                    listener.onEndConnection(url);
            } catch (Exception e) {
                Logger.logConsole(
                        (new StringBuilder("Error ending connection:")).append(e.getMessage()).toString());
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openError(viewer.getControl().getShell(), "Error",
                            (new StringBuilder()).append(errorMessageFinal).toString());
                }
            });
        }
    } catch (AccessControlException ace) {
        error = true;
        errorMessage = "The user you tried to connect with did not have the correct access rights. Check that he/she has roles etc enough to access the CMS";
        Logger.logConsole((new StringBuilder("ioe: ")).append(ace.getMessage()).toString());
        if (listener != null)
            listener.onException(ace);
        else
            Logger.logConsole((new StringBuilder()).append(ace.getMessage()).toString());
        final String errorMessageFinal = errorMessage;
        Logger.logConsole(
                (new StringBuilder("The connection was shut. Was it an error:")).append(error).toString());
        if (!error) {
            if (System.currentTimeMillis() - lastRetry > 20000L) {
                Logger.logConsole("Trying to restart the listener as it was a while since last...");
                lastRetry = System.currentTimeMillis();
                listen();
            }
        } else {
            try {
                if (listener != null)
                    listener.onEndConnection(url);
            } catch (Exception e) {
                Logger.logConsole(
                        (new StringBuilder("Error ending connection:")).append(e.getMessage()).toString());
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openError(viewer.getControl().getShell(), "Error",
                            (new StringBuilder()).append(errorMessageFinal).toString());
                }
            });
        }
    } catch (Exception exception) {
        final String errorMessageFinal = errorMessage;
        Logger.logConsole(
                (new StringBuilder("The connection was shut. Was it an error:")).append(error).toString());
        if (!error) {
            if (System.currentTimeMillis() - lastRetry > 20000L) {
                Logger.logConsole("Trying to restart the listener as it was a while since last...");
                lastRetry = System.currentTimeMillis();
                listen();
            }
        } else {
            try {
                if (listener != null)
                    listener.onEndConnection(url);
            } catch (Exception e) {
                Logger.logConsole(
                        (new StringBuilder("Error ending connection:")).append(e.getMessage()).toString());
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openError(viewer.getControl().getShell(), "Error",
                            (new StringBuilder()).append(errorMessageFinal).toString());
                }
            });
        }
    } catch (Throwable e) {
        final String errorMessageFinal = errorMessage;
        Logger.logConsole(
                (new StringBuilder("The connection was shut. Was it an error:")).append(error).toString());
        if (!error) {
            if (System.currentTimeMillis() - lastRetry > 20000L) {
                Logger.logConsole("Trying to restart the listener as it was a while since last...");
                lastRetry = System.currentTimeMillis();
                listen();
            }
        } else {
            try {
                if (listener != null)
                    listener.onEndConnection(url);
            } catch (Exception e2) {
                Logger.logConsole(
                        (new StringBuilder("Error ending connection:")).append(e2.getMessage()).toString());
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openError(viewer.getControl().getShell(), "Error",
                            (new StringBuilder()).append(errorMessageFinal).toString());
                }
            });
        }
    }
}

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

public static String getName(Node node) {
    try {/*w  w w. j a  v a 2  s  .c o m*/
        return node.getName();
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to get name of Node " + node, e);
    }
}

From source file:org.sakaiproject.kernel.loader.server.jetty.SakaiWebAppContext.java

@Override
@SuppressWarnings(value = "DC_DOUBLECHECK", justification = "Double checking in this instance avoids excessive use of the sunchronized lock as the variable is immutable once set")
public ClassLoader getClassLoader() {
    if (webappClassLoader == null) {
        synchronized (lock) {
            if (webappClassLoader == null) {
                try {

                    CommonObjectManager com = new CommonObjectManager("sharedclassloader");
                    final ClassLoader cl = com.getManagedObject();
                    parentClassloader = AccessController
                            .doPrivileged(new PrivilegedAction<SwitchedClassLoader>() {

                                public SwitchedClassLoader run() {
                                    return new SwitchedClassLoader(new URL[] {}, cl, containerClassLoader);
                                }/*from   w w w  .  ja v a2 s . c o m*/

                            });

                    LOG.info("Got Classloader fromm JMX as " + parentClassloader + "("
                            + parentClassloader.getClass() + ")");
                    if (debug) {
                        LOG.debug("Thread Context class loader is: " + parentClassloader);
                        ClassLoader loader = parentClassloader.getParent();
                        while (loader != null) {
                            LOG.debug("Parent class loader is: " + loader);
                            loader = loader.getParent();
                        }
                    }

                    webappClassLoader = AccessController
                            .doPrivileged(new PrivilegedAction<WebAppClassLoader>() {

                                public WebAppClassLoader run() {
                                    try {
                                        return new WebAppClassLoader(parentClassloader,
                                                SakaiWebAppContext.this);
                                    } catch (IOException e) {
                                        throw new AccessControlException(
                                                "Unable to start classloader cause:" + e.getMessage());
                                    }
                                }

                            });
                    super.setClassLoader(webappClassLoader);
                } catch (CommonObjectConfigurationException e) {
                    LOG.error(e);
                }
            }
        }
    }
    return webappClassLoader;
}

From source file:org.infoscoop.admin.web.AuthenticationServlet.java

private void login(HttpServletRequest request, String uid, String password) {

    String[] _userid = null;/*w  w  w.j a  va  2  s .  c o  m*/
    if (m_userid != null)
        _userid = m_userid.split(",");
    String[] _password = null;
    if (m_password != null)
        _password = m_password.split(",");

    boolean success = false;
    for (int i = 0; i < _userid.length; i++) {
        if (uid.equals(_userid[i]) && password.equals(_password[i]))
            success = true;
    }

    if (!success)
        throw new AccessControlException("Failed to login.");

    HttpSession session = request.getSession();
    session.setAttribute("Uid", uid);
}

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

public static String getPath(Node node) {
    try {//  ww w  .  j  a va2s.  co m
        return node.getPath();
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to get the Path", e);
    }
}

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

public static String getIdentifier(Node node) {
    try {// ww  w. j  a  v  a  2 s.c o m
        return node.getIdentifier();
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to access identifier property of node: " + node, e);
    }
}

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

public static boolean isNodeType(Node node, String typeName) {
    try {/*  w ww  .  j av a 2 s .  com*/
        return node.getPrimaryNodeType().isNodeType(typeName);
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to retrieve the type of node: " + node, e);
    }
}