📄 securitysail.java
字号:
throw new SailInternalException(e); } return si; } public StatementIterator getDirectSubPropertyOf(Resource subProperty, Resource superProperty) { StatementIterator si = baseRdfSchemaSource.getDirectSubPropertyOf(subProperty, superProperty); try { si = new StatementFilterIterator(si, this, Right.READ); } catch (Exception e){ throw new SailInternalException(e); } return si; } public boolean isSubPropertyOf(Resource subProperty, Resource superProperty) { boolean is = baseRdfSchemaSource.isSubPropertyOf(subProperty,superProperty); if ( is ) { is = is && isResourceAccessible(subProperty); is = is && isResourceAccessible(superProperty); } return is; } public boolean isDirectSubPropertyOf(Resource subProperty, Resource superProperty) { boolean is = baseRdfSchemaSource.isDirectSubPropertyOf(subProperty,superProperty); if ( is ) { is = is && isResourceAccessible(subProperty); is = is && isResourceAccessible(superProperty); } return is; } public StatementIterator getDomain(Resource prop, Resource domain) { StatementIterator si = baseRdfSchemaSource.getDomain(prop, domain); try { si = new StatementFilterIterator(si, this, Right.READ); } catch (Exception e) { throw new SailInternalException(e); } return si; } public StatementIterator getRange(Resource prop, Resource range) { StatementIterator si = baseRdfSchemaSource.getRange(prop, range); try { si = new StatementFilterIterator(si, this, Right.READ); } catch (Exception e) { throw new SailInternalException(e); } return si; } public StatementIterator getType(Resource anInstance, Resource aClass) { StatementIterator si = baseRdfSchemaSource.getType(anInstance, aClass); try { si = new StatementFilterIterator(si, this, Right.READ); } catch (Exception e) { throw new SailInternalException(e); } return si; } public StatementIterator getDirectType(Resource anInstance, Resource aClass) { StatementIterator si = baseRdfSchemaSource.getDirectType(anInstance, aClass); try { si = new StatementFilterIterator(si, this, Right.READ); } catch (Exception e) { throw new SailInternalException(e); } return si; } public boolean isType(Resource anInstance, Resource aClass) { boolean is = false; if (isResourceAccessible(anInstance) && isResourceAccessible(aClass)) { is = baseRdfSchemaSource.isType(anInstance,aClass); } return is; } public boolean isDirectType(Resource anInstance, Resource aClass) { boolean is = false; if (isResourceAccessible(anInstance) && isResourceAccessible(aClass)) { is = baseRdfSchemaSource.isDirectType(anInstance,aClass); } return is; } public LiteralIterator getLiterals( String label, String language, URI datatype) { // FIXME: do we need to filter this? return baseRdfSchemaSource.getLiterals(label, language, datatype); }/* < RDFSchemaSource implementation *//* > RDFRepository Implementation */ public void startTransaction() { baseRdfRepository.startTransaction(); // reset the query results since they might be inaccurate after the // transaction queryResults = new HashMap(); } public void commitTransaction() { String status = "" ; if (areThereTransients()) { // freeze THE UPDATE COUNTER if (null != versionMngmt) versionMngmt.pauseCounterIncrement(); baseRdfRepository.commitTransaction(); //start a new transaction to remove the irrelevant statements baseRdfRepository.startTransaction(); status = removeIrrelevantTransients(); // unFreeze the COUNTER if (null != versionMngmt) versionMngmt.continueCounterIncrement(); } // if there are transinients baseRdfRepository.commitTransaction(); if (status.length()>0) { ThreadLog.trace(status); throw new SailInternalException(status); } } public boolean transactionStarted() { return baseRdfRepository.transactionStarted(); } public void addStatement(Resource subj, URI pred, Value obj) throws SailUpdateException { baseRdfRepository.addStatement(subj,pred,obj); if (!isStatementAccessible(subj,pred,obj,Right.ADD)) { addTransient(subj,pred,obj); throw new SailUpdateException( "Statement Added temporarily.\n "+ "The permissions will be checked at the end of the transaction."); } }// public boolean addStatement(Resource subj, URI pred, Value obj, boolean// bExplicit) throws SailUpdateException {// return baseRdfRepository.addStatement(subj,pred,obj,bExplicit);// } public int removeStatements(Resource subj, URI pred, Value obj) throws SailUpdateException { StatementIterator si = baseRdfRepository.getStatements(subj,pred,obj); StatementFilterIterator sfi = null; try { sfi = new StatementFilterIterator(si,this,Right.REMOVE); } catch (Exception e) { throw new SailInternalException(e); } int removed = 0; while ( sfi.hasNext() ) { org.openrdf.model.Statement st = (org.openrdf.model.Statement) sfi.next(); removed += baseRdfRepository.removeStatements( st.getSubject(),st.getPredicate(),st.getObject()); } return removed; } public void clearRepository() throws SailUpdateException { if ( isRepositoryAccessible(Right.REMOVE) || isRepositoryAccessible(Right.ADMIN)) { baseRdfRepository.clearRepository(); } // if accessible else { throw new SailInternalException( "Cannot Clear the Repository. Access Denied."); } } public void changeNamespacePrefix(String namespace, String prefix) throws SailUpdateException { baseRdfRepository.changeNamespacePrefix(namespace, prefix); }/* > RDFRepository Implementation *//* > RDFSource Implementation */ public ValueFactory getValueFactory() { //FIXME: implement return null; } public StatementIterator getStatements(Resource subj, URI pred, Value obj) { StatementIterator si = baseRdfSource.getStatements(subj,pred,obj); try { si = new StatementFilterIterator(si,this,Right.READ); } catch (Exception e){ throw new SailInternalException(e); } return si; } public boolean hasStatement(Resource subj, URI pred, Value obj) { boolean has = baseRdfSource.hasStatement(subj,pred,obj); if ( has ) { has = has && isStatementAccessible(subj,pred,obj,Right.READ); } return has; } public NamespaceIterator getNamespaces() { return baseRdfSource.getNamespaces(); }/* < RDFSource Implementation */ public void initialize(Map configParams) throws SailInitializationException { ThreadLog.trace("initializing SecuritySail>>>"); // Get initialization parameters String jdbcDriver = (String)configParams.get("jdbcDriver"); String jdbcUrl = (String)configParams.get("jdbcUrl"); String user = (String)configParams.get("user"); String password = (String)configParams.get("password"); String securitySetup = (String)configParams.get("security_setup"); if (jdbcDriver == null) { throw new SailInitializationException("parameter 'jdbcDriver' missing"); } if (jdbcUrl == null) { throw new SailInitializationException("parameter 'jdbcUrl' missing"); } if (user == null) { throw new SailInitializationException("parameter 'user' missing"); } if (password == null) { throw new SailInitializationException("parameter 'password' missing"); } // Load jdbc driver try { Class.forName(jdbcDriver); } catch (ClassNotFoundException e) { throw new SailInitializationException( "Unable to load JDBC-driver '" + jdbcDriver + "'", e); } // Create ConnectionPool conPool = new ConnectionPool(jdbcUrl, user, password); // Initialize database schema, if necessary initDatabase(); Connection con = null; java.sql.Statement st = null; try { con = conPool.getConnection(); st = con.createStatement(); loadNameSpaceTable(con,st); loadResourcesTable(con,st); loadLiteralsTable(con,st); if ( null != securitySetup) { ThreadLog.trace("Loading Security Policy from url == "+securitySetup); /* * IMPORT SECURITY SETUP USING THE JENA DEPENDENT IMPORT * java.net.URL surl = new java.net.URL(securitySetup); * * BufferedReader br = new BufferedReader(new * InputStreamReader(surl.openStream())); * baseRdfRepository.startTransaction(); * * importSecurityPolicy(br); * baseRdfRepository.commitTransaction(); */ /* import security setup using the in-memory sail import */ java.net.URL surl = new java.net.URL(securitySetup); LocalService service = Sesame.getService(); LocalRepository repository = service.createRepository("tempSecurityRep", false); repository.addData(surl, "", RDFFormat.RDFXML, true, new XmlAdminMsgWriter(new FileOutputStream("ImportSecurityPolicy.Log"))); //org.openrdf.sesame.sailimpl.memory.RdfRepository memRepos; //Map map = new HashMap(); //map.put("file","TempSecurityPolicy.nt"); //memRepos= new org.openrdf.sesame.sailimpl.memory.RdfRepository(); //memRepos.initialize(map); //memRepos.clearRepository(); //RdfAdmin admin = new RdfAdmin(memRepos); //admin.addRdfModel(surl.openStream(),securitySetup , // new XmlAdminMsgWriter(), // true); baseRdfRepository.startTransaction(); importPolicy(repository.getGraph()); baseRdfRepository.commitTransaction(); service.removeRepository(repository.getRepositoryId()); repository = null; loadNameSpaceTable(con,st); loadResourcesTable(con,st); loadLiteralsTable(con,st); //Store the setup to the repository storeSecuritySetup(); } else { ThreadLog.trace("Loading Security Policy from the database"); loadSecuritySetup(); } } catch (Exception x) { throw new SailInternalException("While reading the security setup.",x); } ThreadLog.trace("<<<SecuritySail initialized successfully"); } // initialize(Map) public void shutDown() { baseSail.shutDown(); }/* < Sail Implementation *//* < RdfSchemaRepository implementation *//* < StackedSail implementation */ public void setBaseSail(Sail baseSail) { this.baseSail = baseSail; if (baseSail instanceof RdfSchemaSource ) baseRdfSchemaSource = (RdfSchemaSource)baseSail; if (baseSail instanceof RdfSource ) baseRdfSource = (RdfSource)baseSail; if (baseSail instanceof RdfRepository ) baseRdfRepository = (RdfRepository)baseSail; versionMngmt = (VersionManagement)org.openrdf.sesame.sail.util.QuerySailStack.queryInterface( baseSail, VERSION_SAIL); } public Sail getBaseSail() { return this.baseSail; }/* < StackedSail implementation *//* > Version Management implementation */ public void labelState(long stateUID, String label) { if ( isVersionTrackingAccessible() ) versionMngmt.labelState(stateUID, label); } public void labelCurrentState(String label) { if ( isVersionTrackingAccessible() ) versionMngmt.labelCurrentState(label) ; } public void revertToState(long stateUID) { if ( isVersionTrackingAccessible() ) versionMngmt.revertToState(stateUID); } public String branchState(long stateUID) { String result = ""; if ( isVersionTrackingAccessible() ) result = versionMngmt.branchState(stateUID); return result; } public void workWithState(long stateUID) { if ( isVersionTrackingAccessible() )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -