/*
 * Copyright 2014-2016 Hewlett-Packard Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

package com.hp.autonomy.frontend.find.idol.beanconfiguration;

import com.google.common.collect.ImmutableMap;
import com.hp.autonomy.frontend.configuration.authentication.OneToOneOrZeroSimpleAuthorityMapper;
import com.hp.autonomy.frontend.find.core.beanconfiguration.BiConfiguration;
import com.hp.autonomy.frontend.find.core.beanconfiguration.FindRole;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;

@Configuration
public class UserConfiguration {
    public static final String IDOL_USER_ROLE = "FindUser";
    public static final String IDOL_ADMIN_ROLE = "FindAdmin";
    public static final String IDOL_BI_ROLE = "FindBI";

    @Value("${" + BiConfiguration.BI_PROPERTY + '}')
    private boolean enableBi;

    @Bean
    public GrantedAuthoritiesMapper grantedAuthoritiesMapper() {
        final ImmutableMap.Builder<String, String> rolesMapBuilder = ImmutableMap.<String, String>builder()
            .put(IDOL_USER_ROLE, FindRole.USER.toString())
            .put(IDOL_ADMIN_ROLE, FindRole.ADMIN.toString());

        if (enableBi) {
            rolesMapBuilder.put(IDOL_BI_ROLE, FindRole.BI.toString());
        }

        return new OneToOneOrZeroSimpleAuthorityMapper(rolesMapBuilder.build());
    }
}

@@ -249,55 +249,8 @@
 n;%0A%0A
-import com.google.common.collect.ImmutableMap;%0A
 impo
@@ -490,16 +490,109 @@
 ndRole;%0A
+import java.util.Collections;%0Aimport org.apache.commons.collections4.map.CaseInsensitiveMap;%0A
 import o
@@ -1245,28 +1245,26 @@
 nal 
-ImmutableMap.Builder
+CaseInsensitiveMap
 %3CStr
@@ -1288,69 +1288,56 @@
 sMap
-Builder = ImmutableMap.%3CString, String%3Ebuilder()%0A            
+ = new CaseInsensitiveMap%3C%3E();%0A%0A        rolesMap
 .put
@@ -1378,16 +1378,17 @@
 tring())
+;
 %0A       
@@ -1388,20 +1388,24 @@
         
-    
+rolesMap
 .put(IDO
@@ -1491,23 +1491,16 @@
 rolesMap
-Builder
 .put(IDO
@@ -1605,30 +1605,44 @@
 per(
-rolesMapBuilder.build(
+Collections.unmodifiableMap(rolesMap
 ));%0A

Make role check case-insensitive