小编pis*_*ise的帖子

org.springframework.security.core.userdetails.User无法强制转换为MyUserDetails

当我实现Spring安全性的User类时,我得到了类转换异常.我想在MyUserDetails(id)中添加一些额外的细节,但我无法得到结果.

这个问题在这里得到解答,但后来两个我收到错误,不知道我在哪里失踪.

以下是我的代码:

SecurityConfig.java:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    @Qualifier("authenticationProvider")
    AuthenticationProvider authenticationProvider;

    @Autowired
    DataSource dataSource;

    @Autowired
    public void configAuthentication(AuthenticationManagerBuilder auth)
            throws Exception {

        auth.jdbcAuthentication()
                .dataSource(dataSource)
                .passwordEncoder(passwordEncoder())
                .usersByUsernameQuery(
                        "select username,password, enabled from users where username=?")
                .authoritiesByUsernameQuery(
                        "select username, role from user_roles where username=?");

    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        PasswordEncoder encoder = new BCryptPasswordEncoder();
        return encoder;
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.headers().cacheControl().and().xssProtection().and()
                .frameOptions().and();

        http.authorizeRequests()
                .antMatchers("/sadmin/**")
                .access("hasRole('ROLE_SADMIN')")
                .antMatchers("/admin/**")
                .access("hasRole('ROLE_ADMIN') or …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc spring-security

19
推荐指数
2
解决办法
2万
查看次数

关于Bootstrap模式的Ckeditor下拉问题(点击后立即打开和关闭)

我在bootstrap模式中打开了ckeditor但是格式和大小下拉不能正常工作.当我点击大小或格式下拉它立即打开和关闭时,我读到它是ckeditor中的bootstrap模式的一个错误.我在网上找到了解决方案,但这不起作用.

解决方案我在网上发现并且没有工作: -

    $.fn.modal.Constructor.prototype.enforceFocus = function() {
    modal_this = this
    $(document).on('focusin.modal', function(e) {
        if (modal_this.$element[0] !== e.target && !modal_this.$element.has(e.target).length &&
            !$(e.target.parentNode).hasClass('cke_dialog_ui_input_select') &&
            !$(e.target.parentNode).hasClass('cke_dialog_ui_input_text')) {
            modal_this.$element.focus()
        }
    })
  };
Run Code Online (Sandbox Code Playgroud)

我从哪里调用jsp和ck编辑器:

  $scope.emailMsgSetting = function(msgId, headerName) {
  $ocLazyLoad.load({
      name: 'emailSettingsModule',
      files: ['/doc/jsp/portal/viewMessageSettings.js']
  }).then(function() {
      var url = makeURL("/doc/jsp/portal/viewMessageSettings.jsp?");
      $scope.dataURL = url;
  }, function(e) {
      console.log(e);
  });
}
Run Code Online (Sandbox Code Playgroud)

JSP我在哪里实现了ck编辑器

<div class="col-sm-11 nopadright" ng-if="showckeditor">
   <textarea ng-model="$parent.msgTypeBody" ck-editor insert-tag="strTagName" height="ckEditorheight" extra-plugins= "strTagName"></textarea> 
  </div>
Run Code Online (Sandbox Code Playgroud)

谢谢..

jsp ckeditor4.x

12
推荐指数
1
解决办法
564
查看次数

Spring security从数据库授权Requests值

我想在服务器启动时从数据库配置Authorize Requests值.目前我在Java类文件中给出了硬核值,有没有办法从数据库中读取相同内容.

以下是示例代码:

protected void configure(HttpSecurity http) throws Exception {
http
    .authorizeRequests()                                                                
        .antMatchers("/resources/**", "/signup", "/about").permitAll()                  
        .antMatchers("/admin/**").hasRole("ADMIN")                                      
        .antMatchers("/db/**").access("hasRole('ADMIN') and hasRole('DBA')")            
        .anyRequest().authenticated()                                                   
        .and()
    // ...
    .formLogin();
}
Run Code Online (Sandbox Code Playgroud)

如何从数据库中读取url,例如:/ admin/**,而不是类文件中的硬编码值

java spring-mvc spring-security

9
推荐指数
1
解决办法
3124
查看次数

JPQL 右连接

经过搜索,我才知道 JPQL 中没有 Right Join。我看到有另一种方法可以使用 JPA 双向(不是右连接,而是使用 pojo 对象)来实现它,但是我在控制台中注意到一件事,它对数据库进行了多次调用,例如见下表。

       Flat Table                   UserToFlat                    User
| Flat_ID  |  Flat No  |      | ID   |  Flat_ID | User_ID |    | User_ID | Name |
|  1       |    101    |      | 1    |    1     |  1      |    |   1     | XYZ  |  
|  2       |    102    |      | 2    |    2     |  2      |    |   2     | PQR  |
|  3       |    103    |      | 3    |    3     |  3      |    |   3     | …
Run Code Online (Sandbox Code Playgroud)

hibernate jpql jpa-2.0 right-join

5
推荐指数
1
解决办法
8810
查看次数

没有派生表的查询

我有两个表平和usertoflat我想从平面表获取所有数据与usertoflat表上的条件.

我正在使用JPA,但我没有在jpa中找到派生表查询是我的本机sql查询.

Table Flat

flat_id | flat_no | status
   1    |   1001  |   1
   2    |   1002  |   1
   3    |   1003  |   1
   4    |   1004  |   1


Table usertoflat

usertoflat_id | Name    | flat_id | status
      1       | ABC     |   1     |   1
      2       | ABC     |   1     |   2
      3       | XYZ     |   2     |   1
      4       | PQR     |   3     |   1


Required output

flat_id | flat_no | Name
   1    |   1001  | ABC
   2    | …
Run Code Online (Sandbox Code Playgroud)

mysql jpa-2.0

5
推荐指数
1
解决办法
72
查看次数

选择Jquery Datatables中的所有行

我有一个数据表,我可以在其中选择多行onclick但是如何在点击按钮上选择所有行,同时所有行都用选择突出显示(你能不能给出当前页面选择的例子和所有页).我编写了一个代码来获取多个选定值.

Checkbox也会这样做但是如何获得选定的值.

以下是单选和多选的代码.

 var oTable = $("#example").dataTable();

    $('#example tbody').on('click', 'tr', function() {
                        $(this).toggleClass('selected');

    });
Run Code Online (Sandbox Code Playgroud)

用于在按钮提交时获取所选值的代码.

var row = oTable.rows('.selected').data();

var jsonArr = "[";

        if(row != null && row.length){

            for (var i = 0; i < row.length; i++) {
                var row1 = row[i]; // this will give me one row details
                        // row1[0] will give me column details
                        jsonArr = jsonArr + "{\"ID\":" + row1[0] + "},";

                }   
             jsonArr = jsonArr + "]";
Run Code Online (Sandbox Code Playgroud)

jquery datatables

2
推荐指数
1
解决办法
2万
查看次数

在4名玩家中随机分配52张牌

我想在4名玩家中随机分配52张牌.我虽然我会将每张卡放入HashMap,因为hashmap是无序的和未排序的,然后遍历它并将第1张13张牌分配给玩家1,最后13张牌分配给玩家4.但是当我遍历hashmap时,值总是相同的,我希望每次迭代的值都应该是不同的.下面是使用6号和输出相同的例子.

    public static void main(String[] args) {

    Map<String,String> map = new HashMap<String,String>();
    map.put("1", "one");
    map.put("2", "two");
    map.put("3", "three");
    map.put("4", "four");
    map.put("5", "five");
    map.put("6", "six");

    for(Iterator<Entry<String, String>> iterator =  map.entrySet().iterator(); iterator.hasNext();){
        Entry<String,String> entry = iterator.next();
        System.out.print(entry.getKey()+" "+ entry.getValue() +"\n");
    }

}


Output
3 three
2 two
1 one
6 six
5 five
4 four
Run Code Online (Sandbox Code Playgroud)

N次运行代码但输出在我的机器中始终相同.我希望每次运行都有不同的输出.请指教.

java collections

0
推荐指数
1
解决办法
619
查看次数