Example usage for java.lang SecurityException getMessage

List of usage examples for java.lang SecurityException getMessage

Introduction

In this page you can find the example usage for java.lang SecurityException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.apache.maven.classpath.munger.validation.JarValidationUtilsTest.java

@Test
public void testSignatureOnModifiedOneByte() throws Exception {
    byte[] TEST_DATA = "the quick brown fox jumps over the lazy dog back".getBytes("UTF-8");
    NamedPropertySource expected = JarValidationUtils.createJarSignature(createTestJar(TEST_DATA));
    for (int index = 0; index < TEST_DATA.length; index++) {
        byte orgValue = TEST_DATA[index];
        try {// www  .ja va 2 s  .  c om
            if (TEST_DATA[index] == ' ') {
                continue;
            }

            TEST_DATA[index] = (byte) (Character.toUpperCase((char) (orgValue & 0xFF)) & 0xFF);
            NamedPropertySource actual = JarValidationUtils.createJarSignature(createTestJar(TEST_DATA));
            try {
                JarValidationUtils.validateJarSignature(expected, actual);
                fail("Unexpected success for " + new String(TEST_DATA));
            } catch (SecurityException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(e.getMessage());
                }
            }
        } finally {
            TEST_DATA[index] = orgValue;
        }
    }
}

From source file:org.apache.ws.security.validate.KerberosTokenValidator.java

/**
 * Validate the credential argument. It must contain a non-null BinarySecurityToken. 
 * // ww  w .j a  v  a2 s  .c  o m
 * @param credential the Credential to be validated
 * @param data the RequestData associated with the request
 * @throws WSSecurityException on a failed validation
 */
public Credential validate(Credential credential, RequestData data) throws WSSecurityException {
    if (credential == null || credential.getBinarySecurityToken() == null) {
        throw new WSSecurityException(WSSecurityException.FAILURE, "noCredential");
    }

    BinarySecurity binarySecurity = credential.getBinarySecurityToken();
    if (!(binarySecurity instanceof KerberosSecurity)) {
        return credential;
    }

    if (log.isDebugEnabled()) {
        try {
            String jaasAuth = System.getProperty("java.security.auth.login.config");
            String krbConf = System.getProperty("java.security.krb5.conf");
            log.debug("KerberosTokenValidator - Using JAAS auth login file: " + jaasAuth);
            log.debug("KerberosTokenValidator - Using KRB conf file: " + krbConf);
        } catch (SecurityException ex) {
            log.debug(ex.getMessage(), ex);
        }
    }

    // Get a TGT from the KDC using JAAS
    LoginContext loginContext = null;
    try {
        if (callbackHandler == null) {
            loginContext = new LoginContext(getContextName());
        } else {
            loginContext = new LoginContext(getContextName(), callbackHandler);
        }
        loginContext.login();
    } catch (LoginException ex) {
        if (log.isDebugEnabled()) {
            log.debug(ex.getMessage(), ex);
        }
        throw new WSSecurityException(WSSecurityException.FAILURE, "kerberosLoginError",
                new Object[] { ex.getMessage() }, ex);
    }
    if (log.isDebugEnabled()) {
        log.debug("Successfully authenticated to the TGT");
    }

    byte[] token = binarySecurity.getToken();

    // Get the service name to use - fall back on the principal
    Subject subject = loginContext.getSubject();
    String service = serviceName;
    if (service == null) {
        Set<Principal> principals = subject.getPrincipals();
        if (principals.isEmpty()) {
            throw new WSSecurityException(WSSecurityException.FAILURE, "kerberosLoginError",
                    new Object[] { "No Client principals found after login" });
        }
        service = principals.iterator().next().getName();
    }

    // Validate the ticket
    KerberosServiceAction action = new KerberosServiceAction(token, service);
    Principal principal = (Principal) Subject.doAs(subject, action);
    if (principal == null) {
        throw new WSSecurityException(WSSecurityException.FAILURE, "kerberosTicketValidationError");
    }
    credential.setPrincipal(principal);
    credential.setSubject(subject);

    // Try to extract the session key from the token if a KerberosTokenDecoder implementation is
    // available
    if (kerberosTokenDecoder != null) {
        kerberosTokenDecoder.clear();
        kerberosTokenDecoder.setToken(token);
        kerberosTokenDecoder.setSubject(subject);
        byte[] sessionKey = kerberosTokenDecoder.getSessionKey();
        credential.setSecretKey(sessionKey);
    }

    if (log.isDebugEnabled()) {
        log.debug("Successfully validated a ticket");
    }

    return credential;
}

From source file:org.cloudifysource.shell.validators.NicAddressValidator.java

@Override
public void validate() throws CLIValidationException {

    ServerSocket serverSocket = null;
    try {//from  w  w  w .j a  v  a 2s . c  o  m
        if (StringUtils.isBlank(nicAddress)) {
            nicAddress = Constants.getHostAddress();
        }

        if (StringUtils.isBlank(nicAddress)) {
            throw new IllegalArgumentException("NIC Address is empty");
        }
        IPUtils.testOpenServerSocket(nicAddress);
    } catch (UnknownHostException uhe) {
        // thrown if the host could not be determined.
        throw new CLIValidationException(uhe, 121,
                CloudifyErrorMessages.NIC_VALIDATION_ABORTED_UNKNOWN_HOST.getName(), uhe.getMessage());
    } catch (IOException ioe) {
        // thrown if an I/O error occurs when creating the socket or connecting to it.
        throw new CLIValidationException(ioe, 122,
                CloudifyErrorMessages.NIC_VALIDATION_ABORTED_IO_ERROR.getName(), nicAddress, ioe.getMessage());
    } catch (SecurityException se) {
        // thrown if a security manager exists and doesn't allow the operation.
        throw new CLIValidationException(se, 123,
                CloudifyErrorMessages.NIC_VALIDATION_ABORTED_NO_PERMISSION.getName(), se.getMessage());
    } finally {
        if (serverSocket != null) {
            try {
                serverSocket.close();
            } catch (Exception e) {
                //ignore
            }
        }
    }

}

From source file:ee.ioc.cs.vsle.util.Console.java

private Console() {
    // create all components and add them
    frame = new JFrame("Java Console");
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = new Dimension((screenSize.width / 2), (screenSize.height / 2));
    int x = (frameSize.width / 2);
    int y = (frameSize.height / 2);
    frame.setBounds(x, y, frameSize.width, frameSize.height);

    textArea = new JTextArea();
    textArea.setEditable(false);// w ww .j  a v a  2 s .  c o  m
    JButton button = new JButton("clear");

    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER);
    frame.getContentPane().add(button, BorderLayout.SOUTH);
    frame.setVisible(true);

    frame.addWindowListener(this);
    button.addActionListener(this);

    final PipedInputStream pin = new PipedInputStream();
    try {
        PipedOutputStream pout = new PipedOutputStream(pin);
        System.setOut(new PrintStream(new TeeOutputStream(systemOut, pout), true));
    } catch (java.io.IOException io) {
        textArea.append("Couldn't redirect STDOUT to this console\n" + io.getMessage());
    } catch (SecurityException se) {
        textArea.append("Couldn't redirect STDOUT to this console\n" + se.getMessage());
    }

    final PipedInputStream pin2 = new PipedInputStream();
    try {
        PipedOutputStream pout2 = new PipedOutputStream(pin2);
        System.setErr(new PrintStream(new TeeOutputStream(systemErr, pout2), true));
    } catch (java.io.IOException io) {
        textArea.append("Couldn't redirect STDERR to this console\n" + io.getMessage());
    } catch (SecurityException se) {
        textArea.append("Couldn't redirect STDERR to this console\n" + se.getMessage());
    }

    quit = false; // signals the Threads that they should exit

    sysOutFollower = new StreamFollower(pin, StreamRestorer.SYS_OUT, "Console_out");
    sysOutFollower.start();
    //
    sysErrFollower = new StreamFollower(pin2, StreamRestorer.SYS_ERR, "Console_err");
    sysErrFollower.start();
}

From source file:org.qxsched.doc.afp.impl.AfpClasses.java

public AfpRecord instantiateSpecific(AfpRecord record, AfpFactory fact) throws AfpException {

    // Get record class
    Class<AfpRecord> cls = getSpecificAfpRecordClass(record);

    // Do nothing if no class
    if (cls == null) {
        LOG.warn("No specific class found for AFP identifier '" + record.getSFIdentifierAbbrev() + "'/"
                + record.getSFIdentifierString());
        return record;
    }//  w  ww  .  j a va  2s.  c  om

    // Get constructor
    Constructor<AfpRecord> constr;
    try {
        Class[] prams = { AfpRecord.class, AfpFactory.class };
        constr = cls.getConstructor(prams);
    } catch (SecurityException e) {
        throw new AfpException(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
        LOG.error("No constructor found accepting AfpRecord in class " + cls.getName(), e);
        return record;
    }

    // Instantiate
    try {
        Object[] prams = { record, fact };
        AfpRecord inst = constr.newInstance(prams);
        return inst;
    } catch (IllegalArgumentException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return record;
    } catch (InstantiationException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return record;
    } catch (IllegalAccessException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return record;
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof AfpException) {
            throw (AfpException) cause;
        }
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return record;
    }
}

From source file:org.qxsched.doc.afp.impl.AfpClasses.java

public AfpTriplet instantiateSpecific(AfpTriplet triplet, AfpFactory fact) throws AfpException {

    // Get triplet class
    Class<AfpTriplet> cls = getSpecificAfpTripletClass(triplet);

    // Do nothing if no class
    if (cls == null) {
        LOG.warn("No specific class found for AFP triplet 0x" + Integer.toString(triplet.getTid(), 16));
        return triplet;
    }// w  w w  .ja v a 2s . co  m

    // Get constructor
    Constructor<AfpTriplet> constr;
    try {
        constr = cls.getConstructor(AfpTriplet.class);
    } catch (SecurityException e) {
        throw new AfpException(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
        LOG.error("No constructor found accepting AfpTriplet in class " + cls.getName());
        return triplet;
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Constructor found accepting AfpTriplet in class " + cls.getName());
    }

    // Instantiate
    try {
        Object[] prams = { triplet };
        AfpTriplet inst = constr.newInstance(prams);
        return inst;
    } catch (IllegalArgumentException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return triplet;
    } catch (InstantiationException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return triplet;
    } catch (IllegalAccessException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return triplet;
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof AfpException) {
            throw (AfpException) cause;
        }
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return triplet;
    }
}

From source file:org.apache.directory.fortress.core.GroupMgrConsole.java

void assign() {
    try {/*w w  w .ja v  a2s .  c  o  m*/
        ReaderUtil.clearScreen();
        System.out.println("Enter userId");
        String userId = ReaderUtil.readLn();
        System.out.println("Enter group name");
        String name = ReaderUtil.readLn();
        groupMgr.assign(new Group(name), userId);
        System.out.println("Group assigned user");
        System.out.println("ENTER to continue");
    } catch (SecurityException e) {
        LOG.error("assign caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
    }
    ReaderUtil.readChar();
}

From source file:org.apache.directory.fortress.core.GroupMgrConsole.java

/**
 * Description of the Method//from  w w w . j a  v a 2  s . c o  m
 */
void delete() {
    try {
        ReaderUtil.clearScreen();
        System.out.println("Enter group name:");
        String name = ReaderUtil.readLn();
        Group group = new Group();
        group.setName(name);
        groupMgr.delete(group);
        System.out.println("Group successfully deleted");
        System.out.println("ENTER to continue");
    } catch (SecurityException e) {
        LOG.error("delete caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
    }
    ReaderUtil.readChar();
}

From source file:org.apache.directory.fortress.core.GroupMgrConsole.java

void deassign() {
    try {/*ww  w.ja v a2 s. c  om*/
        ReaderUtil.clearScreen();
        System.out.println("Enter userId");
        String userId = ReaderUtil.readLn();
        System.out.println("Enter group name");
        String name = ReaderUtil.readLn();
        groupMgr.assign(new Group(name), userId);
        System.out.println("Group deassigned user");
        System.out.println("ENTER to continue");
    } catch (SecurityException e) {
        LOG.error("deassign caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e);
    }
    ReaderUtil.readChar();
}

From source file:org.kuali.rice.kns.util.ActionFormUtilMap.java

/**
 * This method parses from the key the actual method to run.
 *
 * @see java.util.Map#get(java.lang.Object)
 *//*  w  w  w . j av a 2s  .  c  o  m*/
@Override
public Object get(Object key) {
    if (cacheValueFinderResults) {
        if (super.containsKey(key)) {
            // doing a 2 step retrieval allows us to also cache the null key correctly
            Object cachedObject = super.get(key);
            return cachedObject;
        }
    }
    String[] methodKey = StringUtils.split((String) key,
            KRADConstants.ACTION_FORM_UTIL_MAP_METHOD_PARM_DELIMITER);

    String methodToCall = methodKey[0];

    // handle method calls with more than one parameter
    Object[] methodParms = new Object[methodKey.length - 1];
    Class[] methodParmsPrototype = new Class[methodKey.length - 1];
    for (int i = 1; i < methodKey.length; i++) {
        methodParms[i - 1] = methodKey[i];
        methodParmsPrototype[i - 1] = Object.class;
    }

    Method method = null;
    try {
        method = ActionFormUtilMap.class.getMethod(methodToCall, methodParmsPrototype);
    } catch (SecurityException e) {
        throw new RuntimeException(
                "Unable to object handle on method given to ActionFormUtilMap: " + e.getMessage());
    } catch (NoSuchMethodException e1) {
        throw new RuntimeException(
                "Unable to object handle on method given to ActionFormUtilMap: " + e1.getMessage());
    }

    Object methodValue = null;
    try {
        methodValue = method.invoke(this, methodParms);
    } catch (Exception e) {
        throw new RuntimeException("Unable to invoke method " + methodToCall, e);
    }

    if (cacheValueFinderResults) {
        super.put(key, methodValue);
    }

    return methodValue;
}