我目前正在为学校项目,Spring Boot后端和AngularJS前端创建一个简单的应用程序,但是我似乎无法解决安全问题.
登录工作完美,但是当我输入错误的密码时,默认的登录弹出窗口显示出来,这有点烦人.我已经尝试了注释'BasicWebSecurity'并将httpBassic置于禁用状态,但没有结果(意味着登录过程根本不起作用).
我的安全类:
package be.italent.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.csrf.CsrfToken;
import org.springframework.security.web.csrf.CsrfTokenRepository;
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.WebUtils;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Autowired
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}
@Override …
Run Code Online (Sandbox Code Playgroud) java spring-security basic-authentication angularjs spring-boot
我目前正在编写一个小应用程序,通过下载last.fm生成的XML文件来显示当前在我的本地酒吧中播放的歌曲.
我遇到的问题如下:当与xml在线同步时,它没有获得新版本,而是一遍又一遍地使用第一个下载的xml.在此期间,在随机浏览器中打开此链接会产生正确的结果.可能是缓存或懒惰下载,我不知道.我也不知道这是否与ION有关.
我目前已经修复了一些代码,在下载之前清除了这个应用程序中的整个缓存,这很好用,但是因为我可能想扩展应用程序,所以我必须找到解决这个问题的另一种方法.
我的代码:
public class MainActivity extends Activity implements OnClickListener {
private final static String nonXML = {the url to my xml-file}
private String resultXml;
private TextView artistTextView, songTextView, albumTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
artistTextView = (TextView) findViewById(R.id.artistTextView);
songTextView = (TextView) findViewById(R.id.songTextView);
albumTextView = (TextView) findViewById(R.id.albumTextView);
Button mainButton = (Button) findViewById(R.id.mainButton);
mainButton.setOnClickListener(this);
}
@Override
protected void onResume() {
super.onResume();
update();
}
@Override
public void onClick(View v) {
update();
}
private void update() {
deleteCache(this);
getXML(); …
Run Code Online (Sandbox Code Playgroud) 我意识到这可能是一个骗局,但我花了几个小时寻找答案,似乎无法找到答案.
我目前正在创建一个检索Concert数据的Web API.
我有一个SQL Server表,它包含一个开始和结束日期,两者都作为一种datetime2
类型.我已经以这种格式插入了日期,它们在查看数据库时不会出现任何问题:
2015-10-08T20:00:00.0000000+01:00
Run Code Online (Sandbox Code Playgroud)
我的模特:
public class Concert
{
public int Id { get; set; }
public string Name { get; set; }
public int LocationId { get; set; }
[Column(TypeName = "DateTime2")]
public DateTime Start { get; set; }
[Column(TypeName = "DateTime2")]
public DateTime End { get; set; }
public string Description { get; set; }
public string Url { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的类中的方法会调出我的数据库数据:
public List<Concert> getAll()
{
List<Concert> concerts = new List<Concert>();
SqlConnection …
Run Code Online (Sandbox Code Playgroud) 我知道这个问题被问了很多,我冒着双重(或三重或四重)主题的风险,但提议的解决方案似乎对我不起作用。
我遇到了可怕的无法自动装配错误的麻烦。第一次从头开始搭建一个完整的Spring项目,所以我真的不知道是什么问题。
这是我当前的设置:ProjectRepo:
package be.italent.repo;
import be.italent.model.Project;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ProjectRepo extends JpaRepository<Project, Integer> {
}
Run Code Online (Sandbox Code Playgroud)
项目服务:
package be.italent.services;
import be.italent.model.Project;
import be.italent.repo.ProjectRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ProjectService {
@Autowired
private ProjectRepo projectRepo;
public List<Project> getAllProjects() {
return projectRepo.findAll();
}
}
Run Code Online (Sandbox Code Playgroud)
项目休息控制器:
package be.italent.controllers;
import java.util.ArrayList;
import be.italent.services.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import be.italent.model.Project;
@RestController
@RequestMapping("/projects")
public class ProjectRestController {
@Autowired
private ProjectService projectService;
@RequestMapping(method = RequestMethod.GET, …
Run Code Online (Sandbox Code Playgroud) 好的,这是交易:我有一个包含ImageView,TextView和IconTextView的列表.
TextView包含我想要垂直居中并紧贴TextView左侧的文本.但由于某种原因,它不适用于android:gravity ="center | left",也不适用于任何其他重力变化.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/task_item_item_layout"
android:background="?android:attr/activatedBackgroundIndicator" >
<ImageView
android:id="@+id/task_item_imageview"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/default_icon"
android:contentDescription="TODO"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:visibility="visible" />
<TextView
android:id="@+id/task_item_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:text="TODO"
android:textSize="15sp"
android:layout_toLeftOf="@+id/task_item_icontextview"
android:paddingLeft="4dp"
android:paddingRight="8dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_toRightOf="@+id/task_item_imageview"
android:gravity="center|left" />
<IconTextView
android:id="@+id/task_item_icontextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:visibility="gone"
android:gravity="center_horizontal"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
MinSDK = 14目标并编译SDK = 19
我发现了很多可能的答案,但是它们似乎没有用.有任何想法吗?
解
我将layout_height改为android:layout_height ="fill_parent"并添加了android:layout_centerVertical ="true",就像Apoorv所说.
<TextView
android:id="@+id/task_item_textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:text="Description"
android:textSize="15sp"
android:layout_toLeftOf="@+id/task_item_icontextview"
android:paddingLeft="4dp"
android:paddingRight="8dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_toRightOf="@+id/task_item_imageview"
android:gravity="center|left"
android:layout_centerVertical="true"/>
Run Code Online (Sandbox Code Playgroud)
像魅力一样工作!
我正在处理的应用程序应该使用http客户端检索json字符串,然后在应用程序中进行反序列化并使用它.
一切正常,除了等待功能.我做错了什么,我似乎无法弄清楚是什么.我如何确保我的DataService类等待,直到我有我的json并且它已被反序列化?
DataService类:
class DataService : IDataService
{
private IEnumerable<Concert> _concerts;
public DataService()
{
_concerts = new DataFromAPI()._concerts;
Debug.WriteLine("____Deserialization should be done before continuing____");
**other tasks that need the json**
}
}
Run Code Online (Sandbox Code Playgroud)
我的http客户端类:
class DataFromAPI
{
public IEnumerable<Concert> _concerts { get; set; }
public DataFromAPI()
{
Retrieve();
}
public async Task Retrieve()
{
try
{
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage();
var result = await client.GetAsync(new Uri("http://url-of-my-api"), HttpCompletionOption.ResponseContentRead);
string jsonstring = await result.Content.ReadAsStringAsync();
DownloadCompleted(jsonstring);
}
catch …
Run Code Online (Sandbox Code Playgroud) android ×2
c# ×2
java ×2
alignment ×1
android-ion ×1
angularjs ×1
async-await ×1
asynchronous ×1
autowired ×1
caching ×1
datetime ×1
datetime2 ×1
json ×1
last.fm ×1
spring ×1
spring-boot ×1
sql-server ×1
task ×1
textview ×1