use of javax.security.auth.kerberos.KerberosPrincipal in project hadoop by apache.
the class TestMiniKdc method testKerberosLogin.
@Test
public void testKerberosLogin() throws Exception {
MiniKdc kdc = getKdc();
File workDir = getWorkDir();
LoginContext loginContext = null;
try {
String principal = "foo";
File keytab = new File(workDir, "foo.keytab");
kdc.createPrincipal(keytab, principal);
Set<Principal> principals = new HashSet<Principal>();
principals.add(new KerberosPrincipal(principal));
//client login
Subject subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
loginContext = new LoginContext("", subject, null, KerberosConfiguration.createClientConfig(principal, keytab));
loginContext.login();
subject = loginContext.getSubject();
Assert.assertEquals(1, subject.getPrincipals().size());
Assert.assertEquals(KerberosPrincipal.class, subject.getPrincipals().iterator().next().getClass());
Assert.assertEquals(principal + "@" + kdc.getRealm(), subject.getPrincipals().iterator().next().getName());
loginContext.logout();
//server login
subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
loginContext = new LoginContext("", subject, null, KerberosConfiguration.createServerConfig(principal, keytab));
loginContext.login();
subject = loginContext.getSubject();
Assert.assertEquals(1, subject.getPrincipals().size());
Assert.assertEquals(KerberosPrincipal.class, subject.getPrincipals().iterator().next().getClass());
Assert.assertEquals(principal + "@" + kdc.getRealm(), subject.getPrincipals().iterator().next().getName());
loginContext.logout();
} finally {
if (loginContext != null) {
loginContext.logout();
}
}
}
use of javax.security.auth.kerberos.KerberosPrincipal in project hadoop by apache.
the class TestKerberosAuthenticationHandler method testInit.
@Test(timeout = 60000)
public void testInit() throws Exception {
Assert.assertEquals(KerberosTestUtils.getKeytabFile(), handler.getKeytab());
Set<KerberosPrincipal> principals = handler.getPrincipals();
Principal expectedPrincipal = new KerberosPrincipal(KerberosTestUtils.getServerPrincipal());
Assert.assertTrue(principals.contains(expectedPrincipal));
Assert.assertEquals(1, principals.size());
}
use of javax.security.auth.kerberos.KerberosPrincipal in project ddf by codice.
the class AuthNStatementProvider method getStatement.
/*
* (non-Javadoc)
*
* @see
* org.apache.cxf.sts.token.provider.AuthenticationStatementProvider#getStatement(org.apache
* .cxf.sts.token.provider.TokenProviderParameters)
*/
@Override
public AuthenticationStatementBean getStatement(TokenProviderParameters providerParameters) {
AuthenticationStatementBean authBean = new AuthenticationStatementBean();
authBean.setSessionIndex(Integer.toString(secureRandom.nextInt()));
TokenRequirements tokenRequirements = providerParameters.getTokenRequirements();
ReceivedToken receivedToken = null;
if (tokenRequirements.getValidateTarget() != null) {
receivedToken = tokenRequirements.getValidateTarget();
} else if (tokenRequirements.getOnBehalfOf() != null) {
receivedToken = tokenRequirements.getOnBehalfOf();
} else if (tokenRequirements.getActAs() != null) {
receivedToken = tokenRequirements.getActAs();
} else if (tokenRequirements.getRenewTarget() != null) {
receivedToken = tokenRequirements.getRenewTarget();
}
if (receivedToken != null) {
Principal principal = receivedToken.getPrincipal();
if (principal instanceof UsernameTokenPrincipal) {
authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD_PROTECTED_TRANSPORT);
} else if (principal instanceof X500Principal) {
authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_X509);
} else if (principal instanceof KerberosPrincipal) {
authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_KERBEROS);
} else {
authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_UNSPECIFIED);
}
} else {
authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_UNSPECIFIED);
}
return authBean;
}
use of javax.security.auth.kerberos.KerberosPrincipal in project ddf by codice.
the class TestPropertyFileClaimsHandler method testGetUser.
@Test
public void testGetUser() {
PropertyFileClaimsHandler propertyFileClaimsHandler = new PropertyFileClaimsHandler();
Principal principal = mock(Principal.class);
when(principal.getName()).thenReturn("mydude");
String user = propertyFileClaimsHandler.getUser(principal);
assertEquals("mydude", user);
principal = new X500Principal("cn=myxman,ou=someunit,o=someorg");
user = propertyFileClaimsHandler.getUser(principal);
assertEquals("myxman", user);
principal = new KerberosPrincipal("mykman@SOMEDOMAIN.COM");
user = propertyFileClaimsHandler.getUser(principal);
assertEquals("mykman", user);
}
use of javax.security.auth.kerberos.KerberosPrincipal in project jdk8u_jdk by JetBrains.
the class ServiceCreds method getEKeys.
/**
* Gets EKeys for a principal.
* @param princ the target name initiator requests. Not null.
* @return keys for the princ, never null, might be empty
*/
public EncryptionKey[] getEKeys(PrincipalName princ) {
if (destroyed) {
throw new IllegalStateException("This object is destroyed");
}
KerberosKey[] kkeys = getKKeys(new KerberosPrincipal(princ.getName()));
if (kkeys.length == 0) {
// Fallback: old JDK does not perform real name checking. If the
// acceptor has host.sun.com but initiator requests for host,
// as long as their keys match (i.e. keys for one can decrypt
// the other's service ticket), the authentication is OK.
// There are real customers depending on this to use different
// names for a single service.
kkeys = getKKeys();
}
EncryptionKey[] ekeys = new EncryptionKey[kkeys.length];
for (int i = 0; i < ekeys.length; i++) {
ekeys[i] = new EncryptionKey(kkeys[i].getEncoded(), kkeys[i].getKeyType(), new Integer(kkeys[i].getVersionNumber()));
}
return ekeys;
}
Aggregations