java.lang.SecurityException Java Examples

The following examples show how to use java.lang.SecurityException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: constructor.java    From pluotsorbet with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    SecurityException object1 = new SecurityException();
    harness.check(object1 != null);
    harness.check(object1.toString(), "java.lang.SecurityException");

    SecurityException object2 = new SecurityException("nothing happens");
    harness.check(object2 != null);
    harness.check(object2.toString(), "java.lang.SecurityException: nothing happens");

    SecurityException object3 = new SecurityException((String)null);
    harness.check(object3 != null);
    harness.check(object3.toString(), "java.lang.SecurityException");


}
 
Example #2
Source File: RawStore.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private synchronized String privGetCanonicalPath(final File file)
{
    actionCode = REGULAR_FILE_GET_CANONICALPATH_ACTION;
    actionRegularFile = file;

    try
    {
        return (String) AccessController.doPrivileged( this);
    }
    catch( PrivilegedActionException pae) { 
        return null;
    } // does not throw an exception
    catch(SecurityException se) { 
        // there are no permission to get canonical path 
        // just return null.
        return null;
    }
    finally
    {
        actionRegularFile = null;
    }
}
 
Example #3
Source File: RawStore.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private synchronized String privGetCanonicalPath(final StorageFile file)
{
    actionCode = STORAGE_FILE_GET_CANONICALPATH_ACTION;
    actionStorageFile = file;

    try
    {
        return (String) AccessController.doPrivileged( this);
    }
    catch( PrivilegedActionException pae) { 
        return null;
    } // does not throw an exception
    catch(SecurityException se) {
        // there are no permission to get canonical path 
        // just return null.
        return null;
    }
    finally
    {
        actionStorageFile = null;
    }
}
 
Example #4
Source File: RawStore.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private synchronized String privGetCanonicalPath(final File file)
{
    actionCode = REGULAR_FILE_GET_CANONICALPATH_ACTION;
    actionRegularFile = file;

    try
    {
        return (String) AccessController.doPrivileged( this);
    }
    catch( PrivilegedActionException pae) { 
        return null;
    } // does not throw an exception
    catch(SecurityException se) { 
        // there are no permission to get canonical path 
        // just return null.
        return null;
    }
    finally
    {
        actionRegularFile = null;
    }
}
 
Example #5
Source File: RawStore.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private synchronized String privGetCanonicalPath(final StorageFile file)
{
    actionCode = STORAGE_FILE_GET_CANONICALPATH_ACTION;
    actionStorageFile = file;

    try
    {
        return (String) AccessController.doPrivileged( this);
    }
    catch( PrivilegedActionException pae) { 
        return null;
    } // does not throw an exception
    catch(SecurityException se) {
        // there are no permission to get canonical path 
        // just return null.
        return null;
    }
    finally
    {
        actionStorageFile = null;
    }
}
 
Example #6
Source File: SaveFileHelper.java    From Java2PlantUML with Apache License 2.0 5 votes vote down vote up
private static String getPathName(String route) throws IOException {
   if (route == null) {
      route = TARGET_DIRECTORY;
   }
   File file = new File(route);
   if (file.exists() && !file.isDirectory()) {
      throw new IOException("File " + route + " exists but it is not a directory");
   }
   else if (!file.exists()) { // path does not yet exist
      try {
         if (!file.mkdir()) {
            throw new IOException("Error creating directory " + route);
         }
      }
      catch (SecurityException se) {
         throw new IOException("Security Exception creating " + route);
      }
   }
   StringBuilder path = new StringBuilder().append(route).append(File.separator).append(J2PUML);

   SimpleDateFormat instant = new SimpleDateFormat("ddMMyyyy_HM_mm", Locale.getDefault());
   Date now = new Date();
   StringBuilder fileName = new StringBuilder(instant.format(now));

   path.append(fileName).append("." + FILE_EXTENSION);
   return path.toString();
}
 
Example #7
Source File: LocalFileStreamSourceTest.java    From samoa with Apache License 2.0 5 votes vote down vote up
private void writeSimpleFiles(String path, String ext, int numOfFiles) {
	// Create folder
	File folder = new File(path);
	if (!folder.exists()) {
		try{
	        folder.mkdir();
	    } catch(SecurityException se){
	    	fail("Failed creating directory:"+path+se);
	    }
	}
	
	// Write files
	for (int i=1; i<=numOfFiles; i++) {
		String fn = null;
		if (ext != null) {
			fn = Integer.toString(i) + "."+ ext;
		} else {
			fn = Integer.toString(i);
		}
		
		try {
			FileWriter fwr = new FileWriter(new File(path,fn));
			fwr.write(Integer.toString(i));
			fwr.close();
		} catch (IOException ioe) {
			fail("Fail writing to input file: "+ fn + " in directory: " + path + ioe.getMessage());
		}
	}
}
 
Example #8
Source File: TryCatch.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    // flag that is set when exception is caught
    boolean caught = false;
    try {
        throw new SecurityException("SecurityException");
    }
    catch (SecurityException e) {
        // correct exception was caught
        caught = true;
    }
    harness.check(caught);
}
 
Example #9
Source File: LocalFileStreamSourceTest.java    From incubator-samoa with Apache License 2.0 5 votes vote down vote up
private void writeSimpleFiles(String path, String ext, int numOfFiles) {
  // Create folder
  File folder = new File(path);
  if (!folder.exists()) {
    try {
      folder.mkdir();
    } catch (SecurityException se) {
      fail("Failed creating directory:" + path + se);
    }
  }

  // Write files
  for (int i = 1; i <= numOfFiles; i++) {
    String fn = null;
    if (ext != null) {
      fn = Integer.toString(i) + "." + ext;
    } else {
      fn = Integer.toString(i);
    }

    try {
      FileWriter fwr = new FileWriter(new File(path, fn));
      fwr.write(Integer.toString(i));
      fwr.close();
    } catch (IOException ioe) {
      fail("Fail writing to input file: " + fn + " in directory: " + path + ioe.getMessage());
    }
  }
}
 
Example #10
Source File: derbyrunjartest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception
{
    // get location of run class.
    CodeSource cs = null;
    try {
        cs = com.pivotal.gemfirexd.internal.iapi.tools.run.class.getProtectionDomain().getCodeSource();
    } catch (SecurityException se) {
        System.out.println("Security exception: " + se.getMessage());
    }
 
    URL result = cs.getLocation();
    jvm jvm = null;
    String derbyrunloc = null;

    if (result.toString().endsWith(".jar")) {
        derbyrunloc = result.toString().substring(5);
        if (System.getProperty("os.name").startsWith("Windows"))
          derbyrunloc = derbyrunloc.substring(1);
        jvm = jvm.getJvm("currentjvm"); // ensure compatibility
    }

    String[][] testCommands = new String[][] {
        {"ij", "--help"},
        {"sysinfo", "-cp", "help"},
        {"dblook"},
        {"server"},
    };

    for (int i = 0; i < testCommands.length; i++) {
        runtool(jvm, derbyrunloc, testCommands[i]);
    }
}
 
Example #11
Source File: derbyrunjartest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception
{
    // get location of run class.
    CodeSource cs = null;
    try {
        cs = com.pivotal.gemfirexd.internal.iapi.tools.run.class.getProtectionDomain().getCodeSource();
    } catch (SecurityException se) {
        System.out.println("Security exception: " + se.getMessage());
    }
 
    URL result = cs.getLocation();
    jvm jvm = null;
    String derbyrunloc = null;

    if (result.toString().endsWith(".jar")) {
        derbyrunloc = result.toString().substring(5);
        if (System.getProperty("os.name").startsWith("Windows"))
          derbyrunloc = derbyrunloc.substring(1);
        jvm = jvm.getJvm("currentjvm"); // ensure compatibility
    }

    String[][] testCommands = new String[][] {
        {"ij", "--help"},
        {"sysinfo", "-cp", "help"},
        {"dblook"},
        {"server"},
    };

    for (int i = 0; i < testCommands.length; i++) {
        runtool(jvm, derbyrunloc, testCommands[i]);
    }
}
 
Example #12
Source File: ClassSizeCrawler.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private void crawl( File curDir, StringBuilder className)
{
    if( verbose)
        System.out.println( "Searching directory " + curDir.getPath());

    try
    {
        if( ! curDir.isDirectory())
        {
            System.err.println( "*** " + curDir.getPath() + " is not a directory.");
            System.exit(1);
        }
    }
    catch( SecurityException se)
    {
        System.err.println( "Cannot access " + curDir.getPath());
        System.exit(1);
    }
    String[] filenames = curDir.list( );
    if( className.length() != 0)
        className.append( ".");

    int classNameLength = className.length();
    for( int fileIdx = 0; fileIdx < filenames.length; fileIdx++)
    {
        if( filenames[fileIdx].endsWith( ".class"))
        {
            // Strip off the ".class" suffix
            String s = filenames[fileIdx].substring( 0, filenames[fileIdx].length() - 6);
            className.append( s);
            Class targetClass = null;
            String targetClassName = className.toString();
            try
            {
                targetClass = Class.forName( targetClassName);
                if( !targetClass.isInterface())
                {
                    for( int interfaceIdx = 0; interfaceIdx < interfaceCount; interfaceIdx++)
                    {
                        if( interfaceList[interfaceIdx].isAssignableFrom( targetClass))
                            addClass( targetClass);
                    }
                }
            }
            catch( ClassNotFoundException cnfe)
            {
                System.err.println( "Could not find class " + targetClassName);
                System.exit(1);
            }
            catch( Throwable t){}
            className.setLength( classNameLength);
        }
        else
        {
            File nextDir = new File( curDir, filenames[fileIdx]);
            if( nextDir.isDirectory())
            {
                className.append( filenames[fileIdx]);
                crawl( nextDir, className);
                className.setLength( classNameLength);
            }
        }
    }
}
 
Example #13
Source File: SecurityDomain.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** Get the TrustManagerFactory associated with the security domain */
public TrustManagerFactory getTrustManagerFactory() throws SecurityException;
 
Example #14
Source File: SecurityDomain.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** Get the KeyManagerFactory associated with the security domain */
public KeyManagerFactory getKeyManagerFactory() throws SecurityException;
 
Example #15
Source File: ClassSizeCrawler.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private void crawl( File curDir, StringBuilder className)
{
    if( verbose)
        System.out.println( "Searching directory " + curDir.getPath());

    try
    {
        if( ! curDir.isDirectory())
        {
            System.err.println( "*** " + curDir.getPath() + " is not a directory.");
            System.exit(1);
        }
    }
    catch( SecurityException se)
    {
        System.err.println( "Cannot access " + curDir.getPath());
        System.exit(1);
    }
    String[] filenames = curDir.list( );
    if( className.length() != 0)
        className.append( ".");

    int classNameLength = className.length();
    for( int fileIdx = 0; fileIdx < filenames.length; fileIdx++)
    {
        if( filenames[fileIdx].endsWith( ".class"))
        {
            // Strip off the ".class" suffix
            String s = filenames[fileIdx].substring( 0, filenames[fileIdx].length() - 6);
            className.append( s);
            Class targetClass = null;
            String targetClassName = className.toString();
            try
            {
                targetClass = Class.forName( targetClassName);
                if( !targetClass.isInterface())
                {
                    for( int interfaceIdx = 0; interfaceIdx < interfaceCount; interfaceIdx++)
                    {
                        if( interfaceList[interfaceIdx].isAssignableFrom( targetClass))
                            addClass( targetClass);
                    }
                }
            }
            catch( ClassNotFoundException cnfe)
            {
                System.err.println( "Could not find class " + targetClassName);
                System.exit(1);
            }
            catch( Throwable t){}
            className.setLength( classNameLength);
        }
        else
        {
            File nextDir = new File( curDir, filenames[fileIdx]);
            if( nextDir.isDirectory())
            {
                className.append( filenames[fileIdx]);
                crawl( nextDir, className);
                className.setLength( classNameLength);
            }
        }
    }
}
 
Example #16
Source File: SecurityDomain.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/** Get the keystore associated with the security domain */
public KeyStore getKeyStore() throws SecurityException;
 
Example #17
Source File: PublishedAssessmentEntityProviderImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public List getEntities(EntityReference ref, Search search){
 Vector results = new Vector();
 

 String siteId = null;
 Restriction[] restrictions = search.getRestrictions();

    String userId = null;	  
 
 for(int r=0;r<restrictions.length;r++){
  if(restrictions[r].property.equalsIgnoreCase("siteId")){
	  siteId = (String) restrictions[r].value;
  }
  if(restrictions[r].property.equalsIgnoreCase("userId")){
	  userId = (String) restrictions[r].value;
  }
  if(restrictions[r].property.equalsIgnoreCase("context")){
	  siteId = (String) restrictions[r].value;
  }		  
 }

 if(userId==null){
  userId = developerHelperService.getCurrentUserId();
 }
    if (userId == null) {
        throw new SecurityException("No user is currently logged in so no data can be retrieved");
    }
 
 if(userId==null)return results;
 if(siteId==null) return results;
  String orderBy = "title";
  List assessments = null;
  boolean canPublish = false;
  Date currentDate = new Date();

   // Check what the user can do
   if (securityService.unlock(CAN_PUBLISH, "/site/"+siteId)) {
     publishedAssessmentFacadeQueries.
       getBasicInfoOfAllActivePublishedAssessments(orderBy, siteId, true);
     assessments = publishedAssessmentFacadeQueries
       .getBasicInfoOfAllInActivePublishedAssessments(orderBy, siteId, true);
     assessments.addAll(publishedAssessmentFacadeQueries
       .getBasicInfoOfAllActivePublishedAssessments(orderBy, siteId, true));
     canPublish = true;
   }
   else if (securityService.unlock(CAN_TAKE, "/site/"+siteId)) {
     assessments = publishedAssessmentFacadeQueries
       .getBasicInfoOfAllActivePublishedAssessments(orderBy, siteId, true);
   }

if (assessments != null) {
	Iterator assessmentIterator = assessments.iterator();
	while(assessmentIterator.hasNext()){
		PublishedAssessmentFacade pub = (PublishedAssessmentFacade) assessmentIterator.next();
		results.add(pub);

	}
}
 return results;
}
 
Example #18
Source File: PublishedAssessmentEntityProviderImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public List getEntities(EntityReference ref, Search search){
 Vector results = new Vector();
 

 String siteId = null;
 Restriction[] restrictions = search.getRestrictions();

    String userId = null;	  
 
 for(int r=0;r<restrictions.length;r++){
  if(restrictions[r].property.equalsIgnoreCase("siteId")){
	  siteId = (String) restrictions[r].value;
  }
  if(restrictions[r].property.equalsIgnoreCase("userId")){
	  userId = (String) restrictions[r].value;
  }
  if(restrictions[r].property.equalsIgnoreCase("context")){
	  siteId = (String) restrictions[r].value;
  }		  
 }

 if(userId==null){
  userId = developerHelperService.getCurrentUserId();
 }
    if (userId == null) {
        throw new SecurityException("No user is currently logged in so no data can be retrieved");
    }
 
 if(userId==null)return results;
 if(siteId==null) return results;
  String orderBy = "title";
  List assessments = null;
  boolean canPublish = false;
  Date currentDate = new Date();

   // Check what the user can do
   if (securityService.unlock(CAN_PUBLISH, "/site/"+siteId)) {
     publishedAssessmentFacadeQueries.
       getBasicInfoOfAllActivePublishedAssessments(orderBy, siteId, true);
     assessments = publishedAssessmentFacadeQueries
       .getBasicInfoOfAllInActivePublishedAssessments(orderBy, siteId, true);
     assessments.addAll(publishedAssessmentFacadeQueries
       .getBasicInfoOfAllActivePublishedAssessments(orderBy, siteId, true));
     canPublish = true;
   }
   else if (securityService.unlock(CAN_TAKE, "/site/"+siteId)) {
     assessments = publishedAssessmentFacadeQueries
       .getBasicInfoOfAllActivePublishedAssessments(orderBy, siteId, true);
   }

if (assessments != null) {
	Iterator assessmentIterator = assessments.iterator();
	while(assessmentIterator.hasNext()){
		PublishedAssessmentFacade pub = (PublishedAssessmentFacade) assessmentIterator.next();
		results.add(pub);

	}
}
 return results;
}
 
Example #19
Source File: JSSESecurityDomain.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/** 
 * Get the keystore associated with the security domain
 * 
 * @return the keystore
 */
public KeyStore getKeyStore() throws SecurityException;
 
Example #20
Source File: SecurityDomain.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/** Get the truststore associated with the security domain. This may be
 the same as the keystore. */
public KeyStore getTrustStore() throws SecurityException;
 
Example #21
Source File: JSSESecurityDomain.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the TrustManagers created by the configured TrustManagerFactory
 * 
 * @return the initialized TrustManagers
 */
public TrustManager[] getTrustManagers() throws SecurityException;
 
Example #22
Source File: JSSESecurityDomain.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the truststore associated with the security domain. This may be the same as the keystore
 * 
 * @return the truststore
 */
public KeyStore getTrustStore() throws SecurityException;
 
Example #23
Source File: AutoConnectionTrackerTest.java    From tomee with Apache License 2.0 2 votes vote down vote up
@Override
public void close() throws SecurityException {

}
 
Example #24
Source File: JSSESecurityDomain.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the KeyManagers created by the configured KeyManagerFactory
 * 
 * @return the initialized KeyManagers
 */
public KeyManager[] getKeyManagers() throws SecurityException;