private String getName() { if (credentials instanceof SimpleCredentials) { return ((SimpleCredentials) credentials).getUserID(); } else { return null; } }
public UserCredentials(Credentials credentials) { this.credentials = credentials; if(credentials instanceof SimpleCredentials) { username = ((SimpleCredentials)credentials).getUserID(); } }
private String getName() { if (credentials instanceof SimpleCredentials) { return ((SimpleCredentials) credentials).getUserID(); } else { return null; } }
/** * @return */ public String getUserID() { return simpleCredentials.getUserID(); }
private String getName() { if (credentials instanceof SimpleCredentials) { return ((SimpleCredentials) credentials).getUserID(); } else { return null; } }
private boolean equalsCredentials(Credentials credentials) { if (isSimpleDefaultCredentials && (credentials instanceof SimpleCredentials)) { SimpleCredentials other = (SimpleCredentials) credentials; return ((SimpleCredentials) this.defaultCredentials).getUserID().equals(other.getUserID()); } else { return this.defaultCredentials.equals(credentials); } }
@Override public int hashCode() { int result = creds != null ? creds.getUserID().hashCode() : 0; result = 31 * result + ( threadId != null ? threadId.hashCode() : 0 ); return result; } }
@Override @Nullable public String getUserId(@NotNull Credentials credentials) { if (credentials instanceof SimpleCredentials) { return ((SimpleCredentials) credentials).getUserID(); } else { return null; } }
@Override @CheckForNull public String getUserId(@Nonnull Credentials credentials) { if (credentials instanceof SimpleCredentials) { return ((SimpleCredentials) credentials).getUserID(); } else { return null; } }
@Override public ExternalUser authenticate(@NotNull Credentials credentials) throws ExternalIdentityException, LoginException { if (credentials instanceof SimpleCredentials) { String userId = ((SimpleCredentials) credentials).getUserID(); return getUser(userId); } else { throw new LoginException("unsupported credentials"); } }
@Nullable @Override public ExternalUser authenticate(@NotNull Credentials credentials) { return getUser(((SimpleCredentials) credentials).getUserID()); }
private boolean credentialsEqual(final Credentials cred, final Credentials compare) { if (cred instanceof SimpleCredentials && compare instanceof SimpleCredentials) { // SimpleCredentials does *not* override hashcode or equals! SimpleCredentials sc = (SimpleCredentials)cred; if (!sc.getUserID().equals(((SimpleCredentials)compare).getUserID())) { return false; } return Arrays.equals(sc.getPassword(), ((SimpleCredentials)compare).getPassword()); } // we can only check on object equality now return cred == compare; }
protected boolean equalsCredentials(Credentials credentials1, Credentials credentials2) { if (credentials1 instanceof SimpleCredentials && credentials2 instanceof SimpleCredentials) { return (((SimpleCredentials) credentials1).getUserID().equals(((SimpleCredentials) credentials2).getUserID())); }else if (credentials1 instanceof JvmCredentials && credentials2 instanceof JvmCredentials) { return (((JvmCredentials) credentials1).getUserID().equals(((JvmCredentials) credentials2).getUserID())); } else if (credentials1 != null) { return credentials1.equals(credentials2); } return false; }
private int getCredentialsHashCode(Credentials cred) { if (cred instanceof SimpleCredentials) { SimpleCredentials sc = (SimpleCredentials)cred; return sc.getUserID().hashCode()*31 + Arrays.hashCode(sc.getPassword()); } // we can only return object hashcode since Credentials impls do not override hashCode.. return (cred != null ? cred.hashCode() : 0); } }
public void writeInner(ContentHandler handler) throws SAXException { if (creds != null) { AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", ATTR_NAME, "", "CDATA", creds.getUserID()); attrs.addAttribute("", ATTR_PASSWORD, "", "CDATA", encrypt(new String(creds.getPassword()))); handler.startElement("", ELEM_USER, "", attrs); handler.endElement("", ELEM_USER, ""); } }
public static AuthInfo createFromSubject(@NotNull Subject subject) { Set<AuthInfo> infoSet = subject.getPublicCredentials(AuthInfo.class); if (infoSet.isEmpty()) { Set<SimpleCredentials> scs = subject.getPublicCredentials(SimpleCredentials.class); String userId = (scs.isEmpty()) ? null : scs.iterator().next().getUserID(); return new AuthInfoImpl(userId, null, subject.getPrincipals()); } else { return infoSet.iterator().next(); } }
public static AuthInfo createFromSubject(@Nonnull Subject subject) { Set<AuthInfo> infoSet = subject.getPublicCredentials(AuthInfo.class); if (infoSet.isEmpty()) { Set<SimpleCredentials> scs = subject.getPublicCredentials(SimpleCredentials.class); String userId = (scs.isEmpty()) ? null : scs.iterator().next().getUserID(); return new AuthInfoImpl(userId, null, subject.getPrincipals()); } else { return infoSet.iterator().next(); } }
@Override protected Principal getPrincipal(Credentials credentials) { if (ignore) { return null; } else { return new TestPrincipal(((SimpleCredentials) credentials).getUserID()); } } }
@Test public void testAuthenticateCannotResolveUser() throws Exception { SimpleCredentials sc = new SimpleCredentials("unknownUser", "pw".toCharArray()); Authentication a = new UserAuthentication(getUserConfiguration(), root, sc.getUserID()); assertFalse(a.authenticate(sc)); }
@Test public void testBindCredentialsSupport() { context.registerService(CredentialsSupport.class, new TestCredentialsSupport(sc.getUserID())); TokenProvider tp = tokenConfiguration.getTokenProvider(root); assertTrue(tp.doCreateToken(sc)); assertTrue(tp.doCreateToken(new TestCredentialsSupport.Creds())); }