私はアンドロイドアプリケーションで休憩APIを持つスプリングバックエンドを使用して、ユーザー名とパスワードフィールドでユーザーを認証しています。春のセキュリティからのアプリケーションの認証
私はpostmanのようなrest-clientで認証したときに認証されます。
は、ここで私の郵便配達スナップショット
私は両方のケースで、この結果を取得していますURLまたは身体にパラメータを渡すのいずれかです。
しかし、私は私のクライアント側の呼び出しがボレーライブラリを使用している。ここ
404を取得しています私のAndroidアプリからそれを呼び出している間
ここprivate void callLoginVolley() {
try {
RequestQueue requestQueue = Volley.newRequestQueue(this);
String URL = AppConstants.BASE_URL + AppConstants.ADMIN_LOGIN;//+"email="+username.getText().toString()+"&password="+password.getText().toString();
Log.i("url", String.valueOf(URL));
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "failed!", Toast.LENGTH_LONG).show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> pars = new HashMap<String, String>();
pars.put("Content-Type", "application/x-www-form-urlencoded");
return pars;
}
@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
params.put("email", username.getText().toString()); //Add the data you'd like to send to the server.
params.put("password", password.getText().toString());
Log.d("myData", "->" + params);
return params;
}
};
requestQueue.add(stringRequest);
} catch (Exception e) {
e.printStackTrace();
}
}
私の春のセキュリティコードがある
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().usersByUsernameQuery(usersQuery).authoritiesByUsernameQuery(rolesQuery)
.dataSource(dataSource).passwordEncoder(bCryptPasswordEncoder);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/").permitAll().antMatchers("/login", "/loginfailure").permitAll()
.antMatchers("/registration").permitAll().antMatchers("/admin/**").hasAuthority("ADMIN").anyRequest()
.authenticated().and().csrf().disable()
.formLogin().loginPage("/login")
.failureUrl("/loginfailure")
.defaultSuccessUrl("/loginsucess")
.usernameParameter("email")
.passwordParameter("password")
.and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/").and()
.exceptionHandling().accessDeniedPage("/access-denied");
}
ここに私のsuccesと失敗の残りの部分ですオールズ
@RequestMapping(value="/loginsucess", method = RequestMethod.GET)
public ResponseEntity<Object> loginSuccess() {
Map response = new HashMap<>();
/*Set some session variables*/
Object authUser = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
response.put("username", authUser);
response.put("authorities", SecurityContextHolder.getContext().getAuthentication().getAuthorities());
response.put("status", "success");
ResponseEntity<Object> responseEntity= new ResponseEntity<Object>(response,HttpStatus.OK);
logger.info("response"+responseEntity);
return responseEntity;
}
/LoginFailureを
@RequestMapping(value="/loginfailure", method = RequestMethod.GET)
public ResponseEntity<Object> loginFailure() {
Map response = new HashMap<>();
response.put("status", "login failed");
ResponseEntity<Object> responseEntity= new ResponseEntity<Object>(response,HttpStatus.OK);
logger.info("response"+responseEntity);
return responseEntity;
}
私はあなたの返事を楽しみにしています... antMatchersで
あなたの問題を解決しました – Mohammad