Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
chore(rest): minor changes regarding the rest pom files and code review
Browse files Browse the repository at this point in the history
- reverted the data handler dependency for resource-server
- changed copy paste issue for the authorization-server final name
- excluded dependency spring boot logging
- code review changes
  • Loading branch information
maierthomas committed Jan 10, 2018
1 parent 1885a9c commit 52ce732
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 54 deletions.
36 changes: 17 additions & 19 deletions rest/authorization-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${spring-boot.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -70,18 +86,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down Expand Up @@ -112,12 +116,6 @@
<version>${project-lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.sw360</groupId>
<artifactId>datahandler</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand All @@ -132,7 +130,7 @@
</dependencyManagement>

<build>
<finalName>resource</finalName>
<finalName>authorization</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,35 @@ private boolean isAuthorized(String email, String password) {
String url = sw360PortalServerURL + String.format(liferayParameterURL, sw360LiferayCompanyId, email);
RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder();
String encodedPassword;

try {
encodedPassword = URLDecoder.decode(password, "US-ASCII");
} catch (UnsupportedEncodingException e) {
return false;
}

RestTemplate restTemplate = restTemplateBuilder.basicAuthorization(email, encodedPassword).build();
ResponseEntity<String> response = restTemplate.postForEntity(url, null, String.class);
return (parseInteger(response.getBody()) > 0);

try {
// The user exits in liferay if the body contains a number
Integer.parseInt(response.getBody());
} catch (NumberFormatException e) {
return false;
}
return true;
}

private User getUserByEmail(String email) {
UserService.Iface client = new ThriftClients().makeUserClient();
User user = null;
try {
if (!Strings.isNullOrEmpty(email) && client != null) {
user = client.getByEmail(email);
return client.getByEmail(email);
}
} catch (TException e) {
user = null;
return null;
}
return user;
return null;
}

private Authentication createAuthenticationToken(String name, String password, User user) {
Expand All @@ -133,23 +141,13 @@ private Authentication createAuthenticationToken(String name, String password, U
}

private boolean isDevEnvironment() {
Boolean result = false;
String[] activeProfiles = environment.getActiveProfiles();
for (String profile : activeProfiles) {
if (profile.equals(ENVIRONMENT_DEV_PROFILE)) {
result = true;
break;
return true;
}
}
return result;
}

private int parseInteger(String value) {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
return 0;
}
return false;
}

private boolean isValidString(String string) {
Expand Down
22 changes: 10 additions & 12 deletions rest/resource-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand Down Expand Up @@ -124,12 +132,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.sw360</groupId>
<artifactId>datahandler</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down Expand Up @@ -245,14 +247,10 @@
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/static/docs
</outputDirectory>
<outputDirectory>${project.build.outputDirectory}/static/docs</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
<directory>${project.build.directory}/generated-docs</directory>
</resource>
</resources>
</configuration>
Expand Down
6 changes: 3 additions & 3 deletions rest/resource-server/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
//

= SW360 REST API
BETA; Version {project-version}
Documentation; Version {project-version}
:doctype: book
:icons: font
:source-highlighter: highlightjs

SW360 is the upcoming tool for our OSS management and clearing activities.
Here you find information about the REST API for SW360.
The REST API is in early stage, link:https://github.com/sw360/sw360portal[feedback/issues] is very welcome.
The REST API is in early stage, link:https://github.com/sw360/sw360portal/issues[feedback/issues] is very welcome.

* link:api-guide.html[API Guide]
* link:https://github.com/sw360/sw360portal[Git Repository]
* link:https://localhost:8443/browser.html#/api[Interactive API Browser]
* link:../api/browser/index.html[Interactive API Browser]
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ private static class ErrorMessage {

@JsonSerialize(using = JsonInstantSerializer.class)
private Instant timestamp = Instant.now();
final private int status;
final private String error;
final private String message;
private final int status;
private final String error;
private final String message;

public ErrorMessage(Exception e, HttpStatus httpStatus) {
this.status = httpStatus.value();
Expand Down

0 comments on commit 52ce732

Please sign in to comment.