List of usage examples for java.lang SecurityException SecurityException
public SecurityException(Throwable cause)
From source file:org.onecmdb.core.utils.wsdl.OneCMDBWebServiceImpl.java
public CiBean getAuthAccount(String token) { ISession session = onecmdb.getSession(token); if (session == null) { throw new SecurityException("No Session found! Try to do auth() first!"); }/* w w w . j av a 2 s .c o m*/ UserDetails user = session.getPrincipal(); if (user instanceof OneCMDBUser) { OneCMDBUser cmdbUser = (OneCMDBUser) user; ICi account = cmdbUser.getAccount(); if (account != null) { CiBean bean = (new OneCmdbBeanProvider()).convertCiToBean(account); return (bean); } } return (null); //throw new SecurityException("Token is not a OneCMDB Account!"); }
From source file:com.fututel.db.DBProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Constructs a new query builder and sets its table name SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); String finalSortOrder = sortOrder; String[] finalSelectionArgs = selectionArgs; String finalGrouping = null;//from w w w .j av a2 s . com String finalHaving = null; int type = URI_MATCHER.match(uri); Uri regUri = uri; int remoteUid = Binder.getCallingUid(); int selfUid = android.os.Process.myUid(); if (remoteUid != selfUid) { if (type == ACCOUNTS || type == ACCOUNTS_ID) { for (String proj : projection) { if (proj.toLowerCase().contains(SipProfile.FIELD_DATA) || proj.toLowerCase().contains("*")) { throw new SecurityException("Password not readable from external apps"); } } } } Cursor c; long id; switch (type) { case ACCOUNTS: qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipProfile.FIELD_PRIORITY + " ASC"; } break; case ACCOUNTS_ID: qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME); qb.appendWhere(SipProfile.FIELD_ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case CALLLOGS: qb.setTables(SipManager.CALLLOGS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = CallLog.Calls.DATE + " DESC"; } break; case CALLLOGS_ID: qb.setTables(SipManager.CALLLOGS_TABLE_NAME); qb.appendWhere(CallLog.Calls._ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case FILTERS: qb.setTables(SipManager.FILTERS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = Filter.DEFAULT_ORDER; } break; case FILTERS_ID: qb.setTables(SipManager.FILTERS_TABLE_NAME); qb.appendWhere(Filter._ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case MESSAGES: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } break; case MESSAGES_ID: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); qb.appendWhere(SipMessage.FIELD_ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case THREADS: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_FROM_FULL, SipMessage.FIELD_TO, "CASE " + "WHEN " + SipMessage.FIELD_FROM + "='SELF' THEN " + SipMessage.FIELD_TO + " WHEN " + SipMessage.FIELD_FROM + "!='SELF' THEN " + SipMessage.FIELD_FROM + " END AS message_ordering", SipMessage.FIELD_BODY, "MAX(" + SipMessage.FIELD_DATE + ") AS " + SipMessage.FIELD_DATE, "MIN(" + SipMessage.FIELD_READ + ") AS " + SipMessage.FIELD_READ, //SipMessage.FIELD_READ, "COUNT(" + SipMessage.FIELD_DATE + ") AS counter" }; //qb.appendWhere(SipMessage.FIELD_TYPE + " in (" + SipMessage.MESSAGE_TYPE_INBOX // + "," + SipMessage.MESSAGE_TYPE_SENT + ")"); finalGrouping = "message_ordering"; regUri = SipMessage.MESSAGE_URI; break; case THREADS_ID: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_TO, SipMessage.FIELD_BODY, SipMessage.FIELD_DATE, SipMessage.FIELD_MIME_TYPE, SipMessage.FIELD_TYPE, SipMessage.FIELD_STATUS, SipMessage.FIELD_FROM_FULL }; qb.appendWhere(MESSAGES_THREAD_SELECTION); String from = uri.getLastPathSegment(); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { from, from }); regUri = SipMessage.MESSAGE_URI; break; case ACCOUNTS_STATUS: synchronized (profilesStatus) { ContentValues[] cvs = new ContentValues[profilesStatus.size()]; int i = 0; for (ContentValues ps : profilesStatus.values()) { cvs[i] = ps; i++; } c = getCursor(cvs); } if (c != null) { c.setNotificationUri(getContext().getContentResolver(), uri); } return c; case ACCOUNTS_STATUS_ID: id = ContentUris.parseId(uri); synchronized (profilesStatus) { ContentValues cv = profilesStatus.get(id); if (cv == null) { return null; } c = getCursor(new ContentValues[] { cv }); } c.setNotificationUri(getContext().getContentResolver(), uri); return c; default: throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } SQLiteDatabase db = mOpenHelper.getReadableDatabase(); c = qb.query(db, projection, selection, finalSelectionArgs, finalGrouping, finalHaving, finalSortOrder); c.setNotificationUri(getContext().getContentResolver(), regUri); return c; }
From source file:info.magnolia.cms.security.SecurityUtil.java
/** * Gets SHA-1 encoded -> hex string./*from ww w . j ava 2 s . com*/ */ public static String getSHA1Hex(byte[] data) { try { return byteArrayToHex(getDigest(data, SecurityUtil.SHA1)); } catch (NoSuchAlgorithmException e) { throw new SecurityException("Couldn't digest with " + SecurityUtil.SHA1 + " algorithm!"); } }
From source file:be.e_contract.dssp.client.DigitalSignatureServiceClient.java
/** * Downloads the signed document.//from w ww .ja v a 2 s .co m * * @param session * the session object. * @return the signed document. */ public byte[] downloadSignedDocument(DigitalSignatureServiceSession session) { if (false == session.isSignResponseVerified()) { throw new SecurityException("SignResponse not verified"); } PendingRequest pendingRequest = this.asyncObjectFactory.createPendingRequest(); pendingRequest.setProfile(DigitalSignatureServiceConstants.PROFILE); AnyType optionalInputs = this.objectFactory.createAnyType(); pendingRequest.setOptionalInputs(optionalInputs); optionalInputs.getAny().add( this.objectFactory.createAdditionalProfile(DigitalSignatureServiceConstants.DSS_ASYNC_PROFILE)); optionalInputs.getAny().add(this.asyncObjectFactory.createResponseID(session.getResponseId())); RequestSecurityTokenType requestSecurityToken = this.wstObjectFactory.createRequestSecurityTokenType(); optionalInputs.getAny().add(this.wstObjectFactory.createRequestSecurityToken(requestSecurityToken)); requestSecurityToken.getAny().add(this.wstObjectFactory .createRequestType(DigitalSignatureServiceConstants.WS_TRUST_CANCEL_REQUEST_TYPE)); CancelTargetType cancelTarget = this.wstObjectFactory.createCancelTargetType(); requestSecurityToken.getAny().add(this.wstObjectFactory.createCancelTarget(cancelTarget)); SecurityTokenReferenceType securityTokenReference = this.wsseObjectFactory .createSecurityTokenReferenceType(); cancelTarget.setAny(this.wsseObjectFactory.createSecurityTokenReference(securityTokenReference)); ReferenceType reference = this.wsseObjectFactory.createReferenceType(); securityTokenReference.getAny().add(this.wsseObjectFactory.createReference(reference)); reference.setValueType(DigitalSignatureServiceConstants.WS_SEC_CONV_TOKEN_TYPE); reference.setURI(session.getSecurityTokenId()); this.wsSecuritySOAPHandler.setSession(session); SignResponse signResponse = this.dssPort.pendingRequest(pendingRequest); AnyType optionalOutputs = signResponse.getOptionalOutputs(); List<Object> optionalOutputsList = optionalOutputs.getAny(); for (Object optionalOutputsObject : optionalOutputsList) { LOG.debug("optional outputs object type: " + optionalOutputsObject.getClass().getName()); if (optionalOutputsObject instanceof DocumentWithSignature) { DocumentWithSignature documentWithSignature = (DocumentWithSignature) optionalOutputsObject; DocumentType document = documentWithSignature.getDocument(); if (document.getBase64XML() != null) { return document.getBase64XML(); } if (document.getBase64Data() != null) { return document.getBase64Data().getValue(); } if (document.getAttachmentReference() != null) { AttachmentReferenceType attachmentReference = document.getAttachmentReference(); String attachmentUri = attachmentReference.getAttRefURI(); LOG.debug("attachment URI: " + attachmentUri); // skip 'cid:' String attachmentContentId = attachmentUri.substring(4); LOG.debug("attachment content id: " + attachmentContentId); Map<String, DataHandler> inboundAttachments = this.attachmentsSOAPHandler .getInboundAttachments(); for (String attachmentId : inboundAttachments.keySet()) { LOG.debug("actual attachment id: " + attachmentId); } DataHandler dataHandler; if (inboundAttachments.size() == 1) { dataHandler = inboundAttachments.values().iterator().next(); } else { // JAX-WS RI 1.8 and CXF dataHandler = inboundAttachments.get(attachmentContentId); if (null == dataHandler) { // JAX-WS RI 1.7 adds '<' and '>'. attachmentContentId = '<' + attachmentContentId + '>'; dataHandler = inboundAttachments.get(attachmentContentId); } } LOG.debug("received data handler: " + (null != dataHandler)); try { byte[] signedDocument = IOUtils.toByteArray(dataHandler.getInputStream()); LOG.debug("signed document size: " + signedDocument.length); return signedDocument; } catch (IOException e) { throw new RuntimeException("IO error: " + e.getMessage(), e); } } } } return null; }
From source file:br.gov.jfrj.siga.cd.AssinaturaDigital.java
/** * Read an existing PKCS#7 object from a DER encoded byte array *//*from w ww . ja v a2 s . c o m*/ protected static org.bouncycastle.asn1.pkcs.SignedData pkcs7SignedData(byte[] in) { ASN1InputStream din = new ASN1InputStream(new ByteArrayInputStream(in)); // // Basic checks to make sure it's a PKCS#7 SignedData Object // ASN1Primitive pkcs; try { pkcs = din.readObject(); } catch (IOException e) { throw new SecurityException("can't decode PKCS7SignedData object"); } finally { try { din.close(); } catch (IOException e) { e.printStackTrace(); } } if (!(pkcs instanceof ASN1Sequence)) { throw new SecurityException("Not a valid PKCS#7 object - not a sequence"); } ContentInfo content = ContentInfo.getInstance(pkcs); org.bouncycastle.asn1.pkcs.SignedData data = org.bouncycastle.asn1.pkcs.SignedData .getInstance(content.getContent()); return data; }
From source file:be.fedict.commons.eid.jca.BeIDKeyStore.java
public BeIDCard getBeIDCard(boolean recover) { boolean cardReaderStickiness; if (null != this.keyStoreParameter) { cardReaderStickiness = this.keyStoreParameter.getCardReaderStickiness(); } else {// www . ja v a 2 s. c o m cardReaderStickiness = false; } if (recover) { LOG.debug("recovering from error"); this.beIDCard = null; } if (null != this.beIDCard) { return this.beIDCard; } if (null != this.keyStoreParameter) { this.beIDCard = this.keyStoreParameter.getBeIDCard(); } if (null != this.beIDCard) { return this.beIDCard; } Component parentComponent; Locale locale; Logger logger; if (null != this.keyStoreParameter) { parentComponent = this.keyStoreParameter.getParentComponent(); locale = this.keyStoreParameter.getLocale(); logger = this.keyStoreParameter.getLogger(); } else { parentComponent = null; locale = null; logger = null; } if (null == locale) { locale = Locale.getDefault(); } if (null == logger) { logger = new VoidLogger(); } final Messages messages = Messages.getInstance(locale); final BeIDCardsUI ui = new DefaultBeIDCardsUI(parentComponent, messages); final BeIDCards beIDCards = new BeIDCards(logger, ui); beIDCards.setLocale(locale); try { CardTerminal stickyCardTerminal; if (cardReaderStickiness) { stickyCardTerminal = this.cardTerminal; } else { stickyCardTerminal = null; } this.beIDCard = beIDCards.getOneBeIDCard(stickyCardTerminal); if (cardReaderStickiness) { this.cardTerminal = this.beIDCard.getCardTerminal(); LOG.debug("sticky card reader: " + this.cardTerminal.getName()); } final BeIDCardUI userInterface = new DefaultBeIDCardUI(parentComponent, messages); this.beIDCard.setUI(userInterface); } catch (final CancelledException cex) { throw new SecurityException("user cancelled"); } if (null == this.beIDCard) { throw new SecurityException("missing eID card"); } return this.beIDCard; }
From source file:de.xwic.appkit.core.dao.AbstractDAO.java
/** * Makes a security check about the given right and the actual user. * <p>/*from ww w . j av a 2 s . com*/ * * @param entity * * @param rightName */ protected void checkRights(String rightName, IEntity entity) { ISecurityManager manager = DAOSystem.getSecurityManager(); IUser user = manager.getCurrentUser(); if (log.isDebugEnabled()) { // disabled. /* * StringBuffer logbuffer = new StringBuffer(); * logbuffer.append("SECURITY CHECK: User: ").append(user != null ? * user.getName() : "<no user: systemstart>"); * logbuffer.append(" RECHT: ").append(rightName); * logbuffer.append("... Bei Entitt: " * ).append(getEntityClass().getName()); * log.debug(logbuffer.toString()); */ } boolean result = entity == null ? manager.hasRight(getEntityClass().getName(), rightName) : hasRight(entity, rightName); if (user != null && !result) { StringBuffer sb = new StringBuffer(); sb.append("Fehlendes Recht: ").append(rightName); sb.append("... Bei Entitt: ").append(getEntityClass().getName()); log.error("SECURITY EXCEPTION: " + sb.toString()); throw new SecurityException(sb.toString()); } }
From source file:com.ikanow.aleph2.security.service.SecuredCrudManagementDbService.java
/** * Read permissions are the default permissions. * @param new_object// w w w .j av a 2 s . c o m */ protected boolean checkPermissions(Object new_object, Optional<String> oAction, boolean throwOrReturn) { List<String> permissions = permissionExtractor.extractPermissionIdentifiers(new_object, oAction); boolean permitted = false; if (permissions != null && permissions.size() > 0) { for (String permission : permissions) { permitted = securityService.isUserPermitted(principalName, permission); if (permitted) { break; } } if (!permitted && throwOrReturn) { String msg = "Subject '" + principalName + "' has no permissions (" + permissions + ")for " + oAction + " on " + new_object.getClass(); logger.error(msg); throw new SecurityException(msg); } } return permitted; }
From source file:info.magnolia.cms.security.SecurityUtil.java
/** * Gets MD5 encoded -> hex string.// w w w . j a v a 2 s . co m */ public static String getMD5Hex(byte[] data) { try { return byteArrayToHex(getDigest(data, SecurityUtil.MD5)); } catch (NoSuchAlgorithmException e) { throw new SecurityException("Couldn't digest with " + SecurityUtil.MD5 + " algorithm!"); } }
From source file:com.sonetel.db.DBProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Constructs a new query builder and sets its table name SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); String finalSortOrder = sortOrder; String[] finalSelectionArgs = selectionArgs; String finalGrouping = null;//from ww w .j a v a 2s . c o m String finalHaving = null; int type = URI_MATCHER.match(uri); Uri regUri = uri; int remoteUid = Binder.getCallingUid(); int selfUid = android.os.Process.myUid(); if (remoteUid != selfUid) { if (type == ACCOUNTS || type == ACCOUNTS_ID) { for (String proj : projection) { if (proj.toLowerCase().contains(SipProfile.FIELD_DATA) || proj.toLowerCase().contains("*")) { throw new SecurityException("Password not readable from external apps"); } } } } Cursor c; long id; switch (type) { case ACCOUNTS: qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipProfile.FIELD_PRIORITY + " ASC"; } break; case ACCOUNTS_ID: qb.setTables(SipProfile.ACCOUNTS_TABLE_NAME); qb.appendWhere(SipProfile.FIELD_ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case CALLLOGS: qb.setTables(SipManager.CALLLOGS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = CallLog.Calls.DATE + " DESC"; } break; case CALLLOGS_ID: qb.setTables(SipManager.CALLLOGS_TABLE_NAME); qb.appendWhere(CallLog.Calls._ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case FILTERS: qb.setTables(SipManager.FILTERS_TABLE_NAME); if (sortOrder == null) { finalSortOrder = Filter.DEFAULT_ORDER; } break; case FILTERS_ID: qb.setTables(SipManager.FILTERS_TABLE_NAME); qb.appendWhere(Filter._ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case MESSAGES: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } break; case MESSAGES_ID: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); qb.appendWhere(SipMessage.FIELD_ID + "=?"); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; case THREADS: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_FROM_FULL, SipMessage.FIELD_TO, "CASE " + "WHEN " + SipMessage.FIELD_FROM + "='SELF' THEN " + SipMessage.FIELD_TO + " WHEN " + SipMessage.FIELD_FROM + "!='SELF' THEN " + SipMessage.FIELD_FROM + " END AS message_ordering", SipMessage.FIELD_BODY, "MAX(" + SipMessage.FIELD_DATE + ") AS " + SipMessage.FIELD_DATE, "MIN(" + SipMessage.FIELD_READ + ") AS " + SipMessage.FIELD_READ, //SipMessage.FIELD_READ, "COUNT(" + SipMessage.FIELD_DATE + ") AS counter" }; //qb.appendWhere(SipMessage.FIELD_TYPE + " in (" + SipMessage.MESSAGE_TYPE_INBOX // + "," + SipMessage.MESSAGE_TYPE_SENT + ")"); finalGrouping = "message_ordering"; regUri = SipMessage.MESSAGE_URI; break; case THREADS_ID: qb.setTables(SipMessage.MESSAGES_TABLE_NAME); if (sortOrder == null) { finalSortOrder = SipMessage.FIELD_DATE + " DESC"; } projection = new String[] { "ROWID AS _id", SipMessage.FIELD_FROM, SipMessage.FIELD_TO, SipMessage.FIELD_BODY, SipMessage.FIELD_DATE, SipMessage.FIELD_MIME_TYPE, SipMessage.FIELD_TYPE, SipMessage.FIELD_STATUS, SipMessage.FIELD_FROM_FULL }; qb.appendWhere(MESSAGES_THREAD_SELECTION); String from = uri.getLastPathSegment(); finalSelectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { from, from }); regUri = SipMessage.MESSAGE_URI; break; case ACCOUNTS_STATUS: synchronized (profilesStatus) { ContentValues[] cvs = new ContentValues[profilesStatus.size()]; int i = 0; for (ContentValues ps : profilesStatus.values()) { cvs[i] = ps; i++; } c = getCursor(cvs); } if (c != null) { c.setNotificationUri(getContext().getContentResolver(), uri); } return c; case ACCOUNTS_STATUS_ID: id = ContentUris.parseId(uri); synchronized (profilesStatus) { ContentValues cv = profilesStatus.get(id); if (cv == null) { return null; } c = getCursor(new ContentValues[] { cv }); } c.setNotificationUri(getContext().getContentResolver(), uri); return c; case ACCESSNO: qb.setTables(SipProfile.ACCESS_NUMS_TABLE_NAME); break; default: throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri); } SQLiteDatabase db = mOpenHelper.getReadableDatabase(); c = qb.query(db, projection, selection, finalSelectionArgs, finalGrouping, finalHaving, finalSortOrder); c.setNotificationUri(getContext().getContentResolver(), regUri); return c; }