What information can I get from the user through Java EE?

Asked

Viewed 58 times

0

I need to implement SSO(Single Sign-On) in a client of the company I work, the scenario is basically the following: They have a web system, made in java, which has a normal login, but they want that there is no login screen and that this verification is done against an Active Directory that they have. So I would like to know what information I can use about the user. I’ve been suggested frameworks like Waffle, Kerberos and SPNEGO, but I found them to be too complicated to implement. I would like this integration to be as simple as possible.

Thanks in advance.

1 answer

0

They need to pass the user and password to be validated, an example to help you would be this block of code that I implemented:

public static boolean authenticateJndi(String username, String password) throws Exception{
        try{    
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        props.put(Context.PROVIDER_URL, "ldap://192.168.1.5:389");
        props.put(Context.SECURITY_AUTHENTICATION, "simple");
        props.put(Context.SECURITY_PRINCIPAL, "login");
        props.put(Context.SECURITY_CREDENTIALS, "senha");
        DirContext context = new InitialDirContext(props);
        System.out.println("Autenticado");
        context.close();
        return true;
        } catch(NamingException e){
            throw new NamingException("Houve um problema na autenticação");

        }
    }
  • Thanks for the answer, showed me a way. I still have a question, as I would to take for example the username of the network and pass as argument on the line. props.put(Context.SECURITY_PRINCIPAL, "login");

  • Varies, depends on the context. This user will have to be expressed at some point.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.