IdRepoSampleUtils.java revision 386650a8957e131311273ee84a4a4113ad5e3fe2
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: IdRepoSampleUtils.java,v 1.5 2008/08/07 22:08:20 goodearth Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.samples.clientsdk.idrepo;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.AuthContext;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.spi.AuthLoginException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.share.AuthXMLTags;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.util.ISAuthConstants;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.idm.AMIdentityRepository;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public SSOToken realmLogin (String userid, String password, String realm)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws SSOException, AuthLoginException, Exception
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthContext.IndexType authType = AuthContext.IndexType.MODULE_INSTANCE;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "IdRepoSampleUtils: could not get AuthContext for realm " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.err.println("IdRepoSampleUtils: Failed to start login " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "for default authmodule");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster values.put(AuthXMLTags.PASSWORD_CALLBACK, password);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.err.println( "Failed to submit callbacks!");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("==>Authentication SUCCESSFUL for user " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (istat == AuthContext.Status.COMPLETED) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("==>Authentication Status for user " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.err.println( "Failed to get SSO token! " + e.getMessage());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void logout () throws AuthLoginException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.err.println ("IdRepoSampleUtils: logout failed for user '" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void fillCallbacks(Callback[] callbacks, Hashtable values)
73db2ddb960cafd7ffb6daf89eb697910d36c56dJames Phillpotts NameCallback nc = (NameCallback) callbacks[i];
73db2ddb960cafd7ffb6daf89eb697910d36c56dJames Phillpotts nc.setName((String)values.get(AuthXMLTags.NAME_CALLBACK));
73db2ddb960cafd7ffb6daf89eb697910d36c56dJames Phillpotts } else if (callbacks[i] instanceof PasswordCallback) {
73db2ddb960cafd7ffb6daf89eb697910d36c56dJames Phillpotts PasswordCallback pc = (PasswordCallback) callbacks[i];
73db2ddb960cafd7ffb6daf89eb697910d36c56dJames Phillpotts AuthXMLTags.PASSWORD_CALLBACK)).toCharArray());
73db2ddb960cafd7ffb6daf89eb697910d36c56dJames Phillpotts } else if (callbacks[i] instanceof TextInputCallback) {
73db2ddb960cafd7ffb6daf89eb697910d36c56dJames Phillpotts TextInputCallback tic = (TextInputCallback) callbacks[i];
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (callbacks[i] instanceof ChoiceCallback) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ChoiceCallback cc = (ChoiceCallback) callbacks[i];
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cc.setSelectedIndex(Integer.parseInt((String)values.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster char ch = (char)c;
73db2ddb960cafd7ffb6daf89eb697910d36c56dJames Phillpotts System.err.println ("getLine: " + e.getMessage());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getLine (String prompt, String defaultVal) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.print (prompt + " [" + defaultVal + "]: ");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * return integer value of String sVal; -1 if error
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "' does not appear to be an integer.");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * can only create or delete AMIdentities of IdType user, agentgroup,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "\t0: user\n\t1: agent\n\t2: agentonly\n\t3: agentgroup\n\t4: realm\n\t5: No selection");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String answer = getLine ("Select type: [0..3]: ");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster switch (i) {
return tType;
return (null);
return (null);
return (tType);
public void printResults (
public void printResultsRealm (
public void printIdTypeResults(
private void printIdTypeSet (
public int selectFromArray (
boolean isIdType = false;
boolean isString = false;
isIdType = true;
isString = true;
if (isIdType) {
} else if (isString) {
boolean isAMId = false;
boolean isString = false;
return null;
isAMId = true;
isString = true;
if (isAMId) {
} else if (isString) {
return null;
public void waitForReturn() {