org.ar4k.agent.console.Ar4kAgent Maven / Gradle / Ivy
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
package org.ar4k.agent.console;
import java.util.ArrayList;
import java.util.List;
import org.ar4k.agent.core.Homunculus;
import org.ar4k.agent.spring.EdgeUserDetails;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.StringUtils;
/**
* Classe main per avvio Agente Ar4k as is
*
* @author Andrea Ambrosini
*/
@SpringBootApplication
@ComponentScan("org.ar4k.agent")
public class Ar4kAgent {
static final boolean running = true;
public static void main(String[] args) {
final String[] disabledCommands = { "--spring.shell.command.quit.enabled=false" };
final String[] fullArgs = StringUtils.concatenateStringArrays(args, disabledCommands);
final SpringApplication app = new SpringApplication(Ar4kAgent.class);
// app.setWebApplicationType(WebApplicationType.SERVLET);
app.run(fullArgs);
final EdgeUserDetails u = new EdgeUserDetails();
u.setUsername("admin");
u.setPassword(Homunculus.getApplicationContext().getBean(PasswordEncoder.class).encode("admin"));
final List a = new ArrayList<>();
for (final String p : "ROLE_ADMIN,ROLE_USER".split(",")) {
final SimpleGrantedAuthority g = new SimpleGrantedAuthority(p);
a.add(g);
}
u.setAuthorities(a);
Homunculus.getApplicationContext().getBean(Homunculus.class).getLocalUsers().add(u);
}
}