Package javax.security.auth.login

Examples of javax.security.auth.login.CredentialException


        // determine whether the page exists
        if (!(Boolean)info.get("exists"))
            throw new IllegalArgumentException("Tried to move a non-existant page!");
        if (!checkRights(info, "move"))
        {
            CredentialException ex = new CredentialException("Permission denied: page is protected.");
            log(Level.WARNING, "move", "Cannot move - permission denied. " + ex);
            throw ex;
        }
        String wpMoveToken = (String)info.get("token");
View Full Code Here


        // protection and token
        HashMap info = getPageInfo(rev.getPage());
        if (!checkRights(info, "edit"))
        {
            CredentialException ex = new CredentialException("Permission denied: page is protected.");
            log(Level.WARNING, "undo", "Cannot edit - permission denied." + ex);
            throw ex;
        }
        String wpEditToken = (String)info.get("token");
View Full Code Here

        // protection and token
        HashMap info = getPageInfo("File:" + filename);
        if (!checkRights(info, "upload"))
        {
            CredentialException ex = new CredentialException("Permission denied: page is protected.");
            log(Level.WARNING, "upload", "Cannot upload - permission denied." + ex);
            throw ex;
        }
        String wpEditToken = (String)info.get("token");

        // chunked upload setup
        long filesize = file.length();
        long chunks = (filesize >> LOG2_CHUNK_SIZE) + 1;
        FileInputStream fi = new FileInputStream(file);
        String filekey = "";

        // upload the image
        for (int i = 0; i < chunks; i++)
        {
            HashMap<String, Object> params = new HashMap<String, Object>(50);
            params.put("filename", filename);
            params.put("token", wpEditToken);
            params.put("ignorewarnings", "true");
            if (chunks == 1)
            {
                // Chunks disabled due to a small filesize.
                // This is just a normal upload.
                params.put("text", contents);
                if (!reason.isEmpty())
                    params.put("comment", reason);
                byte[] by = new byte[fi.available()];
                fi.read(by);
                // Why this is necessary?
                params.put("file\"; filename=\"" + file.getName(), by);
            }
            else
            {
                long offset = i << LOG2_CHUNK_SIZE;
                params.put("stash", "1");
                params.put("offset", "" + offset);
                params.put("filesize", "" + filesize);
                if (i != 0)
                    params.put("filekey", filekey);

                // write the actual file
                long buffersize = Math.min(1 << LOG2_CHUNK_SIZE, filesize - offset);
                byte[] by = new byte[(int)buffersize]; // 32 bit problem. Why must array indices be ints?
                fi.read(by);
                params.put("chunk\"; filename=\"" + file.getName(), by);

                // Each chunk presumably requires a new edit token
                wpEditToken = (String)getPageInfo("File:" + filename).get("token");
            }

            // done
            String response = multipartPost(apiUrl + "action=upload", params, "upload");
            try
            {
                // look for filekey
                if (chunks > 1)
                {
                    if (response.contains("filekey=\""))
                    {
                        filekey = parseAttribute(response, "filekey", 0);
                        continue;
                    }
                    else
                        throw new IOException("No filekey present! Server response was " + response);
                }
                // TODO: check for more specific errors here
                if (response.contains("error code=\"fileexists-shared-forbidden\""))
                {
                    CredentialException ex = new CredentialException("Cannot overwrite file hosted on central repository.");
                    log(Level.WARNING, "upload", "Cannot upload - permission denied." + ex);
                    throw ex;
                }
                checkErrorsAndUpdateStatus(response, "upload");
            }
View Full Code Here

    /**
     * @tests javax.security.auth.login.CredentialException#CredentialException()
     */
    public final void testCtor1() {
        assertNull(new CredentialException().getMessage());
    }
View Full Code Here

    /**
     * @tests javax.security.auth.login.CredentialException#CredentialException(
     *        java.lang.String)
     */
    public final void testCtor2() {
        assertNull(new CredentialException(null).getMessage());

        String message = "";
        assertSame(message, new CredentialException(message).getMessage());

        message = "message";
        assertSame(message, new CredentialException(message).getMessage());
    }
View Full Code Here

public class CredentialExceptionTest extends SerializationTest {

    @Override
    protected Object[] getData() {
        return new Object[] {new CredentialException("message")};
    }
View Full Code Here

   
    if (parser != null) {   
      if (response.getStatusCode() == 200l) {
        return parser.parseTicketSearchResponse(response);
      } else if (response.getStatusCode() == 401l) {
        throw new CredentialException(response.getStatusMessage());
      } else {
        throw new IOException(String.format("Server returned REST-response code %s (%s)", response.getStatusCode(), response.getStatusMessage()));
      }
    } else {
      throw new UnsupportedOperationException("Could not create parser for response format.");
View Full Code Here

                            if (clientId.equalsIgnoreCase("invalid")) {
                                LOG.info("Client ID was invalid");
                                throw new InvalidClientIDException("Bad client Id");
                            } else if (clientId.equalsIgnoreCase("bad-credential")) {
                                LOG.info("User Name was invalid");
                                throw new CredentialException("Unknwon User Name.");
                            }
                        }
                    }
                };
            }
View Full Code Here

                    + SecurityUtils.toMd5(nonceTimeMS + ":" + secretKey))) {
                // valid wrt secretKey, now check lifespan
                return lifespanMS > (System.currentTimeMillis() - nonceTimeMS);
            }
        } catch (Exception e) {
            throw new CredentialException("error parsing nonce: " + e);
        }
        throw new CredentialException("nonce does not match secretKey");
    }
View Full Code Here

TOP

Related Classes of javax.security.auth.login.CredentialException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.