Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUBMARINE-646. Create rest api to authenticate user from LDAP #419

Closed
wants to merge 14 commits into from

Conversation

Eroschang
Copy link
Contributor

What is this PR for?

Create rest api to authenticate user from LDAP server.
The server should be provided by manager now.

What type of PR is it?

Improvement

Todos

  • - Task

What is the Jira issue?

https://issues.apache.org/jira/browse/SUBMARINE-646

How should this be tested?

https://travis-ci.org/github/Eroschang/submarine/builds/731207490

Screenshots (if appropriate)

Questions:

  • Does the licenses files need update? No
  • Is there breaking changes for older versions? No
  • Does this needs documentation? No


private void authenticate(String username, String password) throws Exception {
DirContext ctx = null;
Hashtable<String, String> HashEnv = new Hashtable<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Hashtable<String, String> HashEnv = new Hashtable<>();
Hashtable<String, String> hashEnv = new Hashtable<>();

@xunliu xunliu changed the title SUBMARINE-646. LDAP rest api SUBMARINE-646. Create rest api to authenticate user from LDAP server Oct 1, 2020
@xunliu xunliu changed the title SUBMARINE-646. Create rest api to authenticate user from LDAP server SUBMARINE-646. Create rest api to authenticate user from LDAP Oct 1, 2020
ctx = new InitialDirContext(HashEnv);
}
catch (AuthenticationException e) {
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use LOG.error(xxx) to print exception.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response authenticateUser(@FormParam("username") String username,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change param name and value nameusername to userName.

ctx.close();
}
catch (NamingException e) {
LOG.error(e.getStackTrace().toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to LOG.error(e.getMessage(), e);

Copy link
Member

@jiwq jiwq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Eroschang for the work. I found some redundant blank lines should be removed.

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the dependencies should be moved to project pom.xml and use the defined version property.

Comment on lines 94 to 95
}
catch (AuthenticationException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code style

Suggested change
}
catch (AuthenticationException e) {
} catch (AuthenticationException e) {

Comment on lines 102 to 103
}
catch (NamingException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
catch (NamingException e) {
} catch (NamingException e) {

}

private String createJWT(String id, long ttlMillis){

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eroschang Please delete this blank line.

package org.apache.submarine.server.api.ldap;

public class Ldap {
private String username;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change username to userName.

private String username;
private String password;

public String getUsername() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change getUsername to getUserName.

return username;
}

public void setUsername(String username) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change setUsername(String username) to setUserName(String userName).


private static final Logger LOG = LoggerFactory.getLogger(LdapAuthenticateRestApi.class);

private void authenticate(String username, String password) throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change username to userName.

Copy link
Member

@xunliu xunliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eroschang Please add test util.

return password;
}

public void setUserName(String user_name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function setUserName param is user_name, this.userName = userName; corrent??

@xunliu xunliu closed this Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants