Java Code Examples for javax.security.auth.login.LoginException#printStackTrace()

The following examples show how to use javax.security.auth.login.LoginException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelloWorldServlet.java    From cloud-weatherapp with Apache License 2.0 6 votes vote down vote up
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
  {
      String user = request.getRemoteUser();
      
      if (user != null)
      {
          response.getWriter().println("Hello, " + user);
      }
      else
      {
          LoginContext loginContext;
          
  	   try 
          {
              loginContext =  LoginContextFactory.createLoginContext("FORM");
  		    loginContext.login();
              response.getWriter().println("Hello, " + request.getRemoteUser());
          } 
          catch (LoginException ex) 
          {
               ex.printStackTrace();
  	   }
      }
  }
 
Example 2
Source File: DiscordService.java    From Game with GNU General Public License v3.0 5 votes vote down vote up
private void startPlayerBot(final String token) {
	this.builder = new JDABuilder(AccountType.BOT);
	this.builder.setEventManager(new AnnotatedEventManager());
	this.builder.addEventListeners(this);
	this.builder.setToken(token);
	try {
		this.jda = this.builder.build();
	} catch (final LoginException a) {
		a.printStackTrace();
	}
}
 
Example 3
Source File: TestOnlyCoreOperationAdvisor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean performLogin(Object shell){
	
	System.out.println("ATTENTION - login handled by " + getClass().getName());
	
	CoreHub.reconfigureServices();
	CoreHub.logoffAnwender();
	
	IUser user;
	try {
		user = loginServices.get(0).performLogin(null);
	} catch (LoginException e) {
		e.printStackTrace();
		return false;
	}
	
	if (user != null && user.isActive()) {
		// set user in system
		ContextServiceHolder.get().setActiveUser(user);
		ElexisEventDispatcher.getInstance().fire(new ElexisEvent(CoreHub.getLoggedInContact(),
			Anwender.class, ElexisEvent.EVENT_USER_CHANGED));
		
		CoreOperationAdvisorHolder.get().adaptForUser();
		CoreHub.getLoggedInContact().setInitialMandator();
		CoreHub.userCfg = CoreHub.getUserSetting(CoreHub.getLoggedInContact());
		CoreHub.heart.resume(true);
		
		return true;
	}
	
	return false;
}
 
Example 4
Source File: SessionConfigurator.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void afterResponse( HandshakeResponse hr ) {
  try {
    if ( loginContext != null ) {
      loginContext.logout();
    }
  } catch ( LoginException e ) {
    e.printStackTrace();
    //work is done just ignore
  }
}
 
Example 5
Source File: ConfigConstructor.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // test non-null behavior with provided config
        LoginContext lc = new LoginContext
                        ("module1",
                        s,
                        ch,
                        c);
        lc.login();
        System.out.println("Test 1 Passed");

        // test null behavior with provided config
        LoginContext lc2 = new LoginContext
                        ("module2",
                        null,
                        null,
                        c);
        lc2.login();
        System.out.println("Test 2 Passed");

        // test null config
        LoginContext lc3 = new LoginContext
                        ("module3",
                        s,
                        ch,
                        null);
        lc3.login();
        System.out.println("Test 3 Passed");

        // test null config
        LoginContext lc4 = new LoginContext
                        ("module4",
                        null,
                        null,
                        null);
        lc4.login();
        System.out.println("Test 4 Passed");

        // test security (without permission)
        try {
            LoginContext lc5 = new LoginContext
                        ("module5",
                        null,
                        null,
                        c);
            lc5.login();
            throw new SecurityException("test failed - security check failed");
        } catch (LoginException le) {
            if (le.getCause() instanceof SecurityException) {
                // test passed
            } else {
                le.printStackTrace();
                throw new SecurityException("test failed: " +
                    "LoginException did not have chained SecurityException");
            }
        }
        System.out.println("Test 5 Passed");

        // test security (with permission)
        LoginContext lc6 = new LoginContext
                        ("module6",
                        null,
                        null,
                        c);
        lc6.login();
        System.out.println("Test 6 Passed");

        // test other
        LoginContext lc7 = new LoginContext
                        ("goToOther",
                        null,
                        null,
                        c);
        lc7.login();
        System.out.println("Test 7 Passed");

        // test other old constructor
        LoginContext lc8 = new LoginContext
                        ("goToOther");
        lc8.login();
        System.out.println("Test 8 Passed");
    }
 
Example 6
Source File: KerberosHelper.java    From antsdb with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean login(String userid, String password) {
	// Kerberos is not configured properly, return false
	if (_realm == null || _realm.isEmpty() || 
			_kdc == null || _kdc.isEmpty() || _jaasConf == null) {
		_log.error("Kerberos auth is not configured.");
		return false;
	}
	
	boolean result = false;

	// 1. Set up Kerberos properties - have to set through java -D....
	//  -Djava.security.krb5.realm=BLUE-ANTS.CLOUDAPP.NET 
	//  -Djava.security.krb5.kdc=blue-ants.cloudapp.net
	//  -Djava.security.auth.login.config=/Users/kylechen/antsdb/0705/salted-fish/fish-server/hbase-db/jaas.conf
       System.setProperty("java.security.auth.login.config", _jaasConf);
	System.setProperty("java.security.krb5.realm", _realm);  
	System.setProperty("java.security.krb5.kdc", _kdc);  

       System.setProperty("sun.security.krb5.debug", "true");
       System.setProperty("javax.security.auth.useSubjectCredsOnly", "true");

       // 2. Authenticate against the KDC using JAAS and return the Subject.
       LoginContext loginCtx = null;
       // "Client" references the corresponding JAAS configuration section in the jaas.conf file.
       KerberosCallbackHandler callback = new KerberosCallbackHandler(userid, password);
       try {
         loginCtx = new LoginContext("Client", callback);
         loginCtx.login();
       }
       catch ( LoginException e) {
       	_log.error("Client: There was an error during the JAAS login: " + e);
         e.printStackTrace();
         return false;
      }

       Subject subject = loginCtx.getSubject();

       if (subject != null) result = true;

       return result;
}
 
Example 7
Source File: MarketableServicePublishCtrl.java    From development with Apache License 2.0 4 votes vote down vote up
private void handleRestrictedMarketplaceAccess(VOMarketplace mpl,
        VOService service) throws ObjectNotFoundException,
                OperationNotPermittedException {

    boolean displayWarnMsg = false;
    String warnedOrgs = "";

    List<VOCustomerService> customerServices = serviceProvisioning
            .getServiceCustomerTemplates(
                    model.getServiceDetails().getService());

    int i = 0;
    for (VOCustomerService customerService : customerServices) {

        String orgName = customerService.getOrganizationName();
        String orgId = customerService.getOrganizationId();

        boolean isAccessible = false;
        try {
            isAccessible = mplService
                    .doesOrganizationHaveAccessMarketplace(
                            mpl.getMarketplaceId(), orgId);
        } catch (LoginException e) {
            e.printStackTrace();
        }

        if (!isAccessible) {
            displayWarnMsg = true;
            if (i != 0) {
                warnedOrgs += ", ";
            }
            warnedOrgs += orgName + " (" + orgId + ")";
        }
        i++;
    }

    if (displayWarnMsg) {
        JSFUtils.addMessage(null, FacesMessage.SEVERITY_WARN,
                BaseBean.WARNING_NO_CUSTOMER_ACCESS_TO_RESTRICTED_MPL,
                new Object[] { warnedOrgs, mpl.getName() });
    }
}