Example usage for java.lang SecurityException SecurityException

List of usage examples for java.lang SecurityException SecurityException

Introduction

In this page you can find the example usage for java.lang SecurityException SecurityException.

Prototype

public SecurityException(Throwable cause) 

Source Link

Document

Creates a SecurityException with the specified cause and a detail message of (cause==null ?

Usage

From source file:org.apache.hadoop.hive.llap.daemon.impl.LlapTokenChecker.java

public static void checkPermissions(LlapTokenInfo prm, String userName, String appId, Object hint) {
    if (userName == null) {
        assert StringUtils.isEmpty(appId);
        return;/*from w w w  . j a  v  a  2  s. c o  m*/
    }
    if (!checkTokenPermissions(userName, appId, prm.userName, prm.appId)) {
        throw new SecurityException("Unauthorized to access " + userName + ", " + appId + " (" + hint + ")");
    }
}

From source file:com.compomics.pladipus.controller.setup.InstallPladipus.java

private static boolean login(String user, String password) {
    boolean accept = false;
    UserService uService = UserService.getInstance();
    try {/*from  w w  w  . jav  a 2  s  .c om*/
        if (!uService.userExists(user)) {
            throw new SecurityException(user + " was not found !");
        } else if (uService.verifyUser(user, password)) {
            accept = true;
        } else {
            throw new SecurityException(user + " is not a authorized to push jobs !");
        }
    } catch (SQLException | UnsupportedEncodingException ex) {
        LOGGER.error(ex);
    }
    return accept;
}

From source file:FileErrorManager.java

/**
 * Performs the initialization for this object.
 *///w  w w .  j  a  va2  s .  c  o m
private void init() {
    if (next == null) {
        throw new NullPointerException(ErrorManager.class.getName());
    }

    File dir = this.emailStore;
    if (dir.getClass() != File.class) { //For security reasons.
        throw new IllegalArgumentException(dir.getClass().getName());
    }

    if (!dir.isDirectory()) {
        throw new IllegalArgumentException("File must be a directory.");
    }

    if (!dir.canWrite()) { //Can throw under a security manager.
        super.error(dir.getAbsolutePath(), new SecurityException("write"), ErrorManager.OPEN_FAILURE);
    }

    //For now, only absolute paths are allowed.
    if (!dir.isAbsolute()) {
        throw new IllegalArgumentException("Only absolute paths are allowed.");
    }

    if (!dir.canRead()) { //Can throw under a security manager.
        super.error(dir.getAbsolutePath(), new SecurityException("read"), ErrorManager.OPEN_FAILURE);
    }
}

From source file:it.smartcommunitylab.aac.apikey.APIKeyController.java

private String getClientId(HttpServletRequest request) {
    try {/* w  ww  .  j  av a2 s . co m*/
        String parsedToken = it.smartcommunitylab.aac.common.Utils.parseHeaderToken(request);
        if (parsedToken == null)
            throw new SecurityException("No clientId specified");
        OAuth2Authentication auth = resourceServerTokenServices.loadAuthentication(parsedToken);
        if (auth == null || auth.getUserAuthentication() != null)
            throw new SecurityException("Invalid token");
        String clientId = auth.getOAuth2Request().getClientId();
        return clientId;
    } catch (Exception e) {
        throw new SecurityException(e.getMessage());
    }
}

From source file:be.e_contract.mycarenet.etee.EncryptionToken.java

/**
 * RFC 3820/*from  w w  w.java2  s .co m*/
 * 
 * @param certificate
 * @param issuer
 */
private void verifyProxyCertificate(X509Certificate certificate, X509Certificate issuer) {
    try {
        certificate.verify(issuer.getPublicKey());
        issuer.checkValidity();
    } catch (Exception e) {
        throw new SecurityException("not a proxy certificate");
    }
}

From source file:com.kaliturin.blacklist.utils.Utils.java

/**
 * Makes file path if it doesn't exist//from  ww w.ja va  2s  .c om
 **/
public static boolean makeFilePath(File file) {
    String parent = file.getParent();
    if (parent != null) {
        File dir = new File(parent);
        try {
            if (!dir.exists() && !dir.mkdirs()) {
                throw new SecurityException("File.mkdirs() returns false");
            }
        } catch (SecurityException e) {
            Log.w(TAG, e);
            return false;
        }
    }

    return true;
}

From source file:org.jactr.tools.async.controller.RemoteIOHandler.java

final public void allowsListeners(IoSession session) {
    if (!isOwner(session) && !_allowListeners) {
        String message = "Listening is not permitted by anyone other than owner, closing " + session;
        session.write(new LoginAcknowledgedMessage(false, message));
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(message);/*from w  w  w  . ja v a  2s.c  om*/
        throw new SecurityException(message);
    }
}

From source file:org.nebulaframework.core.job.archive.GridArchive.java

/**
 * <b>Factory Method</b> to create a {@code GridArchive} instance for the
 * given {@code File} instance of a {@code .nar} file.
 * /*from  ww  w.ja v  a2  s.com*/
 * @param file
 *            {@code File} instance of {@code .nar} file.
 * 
 * @return {@code GridArchive} instance for given {@code .nar} file.
 * 
 * @throws GridArchiveException
 *             if processing of {@code File} failed.
 */
public static GridArchive fromFile(File file) throws GridArchiveException {
    try {
        // Assertions
        Assert.notNull(file);

        // Verify file integrity
        if (!verify(file)) {
            throw new SecurityException("Grid Archive Verification failed of " + file);
        }

        // Detect the GridJob Class names
        String[] jobClassNames = findJobClassNames(file);

        // Read byte[] from File
        byte[] bytes = IOSupport.readBytes(new FileInputStream(file));

        // Create and return GridArchive
        return new GridArchive(bytes, jobClassNames);

    } catch (Exception e) {
        throw new GridArchiveException("Cannot create Grid Archive", e);
    }
}

From source file:org.onecmdb.core.utils.wsdl.OneCMDBWebServiceImpl.java

public CiBean[] search(String auth, QueryCriteria criteria) {
    long start = System.currentTimeMillis();
    log.info("WSDL: search(" + auth + ", " + criteria + ")");

    ISession session = onecmdb.getSession(auth);
    if (session == null) {
        throw new SecurityException("No Session found! Try to do auth() first!");
    }/*from w w  w  . j ava 2  s.  c  o  m*/
    IModelService mService = (IModelService) session.getService(IModelService.class);
    QueryResult<ICi> result = mService.query(criteria);
    ArrayList<CiBean> resultList = new ArrayList<CiBean>();
    OneCmdbBeanProvider converter = new OneCmdbBeanProvider();

    long stop = System.currentTimeMillis();
    log.info("WSDL: search completed in " + (stop - start) + "ms returned + " + result.size() + " objects");
    start = stop;

    for (ICi ci : result) {
        // Convert ci to cibean.
        CiBean bean = converter.convertCiToBean(ci);
        resultList.add(bean);
    }

    stop = System.currentTimeMillis();
    log.info("WSDL: search convert completed in " + (stop - start) + "ms returned + " + result.size()
            + " beans");
    log.info("WSDL: " + BeanCache.getInstance().getStatistics());

    return (resultList.toArray(new CiBean[0]));
}

From source file:org.oscarehr.fax.admin.ManageFaxes.java

public ActionForward CancelFax(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {//from  w w  w .  j a  v a2s.co m

    String jobId = request.getParameter("jobId");

    if (!securityInfoManager.hasPrivilege(LoggedInInfo.getLoggedInInfoFromSession(request), "_admin", "w",
            null)) {
        throw new SecurityException("missing required security object (_admin)");
    }

    FaxJobDao faxJobDao = SpringUtils.getBean(FaxJobDao.class);
    FaxConfigDao faxConfigDao = SpringUtils.getBean(FaxConfigDao.class);

    FaxJob faxJob = faxJobDao.find(Integer.parseInt(jobId));

    FaxConfig faxConfig = faxConfigDao.getConfigByNumber(faxJob.getFax_line());

    DefaultHttpClient client = new DefaultHttpClient();

    String result = "{success:false}";

    log.info("TRYING TO CANCEL FAXJOB " + faxJob.getJobId());

    if (faxConfig.isActive()) {

        if (faxJob.getStatus().equals(FaxJob.STATUS.SENT)) {
            faxJob.setStatus(FaxJob.STATUS.CANCELLED);
            faxJobDao.merge(faxJob);
            result = "{success:true}";

        }

        if (faxJob.getJobId() != null) {

            if (faxJob.getStatus().equals(FaxJob.STATUS.WAITING)) {

                client.getCredentialsProvider().setCredentials(AuthScope.ANY,
                        new UsernamePasswordCredentials(faxConfig.getSiteUser(), faxConfig.getPasswd()));

                HttpPut mPut = new HttpPut(faxConfig.getUrl() + "/fax/" + faxJob.getJobId());
                mPut.setHeader("accept", "application/json");
                mPut.setHeader("user", faxConfig.getFaxUser());
                mPut.setHeader("passwd", faxConfig.getFaxPasswd());

                try {
                    HttpResponse httpResponse = client.execute(mPut);

                    if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

                        HttpEntity httpEntity = httpResponse.getEntity();
                        result = EntityUtils.toString(httpEntity);

                        faxJob.setStatus(FaxJob.STATUS.CANCELLED);
                        faxJobDao.merge(faxJob);
                    }

                } catch (ClientProtocolException e) {

                    log.error("PROBLEM COMM WITH WEB SERVICE");

                } catch (IOException e) {

                    log.error("PROBLEM COMM WITH WEB SERVICE");

                }
            }
        }
    }

    try {
        JSONObject json = JSONObject.fromObject(result);
        json.write(response.getWriter());

    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }

    return null;

}