# Como alterar o atributo principal de autenticação em seu IDP

## Alteração do atributo no IDP

Em seu IDP, assim como em todo IDP, o mesmo possui um atributo chave que é usado como o atributo de autenticação principal. Em clientes que usam LDAP esse atributo é setado por padrão como sendo o "uid" e em clientes que usam o Microsoft AD esse atributo por padrão é setado como sendo o atributo "sAMAccountName".

Clientes nos perguntam se é possível alterar esse atributo principal de login na federação CAFe, e sim, é possível ! Abaixo eu descrevo os passos necessários para que façam esse ajusto em seus IDPs.

{% hint style="warning" %}
Será necessário apenas ajustar e alterar informações em um único arquivo do IDP, é o arquivo "ldap.properties". Sugiro que seja feito um backup do arquivo original antes de altera-lo.

sudo -i

cp -a /opt/shibboleth-idp/conf/ldap.properties /home/cafe/ldap.properties-original
{% endhint %}

Vamos ao procedimento de alteração, acesse o arquivo "ldap.properties" como root:

```
sudo -i
vim /opt/shibboleth-idp/conf/ldap.properties
```

Faremos o exemplo usando um arquivo "ldap.properties" usando a configuração padrão de um LDAP, com isso o atributo principal será o "uid". Se você estiver usando um Microsoft AD esse atributo será o "sAMAccountName" não se preocupe basta fazer o mesmo procedimento.

&#x20;

```
# LDAP authentication (and possibly attribute resolver) configuration
# Note, this doesn't apply to the use of JAAS authentication via LDAP

## Authenticator strategy, either anonSearchAuthenticator, bindSearchAuthenticator, directAuthenticator, adAuthenticator
idp.authn.LDAP.authenticator                    = bindSearchAuthenticator

## Connection properties ##
idp.authn.LDAP.ldapURL                          = ldaps://ldap.rnp.br:636
idp.authn.LDAP.useStartTLS                      = false
# Time in milliseconds that connects will block
idp.authn.LDAP.connectTimeout                   = PT3S
# Time in milliseconds to wait for responses
idp.authn.LDAP.responseTimeout                  = PT3S
# Connection strategy to use when multiple URLs are supplied, either ACTIVE_PASSIVE, ROUND_ROBIN, RANDOM
#idp.authn.LDAP.connectionStrategy              = ACTIVE_PASSIVE

## SSL configuration, either jvmTrust, certificateTrust, or keyStoreTrust
idp.authn.LDAP.sslConfig                        = certificateTrust
## If using certificateTrust above, set to the trusted certificate's path
idp.authn.LDAP.trustCertificates                = %{idp.home}/credentials/ldap-server.crt
## If using keyStoreTrust above, set to the truststore path
#idp.authn.LDAP.trustStore                      = %{idp.home}/credentials/ldap-server.truststore

## Return attributes during authentication
idp.authn.LDAP.returnAttributes                 = uid

## DN resolution properties ##

# Search DN resolution, used by anonSearchAuthenticator, bindSearchAuthenticator
# for AD: CN=Users,DC=example,DC=org
idp.authn.LDAP.baseDN                           = ou=RNP,dc=rnp,dc=local
idp.authn.LDAP.subtreeSearch                    = true
idp.authn.LDAP.userFilter                       = (uid={user})
# bind search configuration
# for AD: idp.authn.LDAP.bindDN=adminuser@domain.com
idp.authn.LDAP.bindDN                           = uid=app.shib.r,OU=APLICACOES,dc=rnp,dc=local

# Format DN resolution, used by directAuthenticator, adAuthenticator
# for AD use idp.authn.LDAP.dnFormat=%s@domain.com
idp.authn.LDAP.dnFormat                         = uid=%s,ou=RNP,dc=rnp,dc=local

# pool passivator, either none, bind or anonymousBind
#idp.authn.LDAP.bindPoolPassivator              = none

# LDAP attribute configuration, see attribute-resolver.xml
# Note, this likely won't apply to the use of legacy V2 resolver configurations
idp.attribute.resolver.LDAP.ldapURL             = %{idp.authn.LDAP.ldapURL}
idp.attribute.resolver.LDAP.connectTimeout      = %{idp.authn.LDAP.connectTimeout:PT3S}
idp.attribute.resolver.LDAP.responseTimeout     = %{idp.authn.LDAP.responseTimeout:PT3S}
idp.attribute.resolver.LDAP.connectionStrategy  = %{idp.authn.LDAP.connectionStrategy:ACTIVE_PASSIVE}
idp.attribute.resolver.LDAP.baseDN              = %{idp.authn.LDAP.baseDN:undefined}
idp.attribute.resolver.LDAP.bindDN              = %{idp.authn.LDAP.bindDN:undefined}
idp.attribute.resolver.LDAP.useStartTLS         = %{idp.authn.LDAP.useStartTLS:true}
idp.attribute.resolver.LDAP.trustCertificates   = %{idp.authn.LDAP.trustCertificates:undefined}
idp.attribute.resolver.LDAP.searchFilter        = (uid=$resolutionContext.principal)

# LDAP pool configuration, used for both authn and DN resolution
#idp.pool.LDAP.minSize                          = 3
#idp.pool.LDAP.maxSize                          = 10
#idp.pool.LDAP.validateOnCheckout               = false
#idp.pool.LDAP.validatePeriodically             = true
#idp.pool.LDAP.validatePeriod                   = PT5M
#idp.pool.LDAP.validateDN                       =
#idp.pool.LDAP.validateFilter                   = (objectClass=*)
#idp.pool.LDAP.prunePeriod                      = PT5M
#idp.pool.LDAP.idleTime                         = PT10M
#idp.pool.LDAP.blockWaitTime                    = PT3S
```

As alterações irão ocorrer em apenas 4 linhas, tenha atenção nesse ponto.

Serão as linhas 25, 33, 40 e 55 procure pelas variáveis nesse ordem que segue:

```
idp.authn.LDAP.returnAttributes                 = uid
idp.authn.LDAP.userFilter                       = (uid={user})
idp.authn.LDAP.dnFormat                         = uid=%s,ou=RNP,dc=rnp,dc=local
idp.attribute.resolver.LDAP.searchFilter        = (uid=$resolutionContext.principal)
```

Essas variáveis são as responsáveis por determinar qual atributo será usado para login em seu IDP, sendo assim em nosso exemplo o nosso atributo de autenticação no IDP está sendo o "uid". Porém houve a necessidade de se alterar esse atributo e a escolha do novo atributo para login, em nosso exemplo, será o atributo "mail". Como ficaria então essa nova configuração, veja:

```
idp.authn.LDAP.returnAttributes                 = mail
idp.authn.LDAP.userFilter                       = (mail={user})
idp.authn.LDAP.dnFormat                         = mail=%s,ou=RNP,dc=rnp,dc=local
idp.attribute.resolver.LDAP.searchFilter        = (mail=$resolutionContext.principal)
```

Repare aonde mudamos os valores para as variáveis, veja como a estrutura deve ficar ao final:

```
# LDAP authentication (and possibly attribute resolver) configuration
# Note, this doesn't apply to the use of JAAS authentication via LDAP

## Authenticator strategy, either anonSearchAuthenticator, bindSearchAuthenticator, directAuthenticator, adAuthenticator
idp.authn.LDAP.authenticator                    = bindSearchAuthenticator

## Connection properties ##
idp.authn.LDAP.ldapURL                          = ldaps://ldap.rnp.br:636
idp.authn.LDAP.useStartTLS                      = false
# Time in milliseconds that connects will block
idp.authn.LDAP.connectTimeout                   = PT3S
# Time in milliseconds to wait for responses
idp.authn.LDAP.responseTimeout                  = PT3S
# Connection strategy to use when multiple URLs are supplied, either ACTIVE_PASSIVE, ROUND_ROBIN, RANDOM
#idp.authn.LDAP.connectionStrategy              = ACTIVE_PASSIVE

## SSL configuration, either jvmTrust, certificateTrust, or keyStoreTrust
idp.authn.LDAP.sslConfig                        = certificateTrust
## If using certificateTrust above, set to the trusted certificate's path
idp.authn.LDAP.trustCertificates                = %{idp.home}/credentials/ldap-server.crt
## If using keyStoreTrust above, set to the truststore path
#idp.authn.LDAP.trustStore                      = %{idp.home}/credentials/ldap-server.truststore

## Return attributes during authentication
idp.authn.LDAP.returnAttributes                 = mail

## DN resolution properties ##

# Search DN resolution, used by anonSearchAuthenticator, bindSearchAuthenticator
# for AD: CN=Users,DC=example,DC=org
idp.authn.LDAP.baseDN                           = ou=RNP,dc=rnp,dc=local
idp.authn.LDAP.subtreeSearch                    = true
idp.authn.LDAP.userFilter                       = (mail={user})
# bind search configuration
# for AD: idp.authn.LDAP.bindDN=adminuser@domain.com
idp.authn.LDAP.bindDN                           = uid=app.shib.r,OU=APLICACOES,dc=rnp,dc=local

# Format DN resolution, used by directAuthenticator, adAuthenticator
# for AD use idp.authn.LDAP.dnFormat=%s@domain.com
idp.authn.LDAP.dnFormat                         = mail=%s,ou=RNP,dc=rnp,dc=local

# pool passivator, either none, bind or anonymousBind
#idp.authn.LDAP.bindPoolPassivator              = none

# LDAP attribute configuration, see attribute-resolver.xml
# Note, this likely won't apply to the use of legacy V2 resolver configurations
idp.attribute.resolver.LDAP.ldapURL             = %{idp.authn.LDAP.ldapURL}
idp.attribute.resolver.LDAP.connectTimeout      = %{idp.authn.LDAP.connectTimeout:PT3S}
idp.attribute.resolver.LDAP.responseTimeout     = %{idp.authn.LDAP.responseTimeout:PT3S}
idp.attribute.resolver.LDAP.connectionStrategy  = %{idp.authn.LDAP.connectionStrategy:ACTIVE_PASSIVE}
idp.attribute.resolver.LDAP.baseDN              = %{idp.authn.LDAP.baseDN:undefined}
idp.attribute.resolver.LDAP.bindDN              = %{idp.authn.LDAP.bindDN:undefined}
idp.attribute.resolver.LDAP.useStartTLS         = %{idp.authn.LDAP.useStartTLS:true}
idp.attribute.resolver.LDAP.trustCertificates   = %{idp.authn.LDAP.trustCertificates:undefined}
idp.attribute.resolver.LDAP.searchFilter        = (mail=$resolutionContext.principal)

# LDAP pool configuration, used for both authn and DN resolution
#idp.pool.LDAP.minSize                          = 3
#idp.pool.LDAP.maxSize                          = 10
#idp.pool.LDAP.validateOnCheckout               = false
#idp.pool.LDAP.validatePeriodically             = true
#idp.pool.LDAP.validatePeriod                   = PT5M
#idp.pool.LDAP.validateDN                       =
#idp.pool.LDAP.validateFilter                   = (objectClass=*)
#idp.pool.LDAP.prunePeriod                      = PT5M
#idp.pool.LDAP.idleTime                         = PT10M
#idp.pool.LDAP.blockWaitTime                    = PT3S
```

## Alteração do texto de acesso

Excelente ! Se o seu arquivo ficou conforme o final do processo anterior indica que você alterou o seu atributo principal de login, agora os usuários usarão o e-mail para logar em seu IDP.

Mas é agora ? Na tela de login a mensagem que aparece para os usuários ainda é a de inserir o "uid" ?&#x20;

Sim, verdade ! Será necessário também customizar a frase da tela de login, afinal mudamos o meio de login do IDP e isso pode confundir os usuários. Então vamos lá !

Na imagem abaixo eu mostro como estava a minha frase na minha tela de login, veja:

&#x20;

![](https://3706451151-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M94Z581aPIo4Bzo9ImS%2Fuploads%2FLSDe8AvUPfqFpmFXiwO9%2Fimage.png?alt=media\&token=e9f15cfe-e221-4704-a646-58449370987c)

Veja que a minha frase era "Seu nome.sobrenome" porque como os usuários usavam o "uid" para se logar, e em minha base o nosso "uid" é nome.sobrenome do usuário, mas eu alterei para  o atributo "mail" conforme procedimento acima, então temos que alterar essa frase.

{% hint style="warning" %}
Para alterar a frase da tela de login do IDP vamos precisar mexer no arquivo "messages\_pt\_BR.properties". Sugiro que seja feito um backup desse arquivo original antes de altera-lo.

sudo -i

cp -a /opt/shibboleth-idp/messages/messages\_pt*BR.properties /home/cafe/messages\_ptBR.*&#x70;roperties-original
{% endhint %}

Agora vamos alterar a mensagem de login da tela do IDP. Edite o arquivo messages\_ptBR.properties

```
sudo -i
vim /opt/shibboleth-idp/messages/messages_ptBR.properties
```

Esse arquivo é muito grande não seria prático colocar todo ele aqui, então oriento você a procurar pela seguinte variável:

```
idp.login.username.label = Seu nome.sobrenome
```

Essa é a mensagem que irá aparecer para os usuários do IDP, então altere como achar melhor para indicar aos seus usuários o que eles devem usar para se autenticar, no nosso exemplo usamos o atributo "mail" referente ao email, então nossa alteração será assim:

```
idp.login.username.label = Seu email @rnp.br
```

Salve o arquivo e vamos agora refazer o "build" do IDP:

```
sudo -i
cd /opt/shibboleth-idp/bin
./build.sh
Buildfile: /opt/shibboleth-idp/bin/build.xml

build-war:
Installation Directory: [/opt/shibboleth-idp] ?

INFO [net.shibboleth.idp.installer.BuildWar:103] - Rebuilding /opt/shibboleth-idp/war/idp.war, Version 4.1.5
INFO [net.shibboleth.idp.installer.BuildWar:113] - Initial populate from /opt/shibboleth-idp/dist/webapp to /opt/shibboleth-idp/webpapp.tmp
INFO [net.shibboleth.idp.installer.BuildWar:92] - Overlay from /opt/shibboleth-idp/edit-webapp to /opt/shibboleth-idp/webpapp.tmp
INFO [net.shibboleth.idp.installer.BuildWar:125] - Creating war file /opt/shibboleth-idp/war/idp.war

BUILD SUCCESSFUL
Total time: 8 seconds
```

Repare que na etapa de número (7) o script está lhe fazendo uma pergunta, aonde é o diretório instalado do seu IDP, como o nosso template usa o padrão, basta pressionar a tecla \<enter> que o script irá seguir com o restante. Feito isso acabamos, agora vamos reiniciar o serviço do Jetty9

```
sudo -i
sudo systemctl restart jetty.service
```

&#x20;Veja como ficou agora a minha tela de login:

![](https://3706451151-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M94Z581aPIo4Bzo9ImS%2Fuploads%2FwyO9LiYdmNqu7cgQQhrE%2Fimage.png?alt=media\&token=c1cb9b22-15f1-4f0e-8651-e5e535b12fda)

Pronto, você alterou o seu atributo de login prinicipal e alterou a frase da sua tela de login.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ajuda.rnp.br/cafe/idp-cafe/faq/como-alterar-o-atributo-principal-de-autenticacao-em-seu-idp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
