+import org.eclipse.swt.widgets.Display;
+
+public class LoginEntryPoint implements EntryPoint, CmsView {
+ // private final static Log log = LogFactory.getLog(WorkbenchLogin.class);
+ private final Subject subject = new Subject();
+ private LoginContext loginContext;
+ private UxContext uxContext = null;
+
+ @Override
+ public int createUI() {
+ final Display display = createDisplay();
+ UiContext.setData(CmsView.KEY, this);
+ try {
+ // try pre-auth
+ loginContext = new LoginContext(AuthConstants.LOGIN_CONTEXT_USER,
+ subject, new HttpRequestCallbackHandler(getRequest()));
+ loginContext.login();
+ } catch (CredentialNotFoundException e) {
+ CmsLoginShell loginShell = createCmsLoginShell();
+ loginShell.open();
+ while (!loginShell.getShell().isDisposed()) {
+ try {
+ if (!display.readAndDispatch())
+ display.sleep();
+ } catch (Exception e1) {
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException e2) {
+ // silent
+ }
+ ErrorFeedback.show("Login failed", e1);
+ return -1;
+ }
+ }
+ } catch (LoginException e) {
+ throw new ArgeoException("Cannot log in", e);
+ }
+ uxContext = new SimpleUxContext();
+ return postLogin();
+ }
+
+ protected Display createDisplay() {
+ return new Display();
+ }
+
+ protected int postLogin() {
+ return 0;
+ }
+
+ protected HttpServletRequest getRequest() {
+ return RWT.getRequest();
+ }
+
+ protected CmsLoginShell createCmsLoginShell() {
+ return new CmsLoginShell(this) {
+
+ @Override
+ public void createContents(Composite parent) {
+ LoginEntryPoint.this.createLoginPage(parent, this);
+ }
+
+ @Override
+ protected void extendsCredentialsBlock(Composite credentialsBlock,
+ Locale selectedLocale,
+ SelectionListener loginSelectionListener) {
+ LoginEntryPoint.this.extendsCredentialsBlock(credentialsBlock,
+ selectedLocale, loginSelectionListener);
+ }
+
+ };
+ }
+
+ /**
+ * To be overridden. CmsLogin#createCredentialsBlock() should be called at
+ * some point in order to create the credentials composite. In order to use
+ * the default layout, call CmsLogin#defaultCreateContents() but <b>not</b>
+ * CmsLogin#createContent(), since it would lead to a stack overflow.
+ */
+ protected void createLoginPage(Composite parent, CmsLogin login) {
+ login.defaultCreateContents(parent);
+ }
+
+ protected void extendsCredentialsBlock(Composite credentialsBlock,
+ Locale selectedLocale, SelectionListener loginSelectionListener) {
+
+ }