Java Code Examples for javax.security.auth.login.LoginException

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project nuxeo-platform-login, under directory /nuxeo-platform-login-cas2/src/test/java/org/nuxeo/ecm/platform/ui/web/auth/simple/.

Source file: LoginModuleYes.java

  23 
vote

public boolean login() throws LoginException {
  NameCallback nc=new NameCallback("Username: ",SecurityConstants.ANONYMOUS);
  try {
    callbackHandler.handle(new Callback[]{nc});
    identity=createIdentity(nc.getName());
  }
 catch (  Exception e) {
    LoginException le=new LoginException();
    le.initCause(e);
    throw le;
  }
  return true;
}
 

Example 2

From project blog_1, under directory /miniprojects/jboss-custom-login/src/main/java/custom/.

Source file: MySimpleUsernamePasswordLoginModule.java

  21 
vote

/** 
 * (required) The groups of the user, there must be at least one group called "Roles" (though it likely can be empty) containing the roles the user has.
 */
@Override protected Group[] getRoleSets() throws LoginException {
  SimpleGroup group=new SimpleGroup("Roles");
  try {
    group.addMember(new SimplePrincipal("user_role"));
  }
 catch (  Exception e) {
    throw new LoginException("Failed to create group member for " + group);
  }
  return new Group[]{group};
}
 

Example 3

From project brix-cms, under directory /brix-rmiserver/src/main/java/org/brixcms/rmiserver/jackrabbit/.

Source file: ServerLoginModule.java

  21 
vote

private Credentials getCredentials() throws LoginException {
  if (callbackHandler == null) {
    throw new LoginException("Null callback handler");
  }
  CredentialsCallback ccb=new CredentialsCallback();
  try {
    callbackHandler.handle(new Callback[]{ccb});
  }
 catch (  Exception e) {
    throw new LoginException("Failed to retrieve login credentials");
  }
  return ccb.getCredentials();
}
 

Example 4

From project core_5, under directory /exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas/.

Source file: SharedStateLoginModule.java

  21 
vote

/** 
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked") public boolean login() throws LoginException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("in login");
  }
  try {
    String username=(String)sharedState.get("javax.security.auth.login.name");
    String password=(String)sharedState.get("javax.security.auth.login.password");
    if (username == null || password == null)     return false;
    Authenticator authenticator=(Authenticator)getContainer().getComponentInstanceOfType(Authenticator.class);
    if (authenticator == null) {
      throw new LoginException("No Authenticator component found, check your configuration");
    }
    Credential[] credentials=new Credential[]{new UsernameCredential(username),new PasswordCredential(password)};
    String userId=authenticator.validateUser(credentials);
    Identity identity=authenticator.createIdentity(userId);
    sharedState.put("exo.security.identity",identity);
    sharedState.put("javax.security.auth.login.name",userId);
    subject.getPrivateCredentials().add(password);
    subject.getPublicCredentials().add(new UsernameCredential(username));
    return true;
  }
 catch (  final Exception e) {
    LoginException le=new LoginException(e.getMessage());
    le.initCause(e);
    throw le;
  }
}
 

Example 5

From project gatein-sso, under directory /agent/src/main/java/org/gatein/sso/agent/login/.

Source file: SPNEGORolesModule.java

  21 
vote

@Override protected Group[] getRoleSets() throws LoginException {
  try {
    Group roles=new SimpleGroup("Roles");
    for (    String role : this.identity.getRoles()) {
      roles.addMember(this.createIdentity(role));
    }
    Group[] groups={roles};
    return groups;
  }
 catch (  Exception e) {
    throw new LoginException(e.getMessage());
  }
}
 

Example 6

From project gatein-wci_1, under directory /wci/src/main/java/org/gatein/wci/security/.

Source file: WCILoginModule.java

  21 
vote

/** 
 * @see javax.security.auth.spi.LoginModule#login()
 */
@SuppressWarnings("unchecked") public boolean login() throws LoginException {
  Callback[] callbacks=new Callback[2];
  callbacks[0]=new NameCallback("Username");
  callbacks[1]=new PasswordCallback("Password",false);
  try {
    callbackHandler.handle(callbacks);
    String password=new String(((PasswordCallback)callbacks[1]).getPassword());
    Credentials credentials=GenericAuthentication.TICKET_SERVICE.validateTicket(password,true);
    sharedState.put("javax.security.auth.login.name",credentials.getUsername());
    sharedState.put("javax.security.auth.login.password",credentials.getPassword());
  }
 catch (  Exception e) {
    LoginException le=new LoginException();
    le.initCause(e);
    throw le;
  }
  return true;
}
 

Example 7

From project integration-tests, under directory /picketlink-trust-tests/src/test/java/org/picketlink/test/trust/loginmodules/.

Source file: TestRequestUserLoginModule.java

  21 
vote

@Override protected String[] getUsernameAndPassword() throws LoginException {
  String WEB_REQUEST_KEY="javax.servlet.http.HttpServletRequest";
  try {
    String password=null;
    HttpServletRequest request=(HttpServletRequest)PolicyContext.getContext(WEB_REQUEST_KEY);
    String username=request.getParameter("user");
    if (username != null && "UserA".equals(username)) {
      password="PassA";
    }
 else     if (username != null && "UserB".equals(username)) {
      password="PassB";
    }
    return new String[]{username,password};
  }
 catch (  PolicyContextException e) {
    LoginException le=new LoginException();
    le.initCause(e);
    throw le;
  }
}
 

Example 8

From project Ivory, under directory /common/src/main/java/org/apache/ivory/security/.

Source file: IvoryLoginModule.java

  21 
vote

@Override public boolean commit() throws LoginException {
  if (!subject.getPrincipals(SecurityConstants.OS_PRINCIPAL_CLASS).isEmpty()) {
    return true;
  }
  Principal user=getCanonicalUser(SecurityConstants.OS_PRINCIPAL_CLASS);
  if (user != null) {
    subject.getPrincipals().add(new UnixPrincipal(user.getName()));
    return true;
  }
  LOG.error("No such user " + subject);
  throw new LoginException("No such user " + subject);
}
 

Example 9

From project jackrabbit-oak, under directory /oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/.

Source file: TokenAuthentication.java

  21 
vote

@Override public boolean authenticate(Credentials credentials) throws LoginException {
  if (tokenProvider != null && credentials instanceof TokenCredentials) {
    TokenCredentials tc=(TokenCredentials)credentials;
    if (!validateCredentials(tc)) {
      throw new LoginException("Invalid token credentials.");
    }
  }
  return false;
}
 

Example 10

From project mina-sshd, under directory /sshd-core/src/test/java/org/apache/sshd/server/jaas/.

Source file: JaasPasswordAuthenticatorTest.java

  21 
vote

public boolean login() throws LoginException {
  Callback[] callbacks=new Callback[2];
  callbacks[0]=new NameCallback("Username: ");
  callbacks[1]=new PasswordCallback("Password: ",false);
  try {
    callbackHandler.handle(callbacks);
  }
 catch (  IOException ioe) {
    throw new LoginException(ioe.getMessage());
  }
catch (  UnsupportedCallbackException uce) {
    throw new LoginException(uce.getMessage() + " not available to obtain information from user");
  }
  String user=((NameCallback)callbacks[0]).getName();
  char[] tmpPassword=((PasswordCallback)callbacks[1]).getPassword();
  return user.equals(new String(tmpPassword));
}
 

Example 11

From project nuxeo-services, under directory /nuxeo-platform-login/src/main/java/org/nuxeo/ecm/platform/login/.

Source file: NuxeoLoginModule.java

  21 
vote

@Override public Principal createIdentity(String username) throws LoginException {
  log.debug("createIdentity: " + username);
  try {
    NuxeoPrincipal principal;
    if (manager == null) {
      principal=new NuxeoPrincipalImpl(username);
    }
 else {
      principal=manager.getPrincipal(username);
      if (principal == null) {
        throw new LoginException(String.format("principal %s does not exist",username));
      }
    }
    String principalId=String.valueOf(random.nextLong());
    principal.setPrincipalId(principalId);
    return principal;
  }
 catch (  Exception e) {
    log.error("createIdentity failed",e);
    LoginException le=new LoginException("createIdentity failed for user " + username);
    le.initCause(e);
    throw le;
  }
}
 

Example 12

From project nuxeo-webengine, under directory /nuxeo-webengine-jaxrs/src/main/java/org/nuxeo/ecm/webengine/jaxrs/login/.

Source file: AuthenticationFilter.java

  21 
vote

protected LoginContext doLogin(HttpServletRequest request,HttpServletResponse response) throws LoginException {
  String[] login=retrieveBasicLogin(request);
  if (login != null) {
    return Framework.login(login[0],login[1]);
  }
  throw new LoginException("User must login");
}
 

Example 13

From project picketlink-integration-tests, under directory /unit-tests/trust/src/test/java/org/picketlink/test/trust/loginmodules/.

Source file: TestRequestUserLoginModule.java

  21 
vote

@Override protected String[] getUsernameAndPassword() throws LoginException {
  String WEB_REQUEST_KEY="javax.servlet.http.HttpServletRequest";
  try {
    String password=null;
    HttpServletRequest request=(HttpServletRequest)PolicyContext.getContext(WEB_REQUEST_KEY);
    String username=request.getParameter("user");
    if (username != null && "UserA".equals(username)) {
      password="PassA";
    }
 else     if (username != null && "UserB".equals(username)) {
      password="PassB";
    }
    return new String[]{username,password};
  }
 catch (  PolicyContextException e) {
    LoginException le=new LoginException();
    le.initCause(e);
    throw le;
  }
}
 

Example 14

From project rundeck, under directory /rundeck-launcher/rundeck-jetty-server/src/main/java/com/dtolabs/rundeck/jetty/jaas/.

Source file: JettyCachingLdapLoginModule.java

  21 
vote

public boolean commit() throws LoginException {
  try {
    _rootContext.close();
  }
 catch (  NamingException e) {
    throw new LoginException("error closing root context: " + e.getMessage());
  }
  return super.commit();
}
 

Example 15

From project cas, under directory /cas-server-core/src/test/java/org/jasig/cas/authentication/handler/support/.

Source file: MockLoginModule.java

  20 
vote

public boolean login() throws LoginException {
  final Callback[] callbacks=new Callback[]{new NameCallback("f"),new PasswordCallback("f",false)};
  try {
    this.callbackHandler.handle(callbacks);
  }
 catch (  Exception e) {
    throw new LoginException();
  }
  final String userName=((NameCallback)callbacks[0]).getName();
  final String password=new String(((PasswordCallback)callbacks[1]).getPassword());
  if (userName.equals("test") && password.equals("test")) {
    return true;
  }
  throw new LoginException();
}
 

Example 16

From project chililog-server, under directory /src/main/java/org/chililog/server/engine/.

Source file: JAASLoginModule.java

  20 
vote

/** 
 * <p> We check the credentials against the repository. By convention, the username is the repository name and the password is either the publisher or subscriber password. The role assigned to the user is constructed from the combination of username and publisher password. </p>
 * @return Returns true if this method succeeded, or false if this LoginModule should be ignored.
 */
public boolean login() throws LoginException {
  try {
    Iterator<Principal> iterator=_subject.getPrincipals().iterator();
    String username=iterator.next().getName();
    if (StringUtils.isBlank(username)) {
      throw new FailedLoginException("Username is requried.");
    }
    Iterator<char[]> iterator2=_subject.getPrivateCredentials(char[].class).iterator();
    char[] passwordChars=iterator2.next();
    String password=new String(passwordChars);
    if (StringUtils.isBlank(password)) {
      throw new FailedLoginException("Password is requried.");
    }
    if (username.equals(_systemUsername) && password.equals(_systemPassword)) {
      Group roles=new SimpleGroup("Roles");
      roles.addMember(new SimplePrincipal(UserBO.SYSTEM_ADMINISTRATOR_ROLE_NAME));
      _subject.getPrincipals().add(roles);
      return true;
    }
    DB db=MongoConnection.getInstance().getConnection();
    UserBO user=UserController.getInstance().tryGetByUsername(db,username);
    if (user == null) {
      throw new FailedLoginException("Invalid username or password.");
    }
    if (StringUtils.isBlank(password) || !user.validatePassword(password)) {
      throw new FailedLoginException("Invalid username or password.");
    }
    Group roles=new SimpleGroup("Roles");
    for (    String role : user.getRoles()) {
      roles.addMember(new SimplePrincipal(role));
    }
    _subject.getPrincipals().add(roles);
    return true;
  }
 catch (  Exception ex) {
    throw new LoginException(ex.getMessage());
  }
}
 

Example 17

From project jspwiki, under directory /src/org/apache/wiki/auth/login/.

Source file: AnonymousLoginModule.java

  20 
vote

/** 
 * Logs in the user by calling back to the registered CallbackHandler with an HttpRequestCallback. The CallbackHandler must supply the current servlet HTTP request as its response.
 * @return the result of the login; this will always be <code>true</code>.
 * @see javax.security.auth.spi.LoginModule#login()
 * @throws {@inheritDoc}
 */
public boolean login() throws LoginException {
  HttpRequestCallback hcb=new HttpRequestCallback();
  Callback[] callbacks=new Callback[]{hcb};
  try {
    m_handler.handle(callbacks);
    HttpServletRequest request=hcb.getRequest();
    WikiPrincipal ipAddr=new WikiPrincipal(request.getRemoteAddr());
    if (log.isDebugEnabled()) {
      HttpSession session=request.getSession(false);
      String sid=(session == null) ? NULL : session.getId();
      log.debug("Logged in session ID=" + sid + "; IP="+ ipAddr);
    }
    m_principals.add(ipAddr);
    return true;
  }
 catch (  IOException e) {
    log.error("IOException: " + e.getMessage());
    return false;
  }
catch (  UnsupportedCallbackException e) {
    String message="Unable to handle callback, disallowing login.";
    log.error(message,e);
    throw new LoginException(message);
  }
}
 

Example 18

From project karaf, under directory /jaas/modules/src/main/java/org/apache/karaf/jaas/modules/ldap/.

Source file: LDAPLoginModule.java

  20 
vote

protected void setupSsl(Hashtable env) throws LoginException {
  ServiceReference ref=null;
  try {
    logger.debug("Setting up SSL");
    env.put(Context.SECURITY_PROTOCOL,"ssl");
    env.put("java.naming.ldap.factory.socket",ManagedSSLSocketFactory.class.getName());
    ref=bundleContext.getServiceReference(KeystoreManager.class.getName());
    KeystoreManager manager=(KeystoreManager)bundleContext.getService(ref);
    SSLSocketFactory factory=manager.createSSLFactory(sslProvider,sslProtocol,sslAlgorithm,sslKeystore,sslKeyAlias,sslTrustStore);
    ManagedSSLSocketFactory.setSocketFactory(factory);
    Thread.currentThread().setContextClassLoader(ManagedSSLSocketFactory.class.getClassLoader());
  }
 catch (  Exception e) {
    throw new LoginException("Unable to setup SSL support for LDAP: " + e.getMessage());
  }
 finally {
    bundleContext.ungetService(ref);
  }
}
 

Example 19

From project nuxeo-tycho-osgi, under directory /nuxeo-core/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/local/.

Source file: ClientLoginModule.java

  20 
vote

/** 
 * Authenticates a Subject (phase 1).
 */
@Override public boolean login() throws LoginException {
  if (useFirstPass) {
    return true;
  }
  if (callbackHandler == null) {
    throw new LoginException("Error: no CallbackHandler available " + "to garner authentication information from the user");
  }
  PasswordCallback pc=new PasswordCallback("Password: ",false);
  NameCallback nc=new NameCallback("User name: ","guest");
  Callback[] callbacks={nc,pc};
  try {
    callbackHandler.handle(callbacks);
    username=nc.getName();
    char[] tmpPassword=pc.getPassword();
    if (tmpPassword != null) {
      password=new char[tmpPassword.length];
      System.arraycopy(tmpPassword,0,password,0,tmpPassword.length);
      pc.clearPassword();
    }
  }
 catch (  IOException ioe) {
    throw new LoginException(ioe.toString());
  }
catch (  UnsupportedCallbackException uce) {
    throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information "+ "from the user");
  }
  return true;
}
 

Example 20

From project picketlink-idm, under directory /picketlink-idm-auth/src/main/java/org/picketlink/idm/auth/.

Source file: JBossIdentityIDMLoginModule.java

  20 
vote

protected Group[] getRoleSets() throws LoginException {
  try {
    TransactionManager tm=TransactionManagerProvider.JBOSS_PROVIDER.getTransactionManager();
    return (Group[])Transactions.required(tm,new Transactions.Runnable(){
      public Object run() throws Exception {
        IdentitySession ids=getIdentitySessionFactory().getCurrentIdentitySession(realmName);
        ids.beginTransaction();
        if (manageTransaction != null && manageTransaction.equals("true")) {
          ids.beginTransaction();
        }
        Group[] result=_getRoleSets();
        if (manageTransaction != null && manageTransaction.equals("true")) {
          ids.getTransaction().commit();
        }
        return result;
      }
    }
);
  }
 catch (  Exception e) {
    Throwable cause=e.getCause();
    throw new LoginException(cause.toString());
  }
}
 

Example 21

From project picketlink-idm_1, under directory /picketlink-idm-auth/src/main/java/org/picketlink/idm/auth/.

Source file: JBossIdentityIDMLoginModule.java

  20 
vote

protected Group[] getRoleSets() throws LoginException {
  try {
    TransactionManager tm=TransactionManagerProvider.JBOSS_PROVIDER.getTransactionManager();
    return (Group[])Transactions.required(tm,new Transactions.Runnable(){
      public Object run() throws Exception {
        IdentitySession ids=getIdentitySessionFactory().getCurrentIdentitySession(realmName);
        ids.beginTransaction();
        if (manageTransaction != null && manageTransaction.equals("true")) {
          ids.beginTransaction();
        }
        Group[] result=_getRoleSets();
        if (manageTransaction != null && manageTransaction.equals("true")) {
          ids.getTransaction().commit();
        }
        return result;
      }
    }
);
  }
 catch (  Exception e) {
    Throwable cause=e.getCause();
    throw new LoginException(cause.toString());
  }
}
 

Example 22

From project rj-core, under directory /de.walware.rj.server/src/de/walware/rj/server/srvstdext/.

Source file: JaasAuthMethod.java

  20 
vote

@Override protected String doPerformLogin(final Callback[] callbacks) throws LoginException, RjException {
  this.pendingLoginCallback=callbacks;
  this.pendingLogin=PERFORM;
synchronized (this) {
    while (this.loginThread.isAlive()) {
      notifyAll();
      try {
        wait();
      }
 catch (      final InterruptedException e) {
      }
    }
  }
  if (this.pendingLogin != LOGGED_IN) {
    if (this.pendingLoginMsg != null) {
      throw new LoginException(this.pendingLoginMsg);
    }
 else {
      throw new SecurityException("",null);
    }
  }
  return null;
}
 

Example 23

From project servicemix4-bundles, under directory /hadoop-core-0.20.203.0/src/main/java/org/apache/hadoop/security/.

Source file: UserGroupInformation.java

  20 
vote

@Override public boolean commit() throws LoginException {
  if (!subject.getPrincipals(User.class).isEmpty()) {
    return true;
  }
  Principal user=null;
  if (useKerberos) {
    user=getCanonicalUser(KerberosPrincipal.class);
  }
  if (user == null) {
    user=getCanonicalUser(OS_PRINCIPAL_CLASS);
  }
  if (user != null) {
    subject.getPrincipals().add(new User(user.getName()));
    return true;
  }
  LOG.error("Can't find user in " + subject);
  throw new LoginException("Can't find user name");
}
 

Example 24

From project alfredo, under directory /alfredo/src/main/java/com/cloudera/alfredo/server/.

Source file: KerberosAuthenticationHandler.java

  19 
vote

/** 
 * Releases any resources initialized by the authentication handler. <p/> It destroys the Kerberos context.
 */
@Override public void destroy(){
  try {
    if (loginContext != null) {
      loginContext.logout();
    }
  }
 catch (  LoginException ex) {
    LOG.warn(ex.getMessage(),ex);
  }
}
 

Example 25

From project coala, under directory /documentation/demos/jsf_gui/coala_gui/src/main/java/beans/.

Source file: LoginBean.java

  19 
vote

/** 
 * Tries to login the user. If username as well as password are correctly spelled this method returns the PatientSearch-Site,  if not the Login-Failed Site will be returned.
 * @return correct login: PatientSearch, else LoginFailed
 * @throws Exception 
 */
public String login() throws Exception {
  try {
    LoginContext lc=new LoginContext("Test");
    lc.login();
  }
 catch (  LoginException e) {
    e.printStackTrace();
  }
 finally {
    return "/errorPage.xhtml";
  }
}
 

Example 26

From project core_1, under directory /security/src/main/java/org/switchyard/security/.

Source file: JaasSecurityProvider.java

  19 
vote

/** 
 * {@inheritDoc}
 */
@Override public boolean authenticate(ServiceSecurity serviceSecurity,SecurityContext securityContext){
  boolean success=false;
  Class<?> ch_clazz=serviceSecurity.getCallbackHandler();
  if (ch_clazz == null) {
    ch_clazz=NamePasswordCallbackHandler.class;
  }
  CallbackHandler ch=(CallbackHandler)Construction.construct(ch_clazz);
  if (ch instanceof SwitchYardCallbackHandler) {
    SwitchYardCallbackHandler sych=(SwitchYardCallbackHandler)ch;
    sych.setProperties(serviceSecurity.getProperties());
    sych.setCredentials(securityContext.getCredentials());
  }
  String domain=Strings.trimToNull(serviceSecurity.getModuleName());
  if (domain == null) {
    domain="other";
  }
  Subject subject=securityContext.getSubject(domain);
  try {
    new LoginContext(domain,subject,ch).login();
    success=true;
  }
 catch (  LoginException le) {
    LOGGER.error("authenticate LoginException: " + le.getMessage(),le);
  }
  return success;
}
 

Example 27

From project hcatalog, under directory /src/java/org/apache/hcatalog/common/.

Source file: HCatUtil.java

  19 
vote

/** 
 * Get or create a hive client depending on whether it exits in cache or not
 * @param hiveConf The hive configuration
 * @return the client
 * @throws MetaException When HiveMetaStoreClient couldn't be created
 * @throws IOException
 */
public static HiveMetaStoreClient getHiveClient(HiveConf hiveConf) throws MetaException, IOException {
  if (hiveClientCache == null) {
synchronized (HiveMetaStoreClient.class) {
      if (hiveClientCache == null) {
        hiveClientCache=new HiveClientCache(hiveConf.getInt(HCatConstants.HCAT_HIVE_CLIENT_EXPIRY_TIME,DEFAULT_HIVE_CACHE_EXPIRY_TIME_SECONDS));
      }
    }
  }
  try {
    return hiveClientCache.get(hiveConf);
  }
 catch (  LoginException e) {
    throw new IOException("Couldn't create hiveMetaStoreClient, Error getting UGI for user",e);
  }
}
 

Example 28

From project java-cas-client, under directory /cas-client-core/src/main/java/org/jasig/cas/client/jaas/.

Source file: CasLoginModule.java

  19 
vote

public final boolean abort() throws LoginException {
  if (this.ticket != null) {
    this.ticket=null;
  }
  if (this.assertion != null) {
    this.assertion=null;
  }
  return true;
}
 

Example 29

From project nuxeo-chemistry, under directory /nuxeo-opencmis-bindings/src/main/java/org/nuxeo/ecm/core/opencmis/bindings/.

Source file: NuxeoCmisAuthHandler.java

  19 
vote

@Override public boolean handleMessage(MessageHandlerContext context){
  boolean res=super.handleMessage(context);
  @SuppressWarnings("unchecked") Map<String,String> callContextMap=(Map<String,String>)context.get(AbstractService.CALL_CONTEXT_MAP);
  if (callContextMap != null) {
    String username=callContextMap.get(CallContext.USERNAME);
    String password=callContextMap.get(CallContext.PASSWORD);
    try {
      LoginContext loginContext=getLoginProvider().login(username,password);
      context.put(NUXEO_LOGIN_CONTEXT,loginContext);
      context.setScope(NUXEO_LOGIN_CONTEXT,Scope.APPLICATION);
    }
 catch (    LoginException e) {
      throw new RuntimeException("Login failed for user '" + username + "'",e);
    }
  }
  return res;
}
 

Example 30

From project nuxeo-cmf, under directory /nuxeo-case-management-core/src/main/java/org/nuxeo/cm/core/usermanager/.

Source file: CaseManagementGroupComputer.java

  19 
vote

protected LoginContext loginOnContext(String username) throws LoginException {
  if (!Framework.isTestModeSet()) {
    UserIdentificationInfo userIdent=new UserIdentificationInfo(username,"");
    userIdent.setLoginPluginName("Trusting_LM");
    CallbackHandler handler=new UserIdentificationInfoCallbackHandler(userIdent);
    LoginContext loginContext=new LoginContext("nuxeo-ecm-web",handler);
    loginContext.login();
    return loginContext;
  }
  return null;
}
 

Example 31

From project nuxeo-jsf, under directory /nuxeo-platform-webapp-base/src/main/java/org/nuxeo/ecm/webapp/delegate/.

Source file: DocumentManagerBusinessDelegate.java

  19 
vote

@Destroy @PermitAll public void remove(){
  LoginContext lc=null;
  try {
    try {
      if (Framework.getRuntime() != null) {
        lc=Framework.login();
      }
    }
 catch (    LoginException le) {
      log.error("Unable to login as System",le);
      log.warn("...try to feed CoreSession(s) without system login ...");
    }
    for (    Entry<RepositoryLocation,CoreSession> entry : sessions.entrySet()) {
      String serverName=entry.getKey().getName();
      CoreSession session=entry.getValue();
      Repository.close(session);
      log.debug("Closed session for repository " + serverName);
    }
  }
  finally {
    if (lc != null) {
      try {
        lc.logout();
      }
 catch (      LoginException lo) {
        log.error("Error when logout",lo);
      }
    }
    sessions.clear();
  }
}
 

Example 32

From project nuxeo-opensocial, under directory /nuxeo-webengine-gadgets/src/main/java/org/nuxeo/opensocial/webengine/gadgets/render/.

Source file: NuxeoContextHelper.java

  19 
vote

protected synchronized void fetchContextInfo(){
  LoginContext loginContext=null;
  try {
    loginContext=Framework.login();
    RepositoryManager rm=Framework.getLocalService(RepositoryManager.class);
    repoNames=new HashMap<String,String>();
    for (    Repository repo : rm.getRepositories()) {
      repoNames.put(repo.getName(),repo.getLabel());
      if (repo.isDefault() || "default".equals(repo.getName())) {
        defaultRepoName=repo.getName();
      }
    }
  }
 catch (  Exception e) {
  }
 finally {
    if (loginContext != null) {
      try {
        loginContext.logout();
      }
 catch (      LoginException e) {
      }
    }
  }
}
 

Example 33

From project overthere, under directory /src/main/java/com/xebialabs/overthere/cifs/winrm/connector/.

Source file: ApacheHttpComponentsHttpClientHttpConnector.java

  19 
vote

/** 
 * Perform the JAAS login and run the command within a privileged scope.
 * @param privilegedSendMessage the PrivilegedSendMessage
 * @return The result Document
 */
private Document runPrivileged(final PrivilegedSendMessage privilegedSendMessage){
  final CallbackHandler handler=new ProvidedAuthCallback(username,password);
  Document result;
  try {
    final LoginContext lc=new LoginContext("",null,handler,new KerberosJaasConfiguration(debugKerberosAuth));
    lc.login();
    result=Subject.doAs(lc.getSubject(),privilegedSendMessage);
  }
 catch (  LoginException e) {
    throw new WinRMRuntimeIOException("Login failure sending message on " + getTargetURL() + " error: "+ e.getMessage(),privilegedSendMessage.getRequestDocument(),null,e);
  }
catch (  PrivilegedActionException e) {
    throw new WinRMRuntimeIOException("Failure sending message on " + getTargetURL() + " error: "+ e.getMessage(),privilegedSendMessage.getRequestDocument(),null,e.getException());
  }
  return result;
}
 

Example 34

From project remitt, under directory /src/main/java/org/remitt/server/jaas/.

Source file: HttpLoginModule.java

  19 
vote

@Override public boolean commit() throws LoginException {
  System.out.println("HttpLoginModule commit()");
  if (!loginSucceeded) {
  }
  assignPrincipal(user);
  for (  Principal role : roles) {
    assignPrincipal(role);
  }
  username=null;
  commitSucceeded=true;
  for (  Principal s : subject.getPrincipals()) {
    System.out.println("Found principal " + s.getName() + " in subject");
  }
  return true;
}
 

Example 35

From project rj-servi, under directory /de.walware.rj.servi/src/de/walware/rj/servi/internal/.

Source file: NodeServer.java

  19 
vote

@Override public Object execute(final String command,final Map<String,? extends Object> properties,final ServerLogin login) throws RemoteException, LoginException {
  if (command.equals(C_CONSOLE_START)) {
    throw new UnsupportedOperationException();
  }
  if (command.equals(C_CONSOLE_CONNECT)) {
synchronized (this.internalEngine) {
      if (!this.isConsoleEnabled) {
        throw new RemoteException("Console is not enabled.");
      }
      final Client client=connectClient(command,login);
      return this.internalEngine.connect(client,properties);
    }
  }
  if (command.equals(C_RSERVI_NODECONTROL)) {
    final Client client=connectClient(command,login);
    final Node node=new Node();
    final RServiNode exported=(RServiNode)UnicastRemoteObject.exportObject(node,0);
    return exported;
  }
  throw new UnsupportedOperationException();
}
 

Example 36

From project security, under directory /impl/src/main/java/org/jboss/seam/security/jaas/.

Source file: JaasAuthenticator.java

  19 
vote

public void authenticate(){
  if (getJaasConfigName() == null) {
    throw new IllegalStateException("jaasConfigName cannot be null.  Please set it to a valid JAAS configuration name.");
  }
  try {
    getLoginContext().login();
    setStatus(AuthenticationStatus.SUCCESS);
  }
 catch (  LoginException e) {
    setStatus(AuthenticationStatus.FAILURE);
    log.error("JAAS authentication failed",e);
  }
}
 

Example 37

From project soja, under directory /soja-server/src/main/java/com/excilys/soja/server/handler/.

Source file: ServerHandler.java

  19 
vote

/** 
 * Handle CONNECT command
 * @param frame
 * @throws SocketException
 */
public void handleConnect(final Channel channel,Frame frame) throws LoginException, UnsupportedVersionException, AlreadyConnectedException, SocketException {
  if (clientsSessionToken.containsKey(channel)) {
    throw new AlreadyConnectedException("User try to connect but it seems to be already connected");
  }
  String[] acceptedVersions=frame.getHeader().get(HEADER_ACCEPT_VERSION,"").split(",");
  if (!ArrayUtils.contains(acceptedVersions,STOMP_VERSION)) {
    sendError(channel,"Supported version doesn't match","Supported protocol version is " + STOMP_VERSION);
    throw new UnsupportedVersionException("The server doesn't support the same STOMP version as the client : server=" + STOMP_VERSION + ", client="+ acceptedVersions);
  }
  String login=frame.getHeaderValue(HEADER_LOGIN);
  String password=frame.getHeaderValue(HEADER_PASSCODE);
  try {
    LOGGER.trace("Check credentials for {}",login);
    String clientSessionToken=authentication.connect(login,password);
    clientsSessionToken.put(channel,clientSessionToken);
    ConnectedFrame connectedFrame=new ConnectedFrame(STOMP_VERSION);
    connectedFrame.setSession(clientSessionToken);
    connectedFrame.setServerName(StompServer.SERVER_HEADER_VALUE);
    if (startLocalHeartBeat(channel,frame)) {
      connectedFrame.setHeartBeat(getLocalGuaranteedHeartBeat(),getLocalExpectedHeartBeat());
    }
    sendFrame(channel,connectedFrame);
    fireConnectedListeners(channel);
  }
 catch (  LoginException e) {
    sendError(channel,"Bad credentials","Username or passcode incorrect");
    throw e;
  }
}
 

Example 38

From project spring-security, under directory /core/src/main/java/org/springframework/security/authentication/jaas/.

Source file: AbstractJaasAuthenticationProvider.java

  19 
vote

/** 
 * Attempts to login the user given the Authentication objects principal and credential
 * @param auth The Authentication object to be authenticated.
 * @return The authenticated Authentication object, with it's grantedAuthorities set.
 * @throws AuthenticationException This implementation does not handle 'locked' or 'disabled' accounts. This methodonly throws a AuthenticationServiceException, with the message of the LoginException that will be thrown, should the loginContext.login() method fail.
 */
public Authentication authenticate(Authentication auth) throws AuthenticationException {
  if (!(auth instanceof UsernamePasswordAuthenticationToken)) {
    return null;
  }
  UsernamePasswordAuthenticationToken request=(UsernamePasswordAuthenticationToken)auth;
  Set<GrantedAuthority> authorities;
  try {
    LoginContext loginContext=createLoginContext(new InternalCallbackHandler(auth));
    loginContext.login();
    authorities=new HashSet<GrantedAuthority>();
    Set<Principal> principals=loginContext.getSubject().getPrincipals();
    for (    Principal principal : principals) {
      for (      AuthorityGranter granter : authorityGranters) {
        Set<String> roles=granter.grant(principal);
        if ((roles != null) && !roles.isEmpty()) {
          for (          String role : roles) {
            authorities.add(new JaasGrantedAuthority(role,principal));
          }
        }
      }
    }
    JaasAuthenticationToken result=new JaasAuthenticationToken(request.getPrincipal(),request.getCredentials(),new ArrayList<GrantedAuthority>(authorities),loginContext);
    publishSuccessEvent(result);
    return result;
  }
 catch (  LoginException loginException) {
    AuthenticationException ase=loginExceptionResolver.resolveException(loginException);
    publishFailureEvent(request,ase);
    throw ase;
  }
}