Skip to content

Commit

Permalink
1.0.3 -> Add auth system based on bcrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Aug 30, 2017
1 parent cd0717a commit 0715922
Show file tree
Hide file tree
Showing 35 changed files with 860 additions and 122 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>org.panda-lang</groupId>
<artifactId>nanomaven</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
Expand Down Expand Up @@ -90,6 +90,11 @@
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/org/panda_lang/nanomaven/NanoMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package org.panda_lang.nanomaven;

import org.fusesource.jansi.Ansi;
import org.panda_lang.nanomaven.console.NanoConsole;
import org.panda_lang.nanomaven.console.commands.HelpCommand;
import org.panda_lang.nanomaven.maven.NanoMavenCli;
import org.panda_lang.nanomaven.server.NanoHttpdServer;
import org.panda_lang.nanomaven.server.auth.NanoProjectsManager;
import org.panda_lang.nanomaven.server.auth.NanoUsersManager;
import org.panda_lang.nanomaven.util.DirectoryUtils;
import org.panda_lang.nanomaven.util.TimeUtils;
import org.panda_lang.nanomaven.workspace.NanoWorkspace;
Expand All @@ -31,8 +33,10 @@ public class NanoMaven {

private NanoConsole console;
private NanoWorkspace workspace;
private NanoUsersManager usersManager;
private NanoMavenConfiguration configuration;
private NanoRepositoryManager repositoryManager;
private NanoProjectsManager projectsManager;
private NanoHttpdServer httpdServer;
private NanoMavenCli mavenCli;
private boolean stopped;
Expand All @@ -48,15 +52,21 @@ private void initialize() {
this.configuration = new NanoMavenConfiguration();
configuration.load();

this.usersManager = new NanoUsersManager();
usersManager.load(configuration);

this.repositoryManager = new NanoRepositoryManager();
repositoryManager.scan();

this.projectsManager = new NanoProjectsManager(usersManager);
projectsManager.load();

this.httpdServer = new NanoHttpdServer(this);
this.mavenCli = new NanoMavenCli(this);
}

public void launch() {
getLogger().info(Ansi.ansi().bold().fg(Ansi.Color.MAGENTA).a("NanoMaven ").reset().a(NanoMavenConstants.VERSION).toString());
getLogger().info(NanoMavenConstants.GREETING_MESSAGE);
initialize();

getLogger().info("Binding NanoMaven at *::" + configuration.getPort());
Expand All @@ -69,6 +79,9 @@ public void launch() {
Runtime.getRuntime().addShutdownHook(shutdownHook);

getLogger().info("Done (" + TimeUtils.getUptime(uptime) + "s)!");

HelpCommand listCommands = new HelpCommand();
listCommands.call(this);
} catch (Exception exception) {
exception.printStackTrace();
shutdown();
Expand All @@ -83,6 +96,13 @@ public void shutdown() {

getLogger().info("Shutting down...");
httpdServer.stop();

getLogger().info("Saving users...");
usersManager.save();

getLogger().info("Saving projects...");
projectsManager.save();

getLogger().info("Bye! Uptime: " + TimeUtils.getUptime(uptime) + "s");
}

Expand All @@ -98,6 +118,10 @@ public NanoMavenCli getMavenCli() {
return mavenCli;
}

public NanoProjectsManager getProjectsManager() {
return projectsManager;
}

public NanoRepositoryManager getRepositoryManager() {
return repositoryManager;
}
Expand All @@ -106,6 +130,10 @@ public NanoMavenConfiguration getConfiguration() {
return configuration;
}

public NanoUsersManager getUsersManager() {
return usersManager;
}

public static String getDataFolder() {
return DirectoryUtils.getDataFolder(NanoMaven.class);
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/panda_lang/nanomaven/NanoMavenConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@

package org.panda_lang.nanomaven;

import org.fusesource.jansi.Ansi.Color;

import static org.fusesource.jansi.Ansi.ansi;

public class NanoMavenConstants {

public static final String VERSION = "1.0.2";
public static final String VERSION = "1.0.3";

public static final boolean INTERNAL_DEBUG = true;

protected static final String GREETING_MESSAGE = ansi().bold().fg(Color.CYAN).a("NanoMaven ").reset().a(NanoMavenConstants.VERSION).toString();

}
33 changes: 32 additions & 1 deletion src/main/java/org/panda_lang/nanomaven/console/NanoConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.panda_lang.nanomaven.console;

import org.panda_lang.nanomaven.NanoMaven;
import org.panda_lang.nanomaven.console.commands.ReinstallArtifactsCommand;
import org.panda_lang.nanomaven.console.commands.*;

public class NanoConsole {

Expand All @@ -36,10 +36,41 @@ public void hook() {

// TODO
public void execute(String command) throws Exception {
String[] elements = command.split(" ");

if (command.equalsIgnoreCase("help")) {
HelpCommand helpCommand = new HelpCommand();
helpCommand.call(nanoMaven);
return;
}

if (command.equalsIgnoreCase("reinstall-artifacts") || command.equalsIgnoreCase("rs")) {
ReinstallArtifactsCommand reinstallArtifactsCommand = new ReinstallArtifactsCommand();
reinstallArtifactsCommand.execute(nanoMaven);
return;
}

command = elements[0];

if (command.equalsIgnoreCase("add-user")) {
UserCommand userCommand = new UserCommand(elements[1], elements[2]);
userCommand.call(nanoMaven);
return;
}

if (command.equalsIgnoreCase("add-project")) {
ProjectCommand projectCommand = new ProjectCommand(elements[1]);
projectCommand.call(nanoMaven);
return;
}

if (command.equalsIgnoreCase("add-member")) {
MemberCommand memberCommand = new MemberCommand(elements[1], elements[2]);
memberCommand.call(nanoMaven);
return;
}

NanoMaven.getLogger().warn("Unknown command " + elements[0]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@

package org.panda_lang.nanomaven.console.commands;

import io.airlift.airline.Command;
import io.airlift.airline.Help;
import org.panda_lang.nanomaven.NanoMaven;
import org.panda_lang.nanomaven.NanoMavenConstants;
import org.panda_lang.nanomaven.console.NanoCommand;

@Command(name = "help", description = "Display help information")
public class NanoHelpCommand extends Help implements NanoCommand {
public class HelpCommand implements NanoCommand {

@Override
public void call(NanoMaven nanoMaven) {
super.run();
NanoMaven.getLogger().info("");
NanoMaven.getLogger().info("NanoMaven " + NanoMavenConstants.VERSION + " Commands:");
NanoMaven.getLogger().info(" help - List available commands");
NanoMaven.getLogger().info(" add-user <username> <password> - Add user");
NanoMaven.getLogger().info(" add-project <groupId|artifactId> - Add project extra data");
NanoMaven.getLogger().info(" add-member <groupId|artifactId> <username> - Add user to the specified project");
NanoMaven.getLogger().info(" reinstall-artifacts (rs) - Reinstall all artifacts");
NanoMaven.getLogger().info("");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2017 Dzikoysk
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.panda_lang.nanomaven.console.commands;

import org.panda_lang.nanomaven.NanoMaven;
import org.panda_lang.nanomaven.console.NanoCommand;
import org.panda_lang.nanomaven.server.auth.NanoProject;
import org.panda_lang.nanomaven.server.auth.NanoProjectsManager;
import org.panda_lang.nanomaven.server.auth.NanoUser;
import org.panda_lang.nanomaven.server.auth.NanoUsersManager;

public class MemberCommand implements NanoCommand {

private final String projectName;
private final String username;

public MemberCommand(String projectName, String username) {
this.projectName = projectName;
this.username = username;
}

@Override
public void call(NanoMaven nanoMaven) {
NanoUsersManager usersManager = nanoMaven.getUsersManager();
NanoProjectsManager projectsManager = nanoMaven.getProjectsManager();

if (!projectName.contains("/")) {
NanoMaven.getLogger().warn("GroupId or ArtifactId is not specified");
return;
}

NanoProject nanoProject = projectsManager.getProject(projectName);

if (nanoProject == null) {
NanoMaven.getLogger().warn("Project " + projectName + " doesn't exists");
return;
}

NanoUser nanoUser = usersManager.getUser(username);

if (nanoUser == null) {
NanoMaven.getLogger().warn("User " + username + " doesn't exists");
return;
}

nanoProject.addUser(nanoUser);
nanoUser.addProject(nanoProject);

projectsManager.save();
NanoMaven.getLogger().info("User " + username + " has been added to the '" + projectName + "' project");
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2017 Dzikoysk
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.panda_lang.nanomaven.console.commands;

import org.panda_lang.nanomaven.NanoMaven;
import org.panda_lang.nanomaven.console.NanoCommand;
import org.panda_lang.nanomaven.server.auth.NanoProject;
import org.panda_lang.nanomaven.server.auth.NanoProjectsManager;

public class ProjectCommand implements NanoCommand {

private final String projectName;

public ProjectCommand(String projectName) {
this.projectName = projectName;
}

@Override
public void call(NanoMaven nanoMaven) {
NanoProjectsManager projectsManager = nanoMaven.getProjectsManager();

if (!projectName.contains("/")) {
NanoMaven.getLogger().warn("GroupId or ArtifactId is not specified");
return;
}

NanoProject nanoProject = projectsManager.getProject(projectName);

if (nanoProject != null) {
NanoMaven.getLogger().warn("Project " + projectName + " exists");
return;
}

NanoMaven.getLogger().info("Creating project...");

NanoProject project = new NanoProject(projectName);
projectsManager.addProject(project);
projectsManager.save();

NanoMaven.getLogger().info("Project " + project.getProjectName() + " has been created");
}

}
Loading

0 comments on commit 0715922

Please sign in to comment.