WebUI mit lokalem Server starten

This commit is contained in:
Peter Hormanns 2017-05-08 19:25:13 +02:00
parent 53ad73e825
commit 33ec937904
28 changed files with 436 additions and 249 deletions

View File

@ -11,9 +11,10 @@ import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import de.hsadmin.jscli.cas.TicketProviderFactory;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.jscli.console.ConsoleWrapper;
import de.hsadmin.jscli.exception.JSCliException;
import de.hsadmin.login.cas.TicketProviderFactory;
public class ScriptClient {
@ -22,6 +23,7 @@ public class ScriptClient {
public ScriptClient(final ConsoleWrapper console, final String user, final String runAs, final String... arguments) throws JSCliException {
final RpcClient rpcClient = new RpcClient();
try {
engine = new ScriptEngineManager().getEngineByName("js");
engine.put("casgrantingticket", TicketProviderFactory.getInstance(console, user, runAs));
engine.put("xmlrpcclient", rpcClient);
@ -67,6 +69,9 @@ public class ScriptClient {
}
}
console.codeCompletion(getCodeCompletionStrings());
} catch (TechnicalException e) {
throw new JSCliException(e);
}
}
public String[] getCodeCompletionStrings() {

View File

@ -1,13 +0,0 @@
package de.hsadmin.jscli;
import java.io.FileNotFoundException;
import de.hsadmin.jscli.exception.JSCliException;
public interface TicketProvider {
public String getTicket() throws JSCliException, FileNotFoundException;
public String getRunAs();
}

View File

@ -1,31 +0,0 @@
package de.hsadmin.jscli.cas;
import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.jscli.TicketProvider;
import de.hsadmin.jscli.console.PasswordReader;
import de.hsadmin.jscli.exception.JSCliException;
public class TicketProviderFactory {
private static final String HOSTSHARING_LOGIN_URL = "https://login.hostsharing.net:443/cas/v1/tickets";
private static final String HOSTSHARING_BACKEND_URL = "https://config.hostsharing.net:443/hsar/backend";
public static TicketProvider getInstance(final PasswordReader console, final String user, final String runAs) throws JSCliException
{
Config config;
try {
config = Config.getInstance();
final String backendURL = config.getProperty("backendURL", HOSTSHARING_BACKEND_URL);
final String loginURL = config.getProperty("loginURL", HOSTSHARING_LOGIN_URL);
if ("TestUmgebung".equalsIgnoreCase(loginURL)) {
return new TestTicketProvider(user, runAs);
} else {
return new CASTicketProvider(console, user, runAs, backendURL, loginURL);
}
} catch (TechnicalException e) {
throw new JSCliException(e);
}
}
}

View File

@ -3,7 +3,9 @@ package de.hsadmin.jscli.console;
import java.io.File;
import java.io.IOException;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.jscli.exception.JSCliException;
import de.hsadmin.login.cas.PasswordReader;
import jline.console.ConsoleReader;
import jline.console.completer.StringsCompleter;
import jline.console.history.FileHistory;
@ -38,25 +40,25 @@ public class ConsoleWrapper implements PasswordReader {
}
}
public void println(final String text) throws JSCliException {
public void println(final String text) throws TechnicalException {
try {
if (cons != null) {
cons.println(text);
} else {
throw new JSCliException("cannot write console");
throw new TechnicalException("cannot write console");
}
} catch (IOException e) {
throw new JSCliException(e);
throw new TechnicalException(e);
}
}
public String readPassword() throws JSCliException {
public String readPassword() throws TechnicalException {
try {
final String pw = cons.readLine("Password: ", new Character('*'));
cons.setPrompt(prompt);
return pw;
} catch (IOException e) {
throw new JSCliException(e);
throw new TechnicalException(e);
}
}

View File

@ -1,11 +0,0 @@
package de.hsadmin.jscli.console;
import de.hsadmin.jscli.exception.JSCliException;
public interface PasswordReader {
public String readPassword() throws JSCliException;
public void println(final String text) throws JSCliException;
}

View File

@ -0,0 +1,13 @@
package de.hsadmin.service.customer;
import de.hsadmin.xmlrpc.AbstractRemote;
import de.hsadmin.xmlrpc.Remote;
public class RoleRemote extends AbstractRemote<RoleVO> implements Remote {
@Override
protected String getModuleLookup() {
return "RoleServiceLocal";
}
}

View File

@ -0,0 +1,54 @@
package de.hsadmin.service.customer;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.common.error.UserException;
import de.hsadmin.login.RequestContext;
import de.hsadmin.login.RequiredScope;
import de.hsadmin.login.Role;
import de.hsadmin.login.ScopePolicy;
import de.hsadmin.module.impl.AbstractModule;
import de.hsadmin.module.property.StringProperty;
@Stateless
public class RoleService extends AbstractModule<RoleVO> implements RoleServiceLocal {
@Override
public RoleVO buildVO() throws TechnicalException {
return new RoleVO();
}
@Override
@RequiredScope({ @ScopePolicy(Role.NONE) })
public RoleVO create(RequestContext requestContext, RoleVO prototype) throws UserException, TechnicalException {
return null;
}
@Override
@RequiredScope({ @ScopePolicy(Role.ANY) })
public List<RoleVO> read(RequestContext requestContext, RoleVO criteria) throws UserException, TechnicalException {
final Role loginRole = requestContext.getLoginRole();
final ArrayList<RoleVO> userRoles = new ArrayList<RoleVO>();
final RoleVO roleVO = buildVO();
roleVO.setRole(loginRole.name());
((StringProperty) roleVO.get("role")).setValue(loginRole.name());
userRoles.add(roleVO);
return userRoles;
}
@Override
@RequiredScope({ @ScopePolicy(Role.NONE) })
public List<RoleVO> update(RequestContext requestContext, RoleVO criteria, RoleVO prototype)
throws UserException, TechnicalException {
return new ArrayList<RoleVO>();
}
@Override
@RequiredScope({ @ScopePolicy(Role.NONE) })
public void delete(RequestContext requestContext, RoleVO criteria) throws UserException, TechnicalException {
}
}

View File

@ -0,0 +1,10 @@
package de.hsadmin.service.customer;
import javax.ejb.Local;
import de.hsadmin.module.Module;
@Local
public interface RoleServiceLocal extends Module<RoleVO> {
}

View File

@ -0,0 +1,31 @@
package de.hsadmin.service.customer;
import javax.validation.constraints.Size;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.module.ValueObject;
import de.hsadmin.module.impl.AbstractVO;
import de.hsadmin.module.property.ReadWrite;
import de.hsadmin.module.property.ReadWritePolicy;
import de.hsadmin.module.property.Required;
public class RoleVO extends AbstractVO implements ValueObject {
@ReadWrite(ReadWritePolicy.READ)
@Required(true)
@Size(min=1,max=24)
private String role;
public RoleVO() throws TechnicalException {
super();
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}

View File

@ -1,3 +1,4 @@
role=de.hsadmin.service.customer.RoleRemote
customer=de.hsadmin.service.customer.CustomerRemote
contact=de.hsadmin.service.customer.ContactRemote
mandat=de.hsadmin.service.customer.SEPADirectDebitRemote

View File

@ -8,6 +8,7 @@ import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.common.error.UserError;
import de.hsadmin.common.error.UserException;
import de.hsadmin.login.cas.TicketValidatorFactory;
@Stateless
public class LoginService implements LoginServiceLocal {
@ -15,8 +16,6 @@ public class LoginService implements LoginServiceLocal {
@PersistenceContext(name = "hsar")
private EntityManager entityManager;
private TicketValidator ticketValidator;
@Override
public RequestContext createContext(final String ticket, final String runAsUser) throws UserException, TechnicalException {
if (ticket != null && !ticket.isEmpty()) {
@ -74,21 +73,8 @@ public class LoginService implements LoginServiceLocal {
}
private String validateTicket(final String ticket) throws TechnicalException, UserException {
final TicketValidator ticketValidator = getTicketValidator();
final TicketValidator ticketValidator = TicketValidatorFactory.getTicketValidator();
return ticketValidator.validate(ticket);
}
private TicketValidator getTicketValidator() throws TechnicalException {
if (ticketValidator == null) {
try {
final String property = Config.getInstance().getProperty(Config.TICKETVALIDATOR_CLASS);
final Class<?> validatorClass = Class.forName(property);
ticketValidator = (TicketValidator) validatorClass.newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new TechnicalException(e);
}
}
return ticketValidator;
}
}

View File

@ -0,0 +1,11 @@
package de.hsadmin.login;
import de.hsadmin.common.error.TechnicalException;
public interface TicketProvider {
public String getTicket() throws TechnicalException;
public String getRunAs();
}

View File

@ -1,9 +1,8 @@
package de.hsadmin.jscli.cas;
package de.hsadmin.login.cas;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
@ -20,9 +19,7 @@ import javax.net.ssl.HttpsURLConnection;
import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.jscli.TicketProvider;
import de.hsadmin.jscli.console.PasswordReader;
import de.hsadmin.jscli.exception.JSCliException;
import de.hsadmin.login.TicketProvider;
public class CASTicketProvider implements TicketProvider {
@ -34,7 +31,7 @@ public class CASTicketProvider implements TicketProvider {
private String grantingTicket;
public CASTicketProvider(final PasswordReader console, final String user, final String runAs, final String backendURL, final String loginURL) throws JSCliException {
public CASTicketProvider(final PasswordReader console, final String user, final String runAs, final String backendURL, final String loginURL) throws TechnicalException {
this.passwordReader = console;
this.user = user;
this.runAs = runAs;
@ -44,7 +41,7 @@ public class CASTicketProvider implements TicketProvider {
}
@Override
public String getTicket() throws JSCliException {
public String getTicket() throws TechnicalException {
try {
final String encodedParams =
URLEncoder.encode("service", "UTF-8") + "=" + URLEncoder.encode(backendURL, "UTF-8");
@ -64,14 +61,14 @@ public class CASTicketProvider implements TicketProvider {
}
trails++;
if (trails > 3) {
throw new JSCliException("exceeded number of login attempts");
throw new TechnicalException("exceeded number of login attempts");
}
urlString = getGrantingTicket();
}
}
return result;
} catch (UnsupportedEncodingException e) {
throw new JSCliException(e);
throw new TechnicalException(e);
}
}
@ -80,7 +77,7 @@ public class CASTicketProvider implements TicketProvider {
return runAs;
}
private String getGrantingTicket() throws JSCliException {
private String getGrantingTicket() throws TechnicalException {
grantingTicket = null;
try {
String password = Config.getInstance().getProperty(user + ".passWord");
@ -93,25 +90,21 @@ public class CASTicketProvider implements TicketProvider {
+ "=" + URLEncoder.encode(password, "UTF-8");
grantingTicket = requestForGrantingTicket(loginURL, encodedParams);
} catch (UnsupportedEncodingException e) {
throw new JSCliException(e);
} catch (FileNotFoundException e) {
throw new JSCliException("cas server not available: " + loginURL);
} catch (TechnicalException e) {
throw new JSCliException(e);
throw new TechnicalException(e);
}
return grantingTicket;
}
private String readPasswordFromConsole() throws JSCliException {
private String readPasswordFromConsole() throws TechnicalException {
return passwordReader.readPassword();
}
private String requestForGrantingTicket(final String urlString, final String encodedParams) throws JSCliException, FileNotFoundException {
private String requestForGrantingTicket(final String urlString, final String encodedParams) throws TechnicalException {
try {
final HttpsURLConnection connection = doConnect(urlString, encodedParams);
return connection.getHeaderField("Location");
} catch (IOException e) {
throw new JSCliException(e);
throw new TechnicalException(e);
}
}
@ -148,7 +141,7 @@ public class CASTicketProvider implements TicketProvider {
return connection;
}
private void readFiledGrantingTicket() throws JSCliException {
private void readFiledGrantingTicket() throws TechnicalException {
final File file = getTicketFile();
final Properties properties = loadProperties(file);
final String filedTicket = properties.getProperty(user);
@ -162,25 +155,25 @@ public class CASTicketProvider implements TicketProvider {
return new File(ticketFileName);
}
private void saveProperties(final String filedTicket, final File file) throws JSCliException {
private void saveProperties(final String filedTicket, final File file) throws TechnicalException {
final Properties properties = loadProperties(file);
if (filedTicket != null) {
properties.setProperty(user, filedTicket);
try {
properties.store(new FileOutputStream(file), "stored cas tickets");
} catch (IOException e) {
throw new JSCliException(e);
throw new TechnicalException(e);
}
}
}
private Properties loadProperties(final File file) throws JSCliException {
private Properties loadProperties(final File file) throws TechnicalException {
final Properties properties = new Properties();
if (file.isFile() && file.canRead()) {
try {
properties.load(new FileReader(file));
} catch (IOException e) {
throw new JSCliException(e);
throw new TechnicalException(e);
}
}
return properties;

View File

@ -1,4 +1,4 @@
package de.hsadmin.login;
package de.hsadmin.login.cas;
import java.io.BufferedReader;
import java.io.IOException;
@ -11,6 +11,7 @@ import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.common.error.UserError;
import de.hsadmin.common.error.UserException;
import de.hsadmin.login.TicketValidator;
public class CASTicketValidator implements TicketValidator {
@ -29,15 +30,16 @@ public class CASTicketValidator implements TicketValidator {
throw new TechnicalException("TicketValidator is not initialized.");
}
try {
URL url = new URL(proxyValidateURL + "?service=" + proxyServiceURL + "&ticket=" + ticket);
URLConnection httpConnection = url.openConnection();
final URL url = new URL(proxyValidateURL + "?service=" + proxyServiceURL + "&ticket=" + ticket);
final URLConnection httpConnection = url.openConnection();
httpConnection.connect();
InputStream inputStream = httpConnection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
final InputStream inputStream = httpConnection.getInputStream();
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String nextLine = reader.readLine();
while (nextLine != null) {
if (nextLine.contains("<cas:user>")) {
String user = extractUser(nextLine);
reader.close();
inputStream.close();
return user;
}

View File

@ -0,0 +1,11 @@
package de.hsadmin.login.cas;
import de.hsadmin.common.error.TechnicalException;
public interface PasswordReader {
public String readPassword() throws TechnicalException;
public void println(final String text) throws TechnicalException;
}

View File

@ -1,9 +1,7 @@
package de.hsadmin.jscli.cas;
package de.hsadmin.login.cas;
import java.io.FileNotFoundException;
import de.hsadmin.jscli.TicketProvider;
import de.hsadmin.jscli.exception.JSCliException;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.login.TicketProvider;
public class TestTicketProvider implements TicketProvider {
@ -16,7 +14,7 @@ public class TestTicketProvider implements TicketProvider {
}
@Override
public String getTicket() throws JSCliException, FileNotFoundException {
public String getTicket() throws TechnicalException {
return grantingTicket;
}

View File

@ -1,4 +1,6 @@
package de.hsadmin.login;
package de.hsadmin.login.cas;
import de.hsadmin.login.TicketValidator;
public class TestTicketValidator implements TicketValidator {

View File

@ -0,0 +1,24 @@
package de.hsadmin.login.cas;
import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.login.TicketProvider;
public class TicketProviderFactory {
private static final String HOSTSHARING_LOGIN_URL = "https://login.hostsharing.net:443/cas/v1/tickets";
private static final String HOSTSHARING_BACKEND_URL = "https://config.hostsharing.net:443/hsar/backend";
public static TicketProvider getInstance(final PasswordReader console, final String user, final String runAs) throws TechnicalException
{
final Config config = Config.getInstance();
final String backendURL = config.getProperty("backendURL", HOSTSHARING_BACKEND_URL);
final String loginURL = config.getProperty("loginURL", HOSTSHARING_LOGIN_URL);
if ("TestUmgebung".equalsIgnoreCase(loginURL)) {
return new TestTicketProvider(user, runAs);
} else {
return new CASTicketProvider(console, user, runAs, backendURL, loginURL);
}
}
}

View File

@ -0,0 +1,23 @@
package de.hsadmin.login.cas;
import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.login.TicketValidator;
public class TicketValidatorFactory {
public static TicketValidator getTicketValidator() throws TechnicalException {
TicketValidator ticketValidator = null;
if (ticketValidator == null) {
try {
final String property = Config.getInstance().getProperty(Config.TICKETVALIDATOR_CLASS);
final Class<?> validatorClass = Class.forName(property);
ticketValidator = (TicketValidator) validatorClass.newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new TechnicalException(e);
}
}
return ticketValidator;
}
}

5
web/hsadmin.properties Normal file
View File

@ -0,0 +1,5 @@
backendURL=https://config.hostsharing.net:443/hsar/backend
;xmlrpcURL=https://config.hostsharing.net:443/hsar/xmlrpc/hsadmin
;loginURL=https://login.hostsharing.net:443/cas/v1/tickets
xmlrpcURL=http://localhost:8080/cust-webapp/xmlrpc/hsadmin
loginURL=TestUmgebung

View File

@ -25,6 +25,12 @@
<groupId>de.hsadmin</groupId>
<artifactId>framework</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-server</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
@ -96,6 +102,7 @@
<version>2.2</version>
<configuration>
<path>/</path>
<port>8081</port>
</configuration>
</plugin>
</plugins>

View File

@ -0,0 +1,90 @@
package de.hsadmin.model;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.net.URL;
import java.net.URLEncoder;
import javax.net.ssl.HttpsURLConnection;
import de.hsadmin.common.config.Config;
import de.hsadmin.rpc.RpcException;
/**
* Helper for service tickets.
* Hostsharing uses the CAS authentication service to authenticate
* users of hostsharing services. This class is used to create a
* "ticket granting ticket" for a session and service ticket for
* individual service calls.
*/
class CASTicketService implements Serializable, TicketService {
private static final long serialVersionUID = 1L;
@Override
public String getGrantingTicket(final String user, final String password) throws RpcException {
String ticket = null;
try {
final Config conf = Config.getInstance();
final String userParam = "username=" + URLEncoder.encode(user, "UTF-8");
final String passwordParam = "password=" + URLEncoder.encode(password, "UTF-8");
final String encodedData = userParam + "&" + passwordParam;
final String casUrl = conf.getProperty("loginURL");
final URL url = new URL(casUrl);
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
writer.write(encodedData);
writer.close();
connection.connect();
ticket = connection.getHeaderField("Location");
} catch (Exception e) {
throw new RpcException(e);
}
return ticket;
}
@Override
public String getServiceTicket(String grantingTicket) throws RpcException {
String ticket = null;
try {
final Config conf = Config.getInstance();
final String backendURL = conf.getProperty("backendURL");
final String serviceParam = "service=" + URLEncoder.encode(backendURL, "UTF-8");
final URL url = new URL(grantingTicket);
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
writer.write(serviceParam);
writer.close();
connection.connect();
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
ticket = reader.readLine();
String readLine = reader.readLine();
do {
readLine = reader.readLine();
} while (readLine != null);
} catch (Exception e) {
throw new RpcException(e);
}
return ticket;
}
}

View File

@ -0,0 +1,21 @@
package de.hsadmin.model;
import java.io.Serializable;
import de.hsadmin.rpc.RpcException;
public class TestTicketService implements TicketService, Serializable {
private static final long serialVersionUID = 1L;
@Override
public String getGrantingTicket(final String user, final String password) throws RpcException {
return "granting:" + user;
}
@Override
public String getServiceTicket(final String grantingTicket) throws RpcException {
return "user" + grantingTicket.substring(grantingTicket.indexOf(':'));
}
}

View File

@ -1,88 +1,11 @@
package de.hsadmin.model;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.net.URL;
import java.net.URLEncoder;
import javax.net.ssl.HttpsURLConnection;
import de.hsadmin.common.config.Config;
import de.hsadmin.rpc.RpcException;
/**
* Helper for service tickets.
* Hostsharing uses the CAS authentication service to authenticate
* users of hostsharing services. This class is used to create a
* "ticket granting ticket" for a session and service ticket for
* individual service calls.
*/
public class TicketService implements Serializable {
public interface TicketService {
private static final long serialVersionUID = 1L;
String getGrantingTicket(String user, String password) throws RpcException;
public String getGrantingTicket(final String user, final String password) throws RpcException {
String ticket = null;
try {
final Config conf = Config.getInstance();
final String userParam = "username=" + URLEncoder.encode(user, "UTF-8");
final String passwordParam = "password=" + URLEncoder.encode(password, "UTF-8");
final String encodedData = userParam + "&" + passwordParam;
final String casUrl = conf.getProperty("loginURL");
final URL url = new URL(casUrl);
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
writer.write(encodedData);
writer.close();
connection.connect();
ticket = connection.getHeaderField("Location");
} catch (Exception e) {
throw new RpcException(e);
}
return ticket;
}
public String getServiceTicket(String grantingTicket) throws RpcException {
String ticket = null;
try {
final Config conf = Config.getInstance();
final String backendURL = conf.getProperty("backendURL");
final String serviceParam = "service=" + URLEncoder.encode(backendURL, "UTF-8");
final URL url = new URL(grantingTicket);
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
writer.write(serviceParam);
writer.close();
connection.connect();
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
ticket = reader.readLine();
String readLine = reader.readLine();
do {
readLine = reader.readLine();
} while (readLine != null);
} catch (Exception e) {
throw new RpcException(e);
}
return ticket;
}
String getServiceTicket(String grantingTicket) throws RpcException;
}

View File

@ -0,0 +1,16 @@
package de.hsadmin.model;
import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
public class TicketServiceFactory {
public static TicketService getTicketService() throws TechnicalException {
final String loginURL = Config.getInstance().getProperty("loginURL");
if ("TestUmgebung".equals(loginURL)) {
return new TestTicketService();
}
return new CASTicketService();
}
}

View File

@ -12,7 +12,9 @@ import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.model.TicketService;
import de.hsadmin.model.TicketServiceFactory;
public class ModulesManagerFactory {
@ -26,8 +28,8 @@ public class ModulesManagerFactory {
public ModulesManager newModulesManager(final String... serverURLs) throws RpcException {
final ModulesManager moduleManager = new ModulesManager();
final TicketService ticketService = new TicketService();
try {
final TicketService ticketService = TicketServiceFactory.getTicketService();;
for (final String servername : serverURLs)
{
final XmlRpcClient rpcClient = new XmlRpcClient();
@ -63,7 +65,7 @@ public class ModulesManagerFactory {
moduleManager.module(moduleName).add(propInfo);
}
}
} catch (MalformedURLException | XmlRpcException e) {
} catch (MalformedURLException | XmlRpcException | TechnicalException e) {
throw new RpcException(e);
}
return moduleManager;

View File

@ -1,20 +1,28 @@
package de.hsadmin.web;
import de.hsadmin.login.Role;
public class EntryPointsFactory extends AbstractEntryPointsFactory {
// FIXME: Domain-Modul zum Testen auskommentiert (ph)
@Override
public String[] getEntryPointNames(final String role) {
if ("HOSTMASTER".equals(role)) {
return new String[] { "customer", "pac", "domain" };
if (Role.SYSTEM.name().equals(role)) {
return new String[] { "customer", "pac" };
// return new String[] { "customer", "pac", "domain" };
}
if ("CUSTOMER".equals(role)) {
return new String[] { "customer", "pac", "domain" };
if (Role.CUSTOMER.name().equals(role)) {
return new String[] { "customer", "pac" };
// return new String[] { "customer", "pac", "domain" };
}
if ("PAC_ADMIN_DW".equals(role)) {
return new String[] { "pac", "domain" };
if (Role.PACKET.name().equals(role)) {
return new String[] { "pac" };
// return new String[] { "pac", "domain" };
}
if ("DOM_ADMIN".equals(role)) {
return new String[] { "domain" };
if (Role.DOMAIN.name().equals(role)) {
// return new String[] { "domain" };
}
return new String[] { };
}

View File

@ -11,7 +11,9 @@ import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.model.TicketService;
import de.hsadmin.model.TicketServiceFactory;
@Title("HSAdmin Web")
@Theme(ValoTheme.THEME_NAME)
@ -35,10 +37,12 @@ public class HSAdminUI extends UI {
setSizeFull();
layout = new VerticalLayout();
layout.setSizeFull();
ticketService = new TicketService();
try {
ticketService = TicketServiceFactory.getTicketService();
UI.getCurrent().addWindow(new LoginWindow(this, ticketService));
} catch (TechnicalException e) {
// dont care
}
setContent(layout);
}