initial commit
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7800c24
--- /dev/null
+++ b/README.md
@@ -0,0 +1,43 @@
+ Copyright (c) 2016 Gigatronik Ingolstadt GmbH
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ <h3>available realms</h3>
+ <h5>glassfish login realm: org.eclipse.mdm.realm.login.glassfish</h5>
+
+- build:
+ The command 'gradlew installRealm' creates the jar file for this login module.
+ The jar file will be generated at org.eclipse.mdm.realms/org.eclipse.mdm.realm.login.glassfish/build/libs/org.eclipse.mdm.realm.login.glassfish-1.0.0.jar
+ <br>
+ <b>install login realm plugin at glassfish:</b>
+ <ul>
+ <li>copy the jar file org.eclipse.mdm.realm.login.glassfish-1.0.0.jar to GLASSFISH4_ROOT/glassfish/domains/domain1/lib</li>
+ <li>open the glassfish login configuration file GLASSFISH4_ROOT/glassfish/domains/domain1/config/login.conf</li>
+ <li>
+ add MDM realm module entry to this config file
+ <code>
+ MDMLoginRealm {
+ org.eclipse.mdm.realm.login.glassfish.LoginRealmModule required;
+ };
+ </code>
+ </li>
+ <li>start glassfish GLASSFISH4_ROOT/glassfish/bin/startserv.bat</li>
+ <li>open glassfish server admin console e.g. at localhost:4848 (default)</li>
+ <li>open site: Configurations/server-config/Security/Realms</li>
+ <li>create new realm ("New" Button)
+ <code>
+ <b>Name:</b> <b><i>MDMLoginRealm</i></b> (realm-name defined at web.xml at org.eclipse.mdm.application/src/main/configuration)
+ <b>Class Name:</b> <b><i>org.eclipse.mdm.realm.login.glassfish.LoginRealm</i></b> (choose a specific class name (radio button))
+ add Property:
+ <b>Name:</b> <b><i>jaas-context</i></b>
+ <b>Value:</b> <b><i>MDMLoginRealm</i></b> (name defined at glassfish login.conf)
+ </code>
+ </li>
+ <li>open site: Configurations/server-config/Virtual Servers</li>
+ <li>choose server and enable SSO (Value: Enabled)</li>
+ <li>save restart the glassfish application server</li>
+
+
+
\ No newline at end of file
diff --git a/org.eclipse.mdm.realm.login.glassfish/build.gradle b/org.eclipse.mdm.realm.login.glassfish/build.gradle
new file mode 100644
index 0000000..4ffc83d
--- /dev/null
+++ b/org.eclipse.mdm.realm.login.glassfish/build.gradle
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Gigatronik Ingolstadt GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sebastian Dirsch - initial configuration
+ *******************************************************************************/
+
+description = 'MDM I18N'
+group = 'org.eclipse.mdm'
+version = '1.0.0'
+apply plugin: 'java'
+apply plugin: 'eclipse'
+apply plugin: 'maven'
+sourceCompatibility = 1.8
+targetCompatibility = 1.8
+
+
+repositories {
+
+ maven {
+ url "https://maven.java.net/content/repositories/staging"
+ }
+
+ mavenLocal()
+ mavenCentral()
+}
+
+
+
+dependencies {
+
+ compile 'javax:javaee-api:7.0'
+
+ compile 'org.eclipse.mdm:org.eclipse.mdm.api.base:1.0.0'
+ compile 'org.eclipse.mdm:org.eclipse.mdm.connector:1.0.0'
+
+ compile 'org.glassfish.main.deployment:deployment-common:4.1.1'
+ compile 'org.glassfish.main.security:security:4.1.1'
+ compile 'org.glassfish.main.common:glassfish-ee-api:4.1.1'
+
+ testCompile 'org.mockito:mockito-core:1.+'
+ testCompile 'junit:junit:4.12'
+}
+
+
+task installRealm(type: Jar) {
+ manifest.from jar.manifest
+ from {
+ configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
+ }
+
+ with jar
+ }
+
+
diff --git a/org.eclipse.mdm.realm.login.glassfish/gradle/wrapper/gradle-wrapper.jar b/org.eclipse.mdm.realm.login.glassfish/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..5ccda13
--- /dev/null
+++ b/org.eclipse.mdm.realm.login.glassfish/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/org.eclipse.mdm.realm.login.glassfish/gradle/wrapper/gradle-wrapper.properties b/org.eclipse.mdm.realm.login.glassfish/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..d758724
--- /dev/null
+++ b/org.eclipse.mdm.realm.login.glassfish/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Tue Mar 29 11:04:16 CEST 2016
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-bin.zip
diff --git a/org.eclipse.mdm.realm.login.glassfish/gradlew b/org.eclipse.mdm.realm.login.glassfish/gradlew
new file mode 100644
index 0000000..9d82f78
--- /dev/null
+++ b/org.eclipse.mdm.realm.login.glassfish/gradlew
@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/org.eclipse.mdm.realm.login.glassfish/gradlew.bat b/org.eclipse.mdm.realm.login.glassfish/gradlew.bat
new file mode 100644
index 0000000..5f19212
--- /dev/null
+++ b/org.eclipse.mdm.realm.login.glassfish/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/org.eclipse.mdm.realm.login.glassfish/settings.gradle b/org.eclipse.mdm.realm.login.glassfish/settings.gradle
new file mode 100644
index 0000000..8b271ea
--- /dev/null
+++ b/org.eclipse.mdm.realm.login.glassfish/settings.gradle
@@ -0,0 +1,12 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Gigatronik Ingolstadt GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sebastian Dirsch - initial configuration
+ *******************************************************************************/
+
+rootProject.name = 'org.eclipse.mdm.realm.login.glassfish'
diff --git a/org.eclipse.mdm.realm.login.glassfish/src/main/java/org/eclipse/mdm/realm/login/glassfish/LoginRealm.java b/org.eclipse.mdm.realm.login.glassfish/src/main/java/org/eclipse/mdm/realm/login/glassfish/LoginRealm.java
new file mode 100644
index 0000000..5a44a7d
--- /dev/null
+++ b/org.eclipse.mdm.realm.login.glassfish/src/main/java/org/eclipse/mdm/realm/login/glassfish/LoginRealm.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Gigatronik Ingolstadt GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sebastian Dirsch - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.mdm.realm.login.glassfish;
+
+import java.util.Enumeration;
+import java.util.Properties;
+
+import com.sun.appserv.security.AppservRealm;
+import com.sun.enterprise.security.auth.realm.BadRealmException;
+import com.sun.enterprise.security.auth.realm.InvalidOperationException;
+import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
+import com.sun.enterprise.security.auth.realm.NoSuchUserException;
+
+/**
+ * Login Ream for Glassfish
+ *
+ * @author Sebastian Dirsch, Gigatronik Ingolstadt GmbH
+ */
+public class LoginRealm extends AppservRealm {
+
+
+
+ private final static String JAAS_CONTEXT = "jaas-context";
+ private final static String AUTH_TYPE = "WebAuthorization";
+
+
+
+ @Override
+ public String getAuthType() {
+ return AUTH_TYPE;
+ }
+
+
+
+ @Override
+ public Enumeration<?> getGroupNames(String username) throws InvalidOperationException, NoSuchUserException {
+ return null;
+ }
+
+
+
+ @Override
+ protected void init(Properties props) throws BadRealmException, NoSuchRealmException {
+ if(!props.containsKey(JAAS_CONTEXT)) {
+ throw new BadRealmException("mandatory property with name '" + JAAS_CONTEXT + "' not found!");
+ }
+ String jaasContext = props.getProperty(JAAS_CONTEXT);
+ setProperty(JAAS_CONTEXT, jaasContext);
+ }
+
+}
diff --git a/org.eclipse.mdm.realm.login.glassfish/src/main/java/org/eclipse/mdm/realm/login/glassfish/LoginRealmModule.java b/org.eclipse.mdm.realm.login.glassfish/src/main/java/org/eclipse/mdm/realm/login/glassfish/LoginRealmModule.java
new file mode 100644
index 0000000..47817f9
--- /dev/null
+++ b/org.eclipse.mdm.realm.login.glassfish/src/main/java/org/eclipse/mdm/realm/login/glassfish/LoginRealmModule.java
@@ -0,0 +1,232 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Gigatronik Ingolstadt GmbH
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sebastian Dirsch - initial implementation
+ *******************************************************************************/
+
+package org.eclipse.mdm.realm.login.glassfish;
+
+import java.security.Principal;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+import org.eclipse.mdm.api.base.EntityManager;
+import org.eclipse.mdm.connector.ConnectorBeanLI;
+import org.eclipse.mdm.connector.ConnectorException;
+import org.glassfish.internal.api.Globals;
+import org.glassfish.security.common.Group;
+
+import com.sun.enterprise.security.PrincipalGroupFactory;
+import com.sun.enterprise.security.auth.login.common.PasswordCredential;
+import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
+import com.sun.enterprise.security.auth.realm.Realm;
+
+/**
+ * Login Module for Glassfish
+ * @author Sebastian Dirsch, Gigatronik Ingolstadt GmbH
+ *
+ */
+public class LoginRealmModule implements LoginModule {
+
+
+
+ private final static String MDM_GROUP = "MDM";
+
+ private Subject subject;
+ private String username = null;
+ private String password = null;
+ private String realm = null;
+
+ private Principal principal = null;
+ private Group group = null;
+
+ private boolean phase1Succeeded = false;
+ private boolean phase2Succeeded = false;
+
+ private ConnectorBeanLI connectorBean;
+ private List<EntityManager> emList;
+
+
+
+ @Override
+ public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState,
+ Map<String, ?> options) {
+
+ this.subject = subject;
+ }
+
+
+
+ @Override
+ public boolean login() throws LoginException {
+ try {
+
+ PasswordCredential passwordCredential = lookupPasswordCredential(this.subject);
+
+ this.realm = passwordCredential.getRealm();
+ this.username = passwordCredential.getUser();
+ this.password = String.valueOf(passwordCredential.getPassword());
+
+ ConnectorBeanLI connector = getConnector();
+ this.emList = connector.connect(this.username, this.password);
+
+ this.phase1Succeeded = true;
+
+ } catch(ConnectorException e) {
+ throw new LoginException(e.getMessage());
+ }
+ return true;
+ }
+
+
+
+ @Override
+ public boolean commit() throws LoginException {
+
+ try {
+
+ if(!this.phase1Succeeded) {
+ return false;
+ }
+
+ if(this.emList != null && this.emList.size() > 0) {
+
+ PrincipalGroupFactory factory = Globals.getDefaultHabitat().getService(PrincipalGroupFactory.class);
+
+ this.principal = createPrincipal(factory);
+ this.group = createGroup(factory);
+
+ Set<Principal> principalSet = this.subject.getPrincipals();
+
+ if(!principalSet.contains(this.principal)) {
+ principalSet.add(this.principal);
+ }
+
+ if(!principalSet.contains(this.group)) {
+ principalSet.add(this.group);
+ }
+
+ ConnectorBeanLI connector = getConnector();
+ connector.registerConnections(this.principal, this.emList);
+
+ this.phase2Succeeded = true;
+ } else {
+ throw new LoginException("unable to connect '" + this.username + "'");
+ }
+
+ return true;
+ } catch(ConnectorException e) {
+ throw new LoginException(e.getMessage());
+ } finally {
+ this.username = null;
+ this.password = null;
+ }
+ }
+
+
+
+ @Override
+ public boolean abort() throws LoginException {
+
+ if(!this.phase1Succeeded) {
+ return false;
+ } else if(this.phase2Succeeded && !this.phase2Succeeded) {
+ this.phase1Succeeded = false;
+ this.username = null;
+ this.password = null;
+ this.principal = null;
+ this.group = null;
+ } else {
+ logout();
+ }
+ return true;
+
+ }
+
+
+
+ @Override
+ public boolean logout() throws LoginException {
+
+ ConnectorBeanLI connectorBean = getConnector();
+ connectorBean.disconnect(this.principal);
+
+ this.emList.clear();
+
+ this.subject.getPrincipals().clear();
+ this.subject.getPublicCredentials().clear();
+ this.subject.getPrivateCredentials().clear();
+
+ this.username = null;
+ this.password = null;
+ this.principal = null;
+ this.group = null;
+
+ this.phase1Succeeded = false;
+ this.phase2Succeeded = false;
+
+ return true;
+ }
+
+
+
+ private Principal createPrincipal(PrincipalGroupFactory factory) throws LoginException {
+ try {
+ Realm realmInstance = Realm.getInstance(this.realm);
+ return factory.getPrincipalInstance(this.username, realmInstance.getName());
+ } catch(NoSuchRealmException e) {
+ throw new LoginException(e.getMessage());
+ }
+ }
+
+
+
+ private Group createGroup(PrincipalGroupFactory factory) throws LoginException {
+ try {
+ Realm realmInstance = Realm.getInstance(this.realm);
+ return factory.getGroupInstance(MDM_GROUP, realmInstance.getName());
+ } catch(NoSuchRealmException e) {
+ throw new LoginException(e.getMessage());
+ }
+ }
+
+
+
+ private PasswordCredential lookupPasswordCredential(Subject subject) throws LoginException {
+ Set<Object> privateCredentials = subject.getPrivateCredentials();
+ for(Object privateCredential : privateCredentials) {
+ if(privateCredential instanceof PasswordCredential) {
+ return ((PasswordCredential)privateCredential);
+ }
+ }
+ throw new LoginException("password credential not found!");
+ }
+
+
+
+ private ConnectorBeanLI getConnector() throws LoginException {
+ try {
+ if(this.connectorBean == null) {
+ String JNDIName = "java:global/org.eclipse.mdm.application-1.0.0/ConnectorBean!org.eclipse.mdm.connector.ConnectorBeanLI";
+ InitialContext initialContext = new InitialContext();
+ this.connectorBean = (ConnectorBeanLI) initialContext.lookup(JNDIName);
+ }
+ return this.connectorBean;
+ } catch(NamingException e) {
+ throw new LoginException(e.getMessage());
+ }
+ }
+}