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

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 mina-sshd, under directory /sshd-core/src/test/java/org/apache/sshd/server/jaas/.

Source file: JaasPasswordAuthenticatorTest.java

  26 
vote

@Before public void setUp(){
  Configuration config=new Configuration(){
    public AppConfigurationEntry[] getAppConfigurationEntry(    String name){
      return new AppConfigurationEntry[]{new AppConfigurationEntry(DummyLoginModule.class.getName(),AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,new HashMap<String,Object>())};
    }
    public void refresh(){
    }
  }
;
  Configuration.setConfiguration(config);
}
 

Example 2

From project nuxeo-tycho-osgi, under directory /nuxeo-runtime/nuxeo-runtime/src/main/java/org/nuxeo/runtime/api/login/.

Source file: LoginComponent.java

  26 
vote

@Override public void activate(ComponentContext context) throws Exception {
  Configuration parentConfig=null;
  try {
    parentConfig=Configuration.getConfiguration();
  }
 catch (  Exception e) {
  }
  config=new LoginConfiguration(this,parentConfig);
  Configuration.setConfiguration(config);
}
 

Example 3

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

Source file: DefaultJaasAuthenticationProviderTests.java

  26 
vote

@Before public void setUp() throws Exception {
  Configuration configuration=mock(Configuration.class);
  publisher=mock(ApplicationEventPublisher.class);
  log=mock(Log.class);
  provider=new DefaultJaasAuthenticationProvider();
  provider.setConfiguration(configuration);
  provider.setApplicationEventPublisher(publisher);
  provider.setAuthorityGranters(new AuthorityGranter[]{new TestAuthorityGranter()});
  provider.afterPropertiesSet();
  AppConfigurationEntry[] aces=new AppConfigurationEntry[]{new AppConfigurationEntry(TestLoginModule.class.getName(),LoginModuleControlFlag.REQUIRED,Collections.<String,Object>emptyMap())};
  when(configuration.getAppConfigurationEntry(provider.getLoginContextName())).thenReturn(aces);
  token=new UsernamePasswordAuthenticationToken("user","password");
  ReflectionTestUtils.setField(provider,"log",log);
}
 

Example 4

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

Source file: JBWSTokenIssuingLoginModuleUnitTestCase.java

  24 
vote

@Before public void setup() throws Exception {
  Configuration.setConfiguration(new Configuration(){
    @Override public void refresh(){
    }
    @Override public AppConfigurationEntry[] getAppConfigurationEntry(    String arg0){
      Map<String,Object> options=new HashMap<String,Object>();
      options.put("endpointAddress","http://localhost:8080/picketlink-sts");
      options.put("wspAppliesTo","http://services.testcorp.org/provider1");
      options.put("serviceName","PicketLinkSTS");
      options.put("portName","PicketLinkSTSPort");
      options.put("inject.callerprincipal","true");
      options.put("groupPrincipalName","Membership");
      options.put("username","UserA");
      options.put("password","PassA");
      AppConfigurationEntry entry=new AppConfigurationEntry(JBWSTokenIssuingLoginModule.class.getName(),LoginModuleControlFlag.REQUIRED,options);
      return new AppConfigurationEntry[]{entry};
    }
  }
);
}
 

Example 5

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

Source file: JaasAuthMethod.java

  23 
vote

@Override public void doInit(final String arg) throws RjException {
  this.configuration=Configuration.getConfiguration();
  if (this.configuration.getAppConfigurationEntry(JAAS_NAME) == null) {
    this.configuration=new JaasConfig(arg);
  }
  try {
    this.context=new LoginContext(JAAS_NAME,new Subject(),this,this.configuration);
  }
 catch (  final LoginException e) {
    e.printStackTrace();
  }
}
 

Example 6

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

Source file: JaasAuthenticationProvider.java

  23 
vote

public void afterPropertiesSet() throws Exception {
  Assert.hasLength(getLoginContextName(),"loginContextName must be set on " + getClass());
  Assert.notNull(loginConfig,"loginConfig must be set on " + getClass());
  configureJaas(loginConfig);
  Assert.notNull(Configuration.getConfiguration(),"As per http://java.sun.com/j2se/1.5.0/docs/api/javax/security/auth/login/Configuration.html " + "\"If a Configuration object was set via the Configuration.setConfiguration method, then that object is " + "returned. Otherwise, a default Configuration object is returned\". Your JRE returned null to "+ "Configuration.getConfiguration().");
}
 

Example 7

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

Source file: JaasAuthenticationProvider.java

  23 
vote

/** 
 * Hook method for configuring Jaas.
 * @param loginConfig URL to Jaas login configuration
 * @throws IOException if there is a problem reading the config resource.
 */
protected void configureJaas(Resource loginConfig) throws IOException {
  configureJaasUsingLoop();
  if (refreshConfigurationOnStartup) {
    Configuration.getConfiguration().refresh();
  }
}
 

Example 8

From project torquebox, under directory /modules/security/src/main/java/org/torquebox/security/auth/as/.

Source file: AuthSubsystemAdd.java

  23 
vote

protected void addTorqueBoxSecurityDomainService(final OperationContext context,ServiceVerificationHandler verificationHandler,List<ServiceController<?>> newControllers){
  final ApplicationPolicy applicationPolicy=new ApplicationPolicy(TORQUEBOX_DOMAIN);
  AuthenticationInfo authenticationInfo=new AuthenticationInfo(TORQUEBOX_DOMAIN);
  Map<String,Object> options=new HashMap<String,Object>();
  AppConfigurationEntry entry=new AppConfigurationEntry(ModulesMap.AUTHENTICATION_MAP.get("Simple"),LoginModuleControlFlag.REQUIRED,options);
  authenticationInfo.addAppConfigurationEntry(entry);
  applicationPolicy.setAuthenticationInfo(authenticationInfo);
  final SecurityDomainService securityDomainService=new SecurityDomainService(TORQUEBOX_DOMAIN,applicationPolicy,null,null);
  final ServiceTarget target=context.getServiceTarget();
  ServiceBuilder<SecurityDomainContext> builder=target.addService(SecurityDomainService.SERVICE_NAME.append(TORQUEBOX_DOMAIN),securityDomainService).addDependency(SecurityManagementService.SERVICE_NAME,ISecurityManagement.class,securityDomainService.getSecurityManagementInjector()).addDependency(JaasConfigurationService.SERVICE_NAME,Configuration.class,securityDomainService.getConfigurationInjector()).addListener(verificationHandler);
  newControllers.add(builder.setInitialMode(Mode.ON_DEMAND).install());
}
 

Example 9

From project torquebox, under directory /modules/security/src/main/java/org/torquebox/security/auth/processors/.

Source file: AuthInstaller.java

  23 
vote

private void addTorqueBoxSecurityDomainService(DeploymentPhaseContext context,TorqueBoxAuthConfig config){
  String domain=this.getTorqueBoxDomainServiceName();
  final ApplicationPolicy applicationPolicy=new ApplicationPolicy(domain);
  AuthenticationInfo authenticationInfo=new AuthenticationInfo(domain);
  Map<String,Object> options=new HashMap<String,Object>();
  Map<String,String> credentials=config.getCredentials();
  if (credentials != null) {
    options.put("credentials",credentials);
  }
  AppConfigurationEntry entry=new AppConfigurationEntry(TorqueBoxLoginModule.class.getName(),LoginModuleControlFlag.REQUIRED,options);
  authenticationInfo.addAppConfigurationEntry(entry);
  applicationPolicy.setAuthenticationInfo(authenticationInfo);
  final SecurityDomainService securityDomainService=new SecurityDomainService(domain,applicationPolicy,null,null);
  final ServiceTarget target=context.getServiceTarget();
  ServiceBuilder<SecurityDomainContext> builder=target.addService(SecurityDomainService.SERVICE_NAME.append(domain),securityDomainService).addDependency(SecurityManagementService.SERVICE_NAME,ISecurityManagement.class,securityDomainService.getSecurityManagementInjector()).addDependency(JaasConfigurationService.SERVICE_NAME,Configuration.class,securityDomainService.getConfigurationInjector());
  builder.setInitialMode(Mode.ON_DEMAND).install();
}
 

Example 10

From project zookeeper, under directory /src/java/main/org/apache/zookeeper/client/.

Source file: ZooKeeperSaslClient.java

  23 
vote

public boolean clientTunneledAuthenticationInProgress(){
  try {
    if ((System.getProperty(Environment.JAAS_CONF_KEY) != null) || ((javax.security.auth.login.Configuration.getConfiguration() != null) && (javax.security.auth.login.Configuration.getConfiguration().getAppConfigurationEntry(System.getProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY,"Client")) != null))) {
      if ((isComplete() == false) && (isFailed() == false)) {
        return true;
      }
      if (isComplete() || isFailed()) {
        if (gotLastPacket == false) {
          return true;
        }
      }
    }
    return false;
  }
 catch (  SecurityException e) {
    if (LOG.isDebugEnabled() == true) {
      LOG.debug("Could not retrieve login configuration: " + e);
    }
    return false;
  }
}
 

Example 11

From project zookeeper, under directory /src/java/main/org/apache/zookeeper/server/auth/.

Source file: SaslServerCallbackHandler.java

  23 
vote

public SaslServerCallbackHandler(Configuration configuration) throws IOException {
  String serverSection=System.getProperty(ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY,ZooKeeperSaslServer.DEFAULT_LOGIN_CONTEXT_NAME);
  AppConfigurationEntry configurationEntries[]=configuration.getAppConfigurationEntry(serverSection);
  if (configurationEntries == null) {
    String errorMessage="Could not find a 'Server' entry in this configuration: Server cannot start.";
    LOG.error(errorMessage);
    throw new IOException(errorMessage);
  }
  credentials.clear();
  for (  AppConfigurationEntry entry : configurationEntries) {
    Map<String,?> options=entry.getOptions();
    for (    Map.Entry<String,?> pair : options.entrySet()) {
      String key=pair.getKey();
      if (key.startsWith(USER_PREFIX)) {
        String userName=key.substring(USER_PREFIX.length());
        credentials.put(userName,(String)pair.getValue());
      }
    }
  }
}
 

Example 12

From project zookeeper, under directory /src/java/main/org/apache/zookeeper/server/.

Source file: ServerCnxnFactory.java

  23 
vote

/** 
 * Initialize the server SASL if specified. If the user has specified a "ZooKeeperServer.LOGIN_CONTEXT_NAME_KEY" or a jaas.conf using "java.security.auth.login.config" the authentication is required and an exception is raised. Otherwise no authentication is configured and no exception is raised.
 * @throws IOException if jaas.conf is missing or there's an error in it.
 */
protected void configureSaslLogin() throws IOException {
  String serverSection=System.getProperty(ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY,ZooKeeperSaslServer.DEFAULT_LOGIN_CONTEXT_NAME);
  AppConfigurationEntry entries[]=null;
  SecurityException securityException=null;
  try {
    entries=Configuration.getConfiguration().getAppConfigurationEntry(serverSection);
  }
 catch (  SecurityException e) {
    securityException=e;
  }
  if (entries == null) {
    String jaasFile=System.getProperty(Environment.JAAS_CONF_KEY);
    String loginContextName=System.getProperty(ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY);
    if (securityException != null && (loginContextName != null || jaasFile != null)) {
      String errorMessage="No JAAS configuration section named '" + serverSection + "' was found";
      if (jaasFile != null) {
        errorMessage+="in '" + jaasFile + "'.";
      }
      if (loginContextName != null) {
        errorMessage+=" But " + ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY + " was set.";
      }
      LOG.error(errorMessage);
      throw new IOException(errorMessage);
    }
    return;
  }
  try {
    saslServerCallbackHandler=new SaslServerCallbackHandler(Configuration.getConfiguration());
    login=new Login(serverSection,saslServerCallbackHandler);
    login.startThreadIfNeeded();
  }
 catch (  LoginException e) {
    throw new IOException("Could not configure server because SASL configuration did not allow the " + " ZooKeeper server to authenticate itself properly: " + e);
  }
}