我正在使用Google的GSON库将字符串转换为JSON集合。
String tmp = ....;
Type collectionType = new TypeToken<ArrayList<Employee>>(){}.getType();
List<Employee> = gson.fromJson(tmp, collectionType);
Run Code Online (Sandbox Code Playgroud)
通过静态分析器运行它时,无法说明对gson的调用。fromJson违反了JSON Injection。
有人可以告诉我Gson lib是否安全吗?
我试图使用FullTextEntityManager(和Spring),但获得'会话已关闭'异常.我能够第一次查询,但第二次抛出异常.这是我的配置:
@Service
@Transactional(readOnly = true, propagation=Propagation.SUPPORTS)
public class SearchServiceImpl extends BaseService implements SearchService {
public List<StrainSearchResultsListItem> advancedSearch(Pageable page,String species) {
return searchRepository.advancedSearch(page, species);
}
Run Code Online (Sandbox Code Playgroud)
回购意见:
@Repository
@Transactional(readOnly = true)
public class SearchRepositoryImpl implements SearchRepository {
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
protected FullTextEntityManager getFullTextEntityManager() {
if (fullTextEntityManager == null) {
fullTextEntityManager = Search.getFullTextEntityManager(getEntityManager());
}
return fullTextEntityManager;
}
Run Code Online (Sandbox Code Playgroud)
一旦我第二次调用fullTestQuery.getResultList(),就会出现'Session is closed'异常.
FullTextQuery fullTextQuery =
getFullTextEntityManager()
.createFullTextQuery(booleanQuery, Strain.class);
fullTextQuery.getResultList()
Run Code Online (Sandbox Code Playgroud)
任何想法都表示赞赏.
谢谢
尝试为我的内容提供商设置同步适配器/服务.内容提供商工作正常,能够毫无问题地存储数据.
我有一个内容观察器,它在我的内容解析器中注册,并且在数据更改后调用onChange方法.
但是,在我调用observer.onChange之后,日志中没有任何内容出现.在observer.onChange中,我调用了contentResolver.requestSync,但是没有调用同步适配器中的onPerformSync方法.
想法?
syncadapter.xml
<sync-adapter
xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="....contentproviderexample.provider"
android:accountType="....contentproviderexample"
android:userVisible="false"
android:supportsUploading="false"
android:allowParallelSyncs="false"
android:isAlwaysSyncable="true"/>
Run Code Online (Sandbox Code Playgroud)
authenticator.xml
<account-authenticator
android:label="@string/app_name"
android:smallIcon="@mipmap/ic_launcher"
android:icon="@mipmap/ic_launcher"
android:accountType="....contentproviderexample"
xmlns:android="http://schemas.android.com/apk/res/android"/>
Run Code Online (Sandbox Code Playgroud)
观察者改变:
@Override
public void onChange(boolean selfChange, Uri uri) {
Log.d(PERSON_OBSERVER_TAG, "onChange: Calling requestSync");
contentResolver.requestSync(newAccount, PersonContract.CONTENT_AUTHORITY, Bundle.EMPTY);
}
Run Code Online (Sandbox Code Playgroud)
表现:
<service android:name=".datasync.AuthenticatorService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"></action>
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator"/>
</service>
<service android:name=".datasync.SyncService"
android:exported="true"
android:process=":sync">
<intent-filter>
<action android:name="android.content.SyncAdapter"/>
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter">
</meta-data>
</service>
Run Code Online (Sandbox Code Playgroud) 我正在使用Spring Data REST,我的存储库中有一个find方法:
public List<Contact> findByLastNameOrderByLastNameAsc(@Param("lastName") String lastName);
Run Code Online (Sandbox Code Playgroud)
我试图为方法添加安全性,但没有运气.在我的数据库中,我有一个用户角色为'ROLE_USER'.当服务启动时,登录表单出现,我可以使用数据库中的凭据登录.
这是我的网络安全配置:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("select username,identification,enabled from users where username = ?");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/contacts/findByLastNameOrderByLastNameAsc").hasRole("ADMIN")
.antMatchers("/contacts/**").fullyAuthenticated()
.antMatchers("/contacts/**").hasRole("USER")
.anyRequest().authenticated()
.and()
.formLogin();
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在我的存储库中调用服务时,我没有看到任何身份验证错误.使用我的浏览器,即使数据库中的用户没有"ADMIN"角色,URL也会正常显示.
我尝试将'RolesAllowed'添加到我的存储库中的方法,但没有运气:
@RolesAllowed(value = { "ADMIN" })
public List<Contact> findByLastNameOrderByLastNameAsc(@Param("lastName") String lastName);
Run Code Online (Sandbox Code Playgroud)
我是否要正确地为Spring Data提供的REST API添加安全性?如何让这个工作的想法?
谢谢